By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

Trying to create an array.

P: 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.
Jun 17 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Vitor wrote:
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
Jun 17 '07 #2

P: n/a
"Vitor" <no**@yahoo.netwrote in message
news:46***********************@roadrunner.com...
>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.
Jun 17 '07 #3

P: n/a
"Jim Langston" <ta*******@rocketmail.comwrote in message
news:el************@newsfe03.lga...
"Vitor" <no**@yahoo.netwrote in message
news:46***********************@roadrunner.com...
>>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 };
Jun 17 '07 #4

P: n/a
Jim Langston wrote:
"Vitor" <no**@yahoo.netwrote in message
news:46***********************@roadrunner.com...
>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:
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.
Jun 17 '07 #5

P: n/a

Default User <de***********@yahoo.comwrote in message ...
Vitor wrote:
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
Jun 17 '07 #6

P: n/a
Vitor wrote:
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);

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Jun 17 '07 #7

P: n/a

Vitor wrote in message...
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:
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
Jun 18 '07 #8

P: n/a
Jim Langston wrote:
"Jim Langston" <ta*******@rocketmail.comwrote in message
news:el************@newsfe03.lga...
>"Vitor" <no**@yahoo.netwrote in message
news:46***********************@roadrunner.com.. .
>>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.
Jun 18 '07 #9

P: n/a
BobR wrote:
Vitor wrote in message...
>>>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:
>> 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
Jun 18 '07 #10

P: n/a
Thomas J. Gritzan wrote:
Vitor wrote:
>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);
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
Jun 18 '07 #11

P: n/a
BobR wrote:
>
Default User <de***********@yahoo.comwrote in message ...
Vitor wrote:
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
Jun 18 '07 #12

P: n/a

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

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>
>
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
Jun 18 '07 #13

P: n/a
BobR wrote:
Grzegorz Wróbel </dev/nu**@localhost.localdomainwrote in message...
>BobR wrote:
>>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>
>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
Jun 19 '07 #14

P: n/a
Thomas J. Gritzan wrote:
Vitor wrote:
>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:
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);
}
Jun 19 '07 #15

P: n/a
Vitor wrote:
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:
> 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
Jun 19 '07 #16

P: n/a
"Vitor" <no**@yahoo.netwrote in message
news:46***********************@roadrunner.com...
Thomas J. Gritzan wrote:
>Vitor wrote:
>>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:
> 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)















> }

Jun 20 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.