473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Trying to create an array.

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
16 1514
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
"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
"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
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

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

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

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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Garry Freemyer | last post by:
I'm trying to convert this macro to a c# function but I have a big problem. It's on the LEFT side of an assignment statement and I am extremely flustered over this one because I'm a little rusty...
2
by: Dave | last post by:
I know in C++ you can create class templates so the data type can be defined during the declaration of an instance of a class. I was trying to do something like that for a VB.NET class cut am not...
5
by: Simon Dean | last post by:
Hello, Im hoping you can help me. Im, probably not that advanced with PHP, well, I probably am, but with a memory like a sieve, I rarely take in information... But, Im just considering some...
4
by: rhaazy | last post by:
I have created this very primitive class for the purpose of performing some simple recursive functions. I am new to C++ and the concept of classes all together. I put this together using various...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
0
by: centos123 | last post by:
Hi I am trying to build an array out of an input text file as shown below. pattern1 SAF 10 1 10 CLB 20 18 10 11 pattern2 SAF 20 1 10 11
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
6
by: The Natural Philosopher | last post by:
I am trying to create what amounts to an array of 'structures'. I.e. I want to dynamically add to and access an object as myobject.anothernumber // actually represents a nesting level. and ...
7
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.