Getting Window Dimentions

This is a discussion on Getting Window Dimentions within the Windows Programming forums, part of the Platform Specific Boards category; How would I get the current length and width of my window? (seperately prefered)....

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902

    Getting Window Dimentions

    How would I get the current length and width of my window? (seperately prefered).
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    Use GetClientRect():

    BOOL GetClientRect(

    HWND hWnd, // handle of window
    LPRECT lpRect // address of structure for client coordinates
    );
    Parameters

    hWnd

    Identifies the window whose client coordinates are to be retrieved.

    lpRect

    Points to a RECT structure that receives the client coordinates. The left and top members are zero. The right and bottom members contain the width and height of the window.

  3. #3
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hey,

    Just a side note as that should be what you want but you said window dimentions.

    Use GetWindowRect().

    Thanks
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  4. #4
    Registered User ExDigit's Avatar
    Join Date
    Jan 2002
    Posts
    31
    As an addition to these.. this is what the RECT structure is:
    The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.

    typedef struct _RECT { // rc
    LONG left;
    LONG top;
    LONG right;
    LONG bottom;
    } RECT;


    Members

    left

    Specifies the x-coordinate of the upper-left corner of the rectangle.

    top

    Specifies the y-coordinate of the upper-left corner of the rectangle.

    right

    Specifies the x-coordinate of the lower-right corner of the rectangle.

    bottom

    Specifies the y-coordinate of the lower-right corner of the rectangle. The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.

    typedef struct _RECT { // rc
    LONG left;
    LONG top;
    LONG right;
    LONG bottom;
    } RECT;


    Members

    left

    Specifies the x-coordinate of the upper-left corner of the rectangle.

    top

    Specifies the y-coordinate of the upper-left corner of the rectangle.

    right

    Specifies the x-coordinate of the lower-right corner of the rectangle.

    bottom

    Specifies the y-coordinate of the lower-right corner of the rectangle.
    Good luck.

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    How do I get dimentions out of that?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  6. #6
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Well it should be self-explanatory, but...

    Code:
    RECT *rect;
    ...
    GetWindowRect(hwnd, rect);
    then, as was stated already

    left

    Specifies the x-coordinate of the upper-left corner of the rectangle.

    top

    Specifies the y-coordinate of the upper-left corner of the rectangle.

    right

    Specifies the x-coordinate of the lower-right corner of the rectangle.

    bottom

    Specifies the y-coordinate of the lower-right corner of the rectangle.
    so rect.left would now be the x-coordinate of the upper-left corner of the window, rect.top would be the y-coordinate of the upper-left corner of the window, etc.

  7. #7
    Registered User ExDigit's Avatar
    Join Date
    Jan 2002
    Posts
    31
    Just incase you're still stuck.. uhm.. I doubt you are..

    Width = Rect.right - Rect.left;
    Height = Rect.bottom - Rect.top

    But that's obvious..

  8. #8
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    RECT *rect;
    ...
    GetWindowRect(hwnd, rect);

    No, it's.....

    RECT rect
    ...
    GetWindowRect(hWnd,&rect)

    btw, thanx ExDigit
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  9. #9
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    that's what I get for typing fast

  10. #10
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    Hey, thanks anyways. I got what I needed from you guys.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  11. #11
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I get them in WM_SIZE:

    Code:
    case WM_SIZE:
        cxClient = LOWORD(lParam);
        cyClient = HIWORD(lParam);
    1978 Silver Anniversary Corvette

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Or for the whole screen

    Code:
    iWidth	=GetDeviceCaps(GetDC(NULL) ,HORZRES);
    iHeight	=GetDeviceCaps(GetDC(NULL) ,VERTRES);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Red face & Anoter as im bored...

    Hey another for screen dimensions:

    Code:
    int cx = GetSystemMetrics(SM_CXSCREEN);
    int cy = GetSystemMetrics(SM_CYSCREEN);
    Cheers
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  14. #14
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    If you're using MFC:

    CRect rect;

    It has member functions like
    rect.Width();
    rect.Height();
    and many more.
    You aquire the rect the same way as with the regular RECT structure
    Don't talk to strangers, unless they offer candy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21