Trying to create an array.

V

Vitor

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.
 
D

Default User

Vitor said:
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
 
J

Jim Langston

Vitor said:
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.
 
J

Jim Langston

Jim Langston said:
Vitor said:
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 };
 
V

Vitor

Jim said:
Vitor said:
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.
 
B

BobR

Default User said:
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>
 
T

Thomas J. Gritzan

Vitor said:
Jim said:
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);
 
B

BobR

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
 
V

Vitor

Jim said:
Jim Langston said:
Vitor said:
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.
 
?

=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=

BobR said:
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.
 
?

=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=

Thomas said:
Vitor said:
Jim said:
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);
 
B

BobR

Grzegorz Wróbel said:
1) RECT is predefined Windows struct not a macro.

Sorry about that said:
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<MyRect> VecArray;
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
}
 
?

=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=

BobR said:
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<MyRect> VecArray;
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.
 
V

Vitor

Thomas said:
Vitor said:
Jim said:
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);
}
 
?

=?ISO-8859-1?Q?Grzegorz_Wr=F3bel?=

Vitor said:
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.
 
J

Jim Langston

Vitor said:
Thomas said:
Vitor said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top