Trying to create an array. 
June 17th, 2007, 06:35 PM
| | | |
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. | 
June 17th, 2007, 09:45 PM
| | | | 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 | 
June 17th, 2007, 10:05 PM
| | | | 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. | 
June 17th, 2007, 10:35 PM
| | | | 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 }; | 
June 17th, 2007, 11:45 PM
| | | | 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. | 
June 18th, 2007, 12:05 AM
| | | | 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 | 
June 18th, 2007, 12:45 AM
| | | | 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 | 
June 18th, 2007, 02:15 AM
| | | | 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 | 
June 18th, 2007, 02:15 AM
| | | | 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. | 
June 18th, 2007, 02:35 AM
| | | | 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 | 
June 18th, 2007, 03:05 AM
| | | | 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 | 
June 18th, 2007, 06:55 AM
| | | | 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 | 
June 18th, 2007, 06:15 PM
| | | | 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 | 
June 19th, 2007, 01:05 AM
| | | | 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 | 
June 19th, 2007, 02:15 AM
| | | | 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);
}
| | 
June 19th, 2007, 03:45 AM
| | | | 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 | 
June 20th, 2007, 10:55 AM
| | | | 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) |  |
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 | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|