Creating a CStatic...

Hi,
I want to create a CStatic at running time, so I use this code:
CStatic *pStatic = new CStatic();
pStatic -> Create(msg, WS_CHILD | WS_VISIBLE | SS_LEFT, rectStatic, this);
My doubt is how to calculate the CRect (rectStatic) that fits to the message (msg) ?
[292 byte] By [raitz] at [2007-11-17 11:50:10]
# 1 Re: Creating a CStatic...
Theres two ways of doing this...first you'll have to find how many characters are in the array...you can use something like sizeof(array) divided by the size per character...e.g. if its not unicode its 8 bits per character.

Then you'll have to use the API GetTextMetrics to get the exact size's of the characters.

Alternatively you can use an approx for each charater ...such as

char msg[] = "Hellow cruel cruel world .";

RECT r;
r.top=0;
r.left=0;
r.right = (sizeof(&msg)/sizeof(char))*10; //10 is the approx width of char
r.bottom = 10; //approx height of char

char str[20]; //testing
sprintf(str,"%d",r.right);
MessageBox(str,"",MB_OK);

CStatic *s;
s = new CStatic();
s->Create(msg, WS_CHILD | WS_VISIBLE | SS_LEFT, r, this);
s->ShowWindow(SW_SHOW);

Well hope its been a help.

Voting is important :/
bkenwright at 2007-11-10 8:06:49 >