Thread: GetClientRect Issue

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    132

    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

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    132
    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

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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;
      }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    132
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. re-entrancy pattern issue setbacks
    By George2 in forum Windows Programming
    Replies: 0
    Last Post: 04-12-2008, 02:23 AM
  3. type safe issue
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 09:32 PM
  4. Replies: 8
    Last Post: 01-17-2006, 05:39 PM
  5. my first issue of GDM
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-12-2002, 04:02 PM