Connecting Tech Pros Worldwide Help | Site Map

Trying to create an array.

  #1  
Old June 17th, 2007, 06:35 PM
Vitor
Guest
 
Posts: n/a
I am trying to create a dynamic list on dialog box.

I have to use RECT with I have to define:

TCHAR popSz[32];
RECT popRect = {60,18,100,30};

wsprintf(popSz, "%d", players[currentPlayer]->getPopSpace(gNum));
DrawText(hdc,popSz,-1,&popRect, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);

I wrote a steuct to so that I can have an array of TCHARS and RECTS:

struct dyn{

TCHAR size[32];
RECT rect;
};

I have tried vectors and arrays. I am having trouble putting the RECT
values in the struct. The reason is that I don't know how many items I
will have in the and I want to use a simple loop and array to display
the information. Also as I display the items I want to be able to:

dyn dList[x].recy{60 + (x+15), 18, 100 + (x +15), 30}; or what I have
to do to put each line where they need to be.

Thanks.
  #2  
Old June 17th, 2007, 09:45 PM
Default User
Guest
 
Posts: n/a

re: Trying to create an array.


Vitor wrote:
Quote:
I am trying to create a dynamic list on dialog box.
>
I have to use RECT with I have to define:
This is not standard C++. You need to find a newsgroup dedicated to
your platform.



Brian
  #3  
Old June 17th, 2007, 10:05 PM
Jim Langston
Guest
 
Posts: n/a

re: Trying to create an array.


"Vitor" <none@yahoo.netwrote in message
news:46757027$0$17072$4c368faf@roadrunner.com...
Quote:
>I am trying to create a dynamic list on dialog box.
>
I have to use RECT with I have to define:
>
TCHAR popSz[32];
RECT popRect = {60,18,100,30};
>
wsprintf(popSz, "%d", players[currentPlayer]->getPopSpace(gNum));
DrawText(hdc,popSz,-1,&popRect, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
>
I wrote a steuct to so that I can have an array of TCHARS and RECTS:
>
struct dyn{
>
TCHAR size[32];
RECT rect;
};
>
I have tried vectors and arrays. I am having trouble putting the RECT
values in the struct. The reason is that I don't know how many items I
will have in the and I want to use a simple loop and array to display the
information. Also as I display the items I want to be able to:
>
dyn dList[x].recy{60 + (x+15), 18, 100 + (x +15), 30}; or what I have to
do to put each line where they need to be.
Is this what you're looking for? Something like:
dyn MyRect;
MyRect.rect.x1 = 60;
MyRect.rect.x2 = 18;
MyRect.rect.y1 = 100;
MyRect.rect.x2 = 30;

Depending on what the actual variables names of rect are.


  #4  
Old June 17th, 2007, 10:35 PM
Jim Langston
Guest
 
Posts: n/a

re: Trying to create an array.


"Jim Langston" <tazmaster@rocketmail.comwrote in message
news:elhdi.16$5Z.14@newsfe03.lga...
Quote:
"Vitor" <none@yahoo.netwrote in message
news:46757027$0$17072$4c368faf@roadrunner.com...
Quote:
>>I am trying to create a dynamic list on dialog box.
>>
>I have to use RECT with I have to define:
>>
> TCHAR popSz[32];
> RECT popRect = {60,18,100,30};
>>
> wsprintf(popSz, "%d", players[currentPlayer]->getPopSpace(gNum));
> DrawText(hdc,popSz,-1,&popRect, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
>>
>I wrote a steuct to so that I can have an array of TCHARS and RECTS:
>>
>struct dyn{
>>
> TCHAR size[32];
> RECT rect;
>};
>>
>I have tried vectors and arrays. I am having trouble putting the RECT
>values in the struct. The reason is that I don't know how many items I
>will have in the and I want to use a simple loop and array to display the
>information. Also as I display the items I want to be able to:
>>
>dyn dList[x].recy{60 + (x+15), 18, 100 + (x +15), 30}; or what I have to
>do to put each line where they need to be.
>
Is this what you're looking for? Something like:
dyn MyRect;
MyRect.rect.x1 = 60;
MyRect.rect.x2 = 18;
MyRect.rect.y1 = 100;
MyRect.rect.x2 = 30;
>
Depending on what the actual variables names of rect are.
Surpising to me, but this also works:

dyn MyDyn = { "ABC", 1, 2, 3, 4 };


  #5  
Old June 17th, 2007, 11:45 PM
Vitor
Guest
 
Posts: n/a

re: Trying to create an array.


Jim Langston wrote:
Quote:
"Vitor" <none@yahoo.netwrote in message
news:46757027$0$17072$4c368faf@roadrunner.com...
Quote:
>I am trying to create a dynamic list on dialog box.
>>
>I have to use RECT with I have to define:
>>
> TCHAR popSz[32];
> RECT popRect = {60,18,100,30};
>>
> wsprintf(popSz, "%d", players[currentPlayer]->getPopSpace(gNum));
> DrawText(hdc,popSz,-1,&popRect, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
>>
>I wrote a steuct to so that I can have an array of TCHARS and RECTS:
>>
>struct dyn{
>>
> TCHAR size[32];
> RECT rect;
>};
>>
>I have tried vectors and arrays. I am having trouble putting the RECT
>values in the struct. The reason is that I don't know how many items I
>will have in the and I want to use a simple loop and array to display the
>information. Also as I display the items I want to be able to:
>>
>dyn dList[x].recy{60 + (x+15), 18, 100 + (x +15), 30}; or what I have to
>do to put each line where they need to be.
>
Is this what you're looking for? Something like:
dyn MyRect;
MyRect.rect.x1 = 60;
MyRect.rect.x2 = 18;
MyRect.rect.y1 = 100;
MyRect.rect.x2 = 30;
>
Depending on what the actual variables names of rect are.
>
>
I will see if that works, it might. It sure did, I think now I can
proceed with my program:
Quote:
d[0].rect.left = 60;
d[0].rect.bottom = 68;
d[0].rect.right = 100;
d[0].rect.top = 8
It makes my program messier than I would like but I think it will work.
  #6  
Old June 18th, 2007, 12:05 AM
BobR
Guest
 
Posts: n/a

re: Trying to create an array.



Default User <defaultuserbr@yahoo.comwrote in message ...
Quote:
Vitor wrote:
Quote:
I am trying to create a dynamic list on dialog box.

I have to use RECT with I have to define:
>
This is not standard C++. You need to find a newsgroup dedicated to
your platform.
What? Being all uppercase, RECT is obviously a macro (which the OP didn't
show). <G>

--
Bob R
POVrookie


  #7  
Old June 18th, 2007, 12:45 AM
Thomas J. Gritzan
Guest
 
Posts: n/a

re: Trying to create an array.


Vitor wrote:
Quote:
Jim Langston wrote:
Quote:
>Is this what you're looking for? Something like:
>dyn MyRect;
>MyRect.rect.x1 = 60;
>MyRect.rect.x2 = 18;
>MyRect.rect.y1 = 100;
>MyRect.rect.x2 = 30;
>>
>Depending on what the actual variables names of rect are.
>>
I will see if that works, it might. It sure did, I think now I can
proceed with my program:
>
Quote:
> d[0].rect.left = 60;
> d[0].rect.bottom = 68;
> d[0].rect.right = 100;
> d[0].rect.top = 8
>
It makes my program messier than I would like but I think it will work.
RECT make_rect(int l, int b, int r, int t)
{
RECT rect = {l,b,r,t};
return rect;
}

Then:
d[0].rect = make_rect(60, 68, 100, 8);

--
Thomas
http://www.netmeister.org/news/learn2quote.html
  #8  
Old June 18th, 2007, 02:15 AM
BobR
Guest
 
Posts: n/a

re: Trying to create an array.



Vitor wrote in message...
Quote:
Quote:
Quote:
I wrote a steuct to so that I can have an array of TCHARS and RECTS:
struct dyn{
TCHAR size[32];
RECT rect;
};
>
I will see if that works, it might. It sure did, I think now I can
proceed with my program:
>
Quote:
d[0].rect.left = 60;
d[0].rect.bottom = 68;
d[0].rect.right = 100;
d[0].rect.top = 8
>
It makes my program messier than I would like but I think it will work.
// --- option 1 ---
struct dyn{
TCHAR size[32];
RECT rect;
dyn( int x1, int y1, int x2, int y2 ){ // Constructor
rect.left = x1;
rect.bottom = y1;
rect.right = x2;
rect.top = y2;
}
};

dyn MyRect( 60, 18, 100, 30 );
// --- option 1 --- END

// --- option 2 ---

If your move 'RECT' out of a macro and into a class/struct, it gets even
easier.

struct Rect{
int left;
int bottom;
int right;
int top;
Rect( int x1, int y1, int x2, int y2 ) : left( x1 ),
bottom( y1 ), right( x2 ), top( y2 ){}
};

struct dyn{
TCHAR size[32];
Rect rect;
dyn() : rect( 0, 0, 10, 10 ){} // set 'rect' defaults.
dyn( int x1, int y1, int x2, int y2 ) : rect( x1, y1, x2, y2 ){} // Ctor
};

dyn MyRect( 60, 18, 100, 30 );
// std::cout<< MyRect.rect.bottom << std::endl; // out: 18
// --- option 2 --- END

--
Bob R
POVrookie


  #9  
Old June 18th, 2007, 02:15 AM
Vitor
Guest
 
Posts: n/a

re: Trying to create an array.


Jim Langston wrote:
Quote:
"Jim Langston" <tazmaster@rocketmail.comwrote in message
news:elhdi.16$5Z.14@newsfe03.lga...
Quote:
>"Vitor" <none@yahoo.netwrote in message
>news:46757027$0$17072$4c368faf@roadrunner.com.. .
Quote:
>>I am trying to create a dynamic list on dialog box.
>>>
>>I have to use RECT with I have to define:
>>>
>> TCHAR popSz[32];
>> RECT popRect = {60,18,100,30};
>>>
>> wsprintf(popSz, "%d", players[currentPlayer]->getPopSpace(gNum));
>> DrawText(hdc,popSz,-1,&popRect, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
>>>
>>I wrote a steuct to so that I can have an array of TCHARS and RECTS:
>>>
>>struct dyn{
>>>
>> TCHAR size[32];
>> RECT rect;
>>};
>>>
>>I have tried vectors and arrays. I am having trouble putting the RECT
>>values in the struct. The reason is that I don't know how many items I
>>will have in the and I want to use a simple loop and array to display the
>>information. Also as I display the items I want to be able to:
>>>
>>dyn dList[x].recy{60 + (x+15), 18, 100 + (x +15), 30}; or what I have to
>>do to put each line where they need to be.
>Is this what you're looking for? Something like:
>dyn MyRect;
>MyRect.rect.x1 = 60;
>MyRect.rect.x2 = 18;
>MyRect.rect.y1 = 100;
>MyRect.rect.x2 = 30;
>>
>Depending on what the actual variables names of rect are.
>
Surpising to me, but this also works:
>
dyn MyDyn = { "ABC", 1, 2, 3, 4 };
>
>
I know that works but I am trying to do this in an array and the above
answered my question.
  #10  
Old June 18th, 2007, 02:35 AM
=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=
Guest
 
Posts: n/a

re: Trying to create an array.


BobR wrote:
Quote:
Vitor wrote in message...
Quote:
Quote:
>>>I wrote a steuct to so that I can have an array of TCHARS and RECTS:
>>>struct dyn{
>>> TCHAR size[32];
>>> RECT rect;
>>>};
>>>>
>I will see if that works, it might. It sure did, I think now I can
>proceed with my program:
>>
Quote:
>> d[0].rect.left = 60;
>> d[0].rect.bottom = 68;
>> d[0].rect.right = 100;
>> d[0].rect.top = 8
>It makes my program messier than I would like but I think it will work.
>
// --- option 1 ---
struct dyn{
TCHAR size[32];
RECT rect;
dyn( int x1, int y1, int x2, int y2 ){ // Constructor
rect.left = x1;
rect.bottom = y1;
rect.right = x2;
rect.top = y2;
}
};
>
dyn MyRect( 60, 18, 100, 30 );
// --- option 1 --- END
>
// --- option 2 ---
>
If your move 'RECT' out of a macro and into a class/struct, it gets even
>
1) RECT is predefined Windows struct not a macro.

2) Constructor will be useless for what OP is asking, since it is not
possible to pass parameters to the constructor while allocating an
array. In fact to create an array of a given type you need a default
constructor.

--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
  #11  
Old June 18th, 2007, 03:05 AM
=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=
Guest
 
Posts: n/a

re: Trying to create an array.


Thomas J. Gritzan wrote:
Quote:
Vitor wrote:
Quote:
>Jim Langston wrote:
Quote:
>>Is this what you're looking for? Something like:
>>dyn MyRect;
>>MyRect.rect.x1 = 60;
>>MyRect.rect.x2 = 18;
>>MyRect.rect.y1 = 100;
>>MyRect.rect.x2 = 30;
>>>
>>Depending on what the actual variables names of rect are.
>>>
>I will see if that works, it might. It sure did, I think now I can
>proceed with my program:
>>
Quote:
>> d[0].rect.left = 60;
>> d[0].rect.bottom = 68;
>> d[0].rect.right = 100;
>> d[0].rect.top = 8
>It makes my program messier than I would like but I think it will work.
>
RECT make_rect(int l, int b, int r, int t)
{
RECT rect = {l,b,r,t};
return rect;
}
>
Then:
d[0].rect = make_rect(60, 68, 100, 8);
>
Inefficient the above will be.

the better would be:

struct dyn{
TCHAR size[32];
RECT rect;

void SetRect(long left, long top, long right, long bottom)
{
rect.left=left;
rect.top=top;
rect.right=right;
rect.bottom=bottom;
}
};

then:

d[0].SetRect(60,68,100,8);

--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
  #12  
Old June 18th, 2007, 06:55 AM
Default User
Guest
 
Posts: n/a

re: Trying to create an array.


BobR wrote:
Quote:
>
Default User <defaultuserbr@yahoo.comwrote in message ...
Quote:
Vitor wrote:
Quote:
I am trying to create a dynamic list on dialog box.
>
I have to use RECT with I have to define:
This is not standard C++. You need to find a newsgroup dedicated to
your platform.
>
What? Being all uppercase, RECT is obviously a macro (which the OP
didn't show). <G>
I'll put that in the "unlikely" category.




Brian
  #13  
Old June 18th, 2007, 06:15 PM
BobR
Guest
 
Posts: n/a

re: Trying to create an array.



Grzegorz Wróbel </dev/null@localhost.localdomainwrote in message...
Quote:
BobR wrote:
Quote:

If your move 'RECT' out of a macro and into a class/struct, it gets even
>
1) RECT is predefined Windows struct not a macro.
Sorry about that, I meant to put a smiley or grin there. <G>
Quote:
>
2) Constructor will be useless for what OP is asking, since it is not
possible to pass parameters to the constructor while allocating an
array. In fact to create an array of a given type you need a default
constructor.
Not sure about that.

struct MyRect : public RECT{
MyRect( long x1 = 0, long y1 = 0, long x2 = 10, long y2 = 10 ){
left = x1;
bottom = y1;
right = x2;
top = y2;
}
};
// ....
{
std::vector<MyRectVecArray;
VecArray.push_back( MyRect( 60, 18, 100, 30 ) );
VecArray.push_back( MyRect( 30, 12, 120, 50 ) );
// .... etc.
cout<<"VecArray.at(0).bottom="
<< VecArray.at(0).bottom << std::endl;
RECT rect1 = VecArray.at(0);
cout<<"RECT rect1.bottom="<< rect1.bottom << std::endl;
// out: RECT rect1.bottom=18
}

--
Bob R
POVrookie


  #14  
Old June 19th, 2007, 01:05 AM
=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=
Guest
 
Posts: n/a

re: Trying to create an array.


BobR wrote:
Quote:
Grzegorz Wróbel </dev/null@localhost.localdomainwrote in message...
Quote:
>BobR wrote:
Quote:
>>If your move 'RECT' out of a macro and into a class/struct, it gets even
>1) RECT is predefined Windows struct not a macro.
>
Sorry about that, I meant to put a smiley or grin there. <G>
>
Quote:
>2) Constructor will be useless for what OP is asking, since it is not
>possible to pass parameters to the constructor while allocating an
>array. In fact to create an array of a given type you need a default
>constructor.
>
Not sure about that.
>
struct MyRect : public RECT{
MyRect( long x1 = 0, long y1 = 0, long x2 = 10, long y2 = 10 ){
left = x1;
bottom = y1;
right = x2;
top = y2;
}
};
// ....
{
std::vector<MyRectVecArray;
VecArray.push_back( MyRect( 60, 18, 100, 30 ) );
VecArray.push_back( MyRect( 30, 12, 120, 50 ) );
// .... etc.
cout<<"VecArray.at(0).bottom="
<< VecArray.at(0).bottom << std::endl;
RECT rect1 = VecArray.at(0);
cout<<"RECT rect1.bottom="<< rect1.bottom << std::endl;
// out: RECT rect1.bottom=18
}
While allocating a classic array a default constructor will be used.
Howevever, now I see what you meant:

MyRect* myarray;
myarray = new MyRect[32]; //here default constructor is used
myarray[0] = MyRect(5,5,20,20); //create temporary MyRect variable and
copy it using predefined "=" operator.
delete[] myarray;

This will work, however it will be similarly inefficient as solution
with make_rect() function, proposed elsewhere in this thread.


--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
  #15  
Old June 19th, 2007, 02:15 AM
Vitor
Guest
 
Posts: n/a

re: Trying to create an array.


Thomas J. Gritzan wrote:
Quote:
Vitor wrote:
Quote:
>Jim Langston wrote:
Quote:
>>Is this what you're looking for? Something like:
>>dyn MyRect;
>>MyRect.rect.x1 = 60;
>>MyRect.rect.x2 = 18;
>>MyRect.rect.y1 = 100;
>>MyRect.rect.x2 = 30;
>>>
>>Depending on what the actual variables names of rect are.
>>>
>I will see if that works, it might. It sure did, I think now I can
>proceed with my program:
>>
Quote:
>> d[0].rect.left = 60;
>> d[0].rect.bottom = 68;
>> d[0].rect.right = 100;
>> d[0].rect.top = 8
>It makes my program messier than I would like but I think it will work.
>
RECT make_rect(int l, int b, int r, int t)
{
RECT rect = {l,b,r,t};
return rect;
}
>
Then:
d[0].rect = make_rect(60, 68, 100, 8);
>
Thanks that looks good too, I have been getting the numbers in the rect
but I am having trouble with the next part, this statement doesn't work:
Quote:
for(int l = 0; l != tst; l++){
wsprintf(d[l].size, "%s",test[l]);
DrawText(hdc,d[l].size,-1,&d[l].rect, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
}
  #16  
Old June 19th, 2007, 03:45 AM
=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=
Guest
 
Posts: n/a

re: Trying to create an array.


Vitor wrote:
Quote:
Thanks that looks good too, I have been getting the numbers in the rect
but I am having trouble with the next part, this statement doesn't work:
>
Quote:
> for(int l = 0; l != tst; l++){
>wsprintf(d[l].size, "%s",test[l]);
> DrawText(hdc,d[l].size,-1,&d[l].rect, DT_SINGLELINE |
>DT_RIGHT | DT_VCENTER);
> }
>
Create new thread then and post it in
comp.os.ms-windows.programmer.win32 or
microsoft.public.win32.programmer.gdi.

This is offtopic for this thread (your array problem have been solved)
and for comp.lang.c++ group.

--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
  #17  
Old June 20th, 2007, 10:55 AM
Jim Langston
Guest
 
Posts: n/a

re: Trying to create an array.


"Vitor" <none@yahoo.netwrote in message
news:46772bc3$0$30621$4c368faf@roadrunner.com...
Quote:
Thomas J. Gritzan wrote:
Quote:
>Vitor wrote:
Quote:
>>Jim Langston wrote:
>>>Is this what you're looking for? Something like:
>>>dyn MyRect;
>>>MyRect.rect.x1 = 60;
>>>MyRect.rect.x2 = 18;
>>>MyRect.rect.y1 = 100;
>>>MyRect.rect.x2 = 30;
>>>>
>>>Depending on what the actual variables names of rect are.
>>>>
>>I will see if that works, it might. It sure did, I think now I can
>>proceed with my program:
>>>
>>> d[0].rect.left = 60;
>>> d[0].rect.bottom = 68;
>>> d[0].rect.right = 100;
>>> d[0].rect.top = 8
>>It makes my program messier than I would like but I think it will work.
>>
>RECT make_rect(int l, int b, int r, int t)
>{
> RECT rect = {l,b,r,t};
> return rect;
>}
>>
>Then:
>d[0].rect = make_rect(60, 68, 100, 8);
>>
>
Thanks that looks good too, I have been getting the numbers in the rect
but I am having trouble with the next part, this statement doesn't work:
>
Quote:
> for(int l = 0; l != tst; l++){ wsprintf(d[l].size,
>"%s",test[l]);
> DrawText(hdc,d[l].size,-1,&d[l].rect, DT_SINGLELINE | DT_RIGHT
>| DT_VCENTER);
Not positive on this one, but you might want:
&(d[1].rect)















































Quote:
Quote:
> }
>

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to create an array? The Natural Philosopher answers 6 November 17th, 2008 03:05 PM