py2akv wrote:
> Good morning,
>
> Out of curiosity, tried to calculate the width and height of a
> Windows message box, but the value of r->right (only r->right)
> varies from session to session.
>
> r->left = 0, obviously;
> r->top = 0, obviously;
> r->right = 0(!), 117, 118 (the most frequent), 124, 177, etc.;
> r->bottom = 15;
>
> I ask my colleagues who program for Windows to review what's wrong
> with this code and all the others to run it in order to see if r-
>> right varies so greatly.
>
> If anyone has a proven recipe to work out the dimensions of a
> message box, it would be highly welcomed.
>
> #include <windows.h>
> #include <stdio.h>
>
> int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
> {
> HWND hwnd = FindWindow(NULL, "");
> LPRECT r;
> GetClientRect(hwnd, r);
>
> char b[128];
> sprintf(b, "%d %d %d %d (left, top, right, bottom)",
> r->left, r->top, r->right, r->bottom);
>
> MessageBox(NULL, b, "Message Box", MB_OK);
>
> return 0;
> }
>
> Best,
>
> Geraldo
You are measuring the first top-level window in the window stack - NOT
necessarily a message box and the window handle you retrieve could be
hidden for all you know. Additionally, message boxes are almost always
child windows, which means this code will basically never work. You are
also using the wrong measurement function. GetClientRect() retrieves
the client area (the area inside the window borders and menu bar) - the
area an application can draw on. GetWindowRect() retrieves the window's
location and size on the screen.
The MessageBox() API is a black box that drops a modal dialog onto the
app. I'm not sure why you want to do this, but whatever it is, it is
probably a bad idea and/or is the wrong approach to the problem.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/