Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi??

I want change array format.

C++
int i;
CRect rCtrlA(14,322,101,359);
CRect rCtrlB(104,322,210,359);
CRect rCtrlC(213,322,319,359);
CRect rCtrlD(322,322,428,359);
CRect rCtrlE(430,322,536,359);
CRect rCtrlF(538,322,624,359);

// i want put CRect on my for loop.

for(i=0; i<6;i++)
{
   m_pTabRadio[i].Create(NULL, WS_CHILD|WS_VISIBLE, rCtrlA, this, IDC_RADIO_MAINTAB+i);

}
Posted

1 solution

You have two choices to statically initialize an array of CRect:
C++
CRect rCtrs [6] = {
    CRect (14, 322, 101, 359),
    CRect (104, 322, 210, 359),
    ...
};

or
C++
RECT rCtrs [6] = {
    14, 322, 101, 359,
    104, 322, 210, 359,
    ...
};

But even better would be that you just calculate the coordinates of your rects in the loop:
C++
const int horSpacing = 100;
const int gapWidth = 3;
for (i=0; i<6; ++i)
{
    CRect r (0, 322, 0, 359);
    r.left = 14 + i*horSpacing;
    r.right = r.left + horSpacing - gapWidth;
   ...

That gives you a perfectly even spacing and is easier to maintain in case the dimensions of your dialog change or the number of your controls grows.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900