-
GetClientRect Issue
When I call GetClientRect() it's not even returning half the size that my client's area fills. Why is this? My screen resolution is set to 1600x1200 and I am creating my window with WS_MAXIMIZED style set. Then when I call GetClientRect() my values are as follows:
Left: 0 Right: 634
Top: 0 Bottom: 448
(tested using a MessageBox to display the return values)
Am I just using the wrong function call? Or is this call just not working for some reason? Also I am creating my child window using the following values:
x=0;
y=0;
nwidth=rect.right-rect.left;
nheight=rect.bottom-rect.top;
So this is not even covering half of my window (and yes I will be adding support for window size changes). Any help would be greatly appreciated.
Thanks
Tyouk
-
Check the lParam (CREATESTRUCT) of WM_CREATE to see what your window dimensions are at that point. If you want to create a window that fills the desktop then use GetSystemMetrics to get the screen dimensions or, if you want to maximise the window, use ShowWindow. For responding to changes in your window's dimensions, handle the WM_SIZE message; the client dimensions are packed into the lParam of that message and you can maintain relative sizes/positions of your child controls more easily from there.
-
Hmmm... I have no idea how to check the (CREATESTRUCT)lParam. I've tried many things such as:
CREATESTRUCT create = (CREATESTRUCT)lParam; // then trying to access it... get an error
I've tried accessing the elements of the CREATESTRUCT as so:
(CREATESTRUCT)lParam.cy // and ->cy to no avail
Can anyone shed some light on this situation, I guess I never really had to do anything like this before (as far as I can tell). It's most likely something really easy that will make me look like an idiot though, right? lol
Thanks for any help.
Tyouk
-
Code:
case WM_CREATE:
{
/*comparison of CREATESTRUCT*, GetWindowRect and GetClientRect dimensions*/
RECT rc,rcClient;
CREATESTRUCT *cs=(CREATESTRUCT*)lParam;
TCHAR buffer[256];
GetWindowRect(hwnd,&rc);
GetClientRect(hwnd,&rcClient);
wsprintf(buffer,
_T("CREATESTRUCT values:\n")
_T("Left: %d\n")
_T("Top: %d\n")
_T("Width: %d\n")
_T("Height: %d\n\n")
_T("GetWindowRect results:\n")
_T("Left: %d\n")
_T("Top: %d\n")
_T("Width: %d\n")
_T("Height: %d\n\n")
_T("GetClientRect results:\n")
_T("Width: %d\n")
_T("Height: %d\n\n"),
cs->x,cs->y,cs->cx,cs->cy,
rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,
rcClient.right,rcClient.bottom);
MessageBox(hwnd,buffer,_T("WM_CREATE: Window Dimensions"),MB_OK);
return 0;
}
-
Ya I figured out how to get the values. Thanks though. What I ended up having to do was create the control in the WM_CREATE and then when a WM_SIZE message was rec'd use the MoveWindow() function to resize it as appropriate (the size of the originally created window was infact the sizes I was getting and so because of the WS_MAXIMIZE style being set it was being maximized when created, but wasn't being created with the maximum size).
Thanks,
Tyouk