Thread: Get size of client window

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    Get size of client window

    Hi I am trying to find some function which would return a lenght and height of current window in pixels... I tried GetSystemMetrics() but it didnt work properly...

    Is there any other way how to find out these two values?

    Thx

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Isn't there a getClientRect type function?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Yes. And GetWindowRect. A search would've found both.

    See also SystemParametersInfo(SPI_GETWORKAREA flag) if you just need to adjust GetSystemMetrics results to account for the taskbar.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Quote Originally Posted by Salem View Post
    Isn't there a getClientRect type function?
    Thank you this one work well

  5. #5
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Quote Originally Posted by Ken Fitlike View Post
    Yes. And GetWindowRect. A search would've found both.

    See also SystemParametersInfo(SPI_GETWORKAREA flag) if you just need to adjust GetSystemMetrics results to account for the taskbar.
    Thanks for that tidbit Ken, I knew there had to be a simpler way. Up until now, I had been using:
    y = GetSystemMetrics(SM_CYVIRTUALSCREEN) to get the height of the window
    hTaskBar = FindWindow("Shell_TrayWnd") to find the handle to the taskbar/tray
    GetWindowRect(hTaskBar, &trayRect)
    and finally,
    WorkAreaY = y - (trayRect.top - trayRect.bottom)

    While were on the topic of insanely complex methods of handling relatively simple problems, would you know a simple way of how to set a window's client size? So far I've been using SetWindowPos(), but since this uses total size, I have to then compensate for title bar thickness by calling GetTitleBarInfo().rcTitleBar.(bottom - top) first :S

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by @nthony View Post
    While were on the topic of insanely complex methods of handling relatively simple problems, would you know a simple way of how to set a window's client size? So far I've been using SetWindowPos(), but since this uses total size, I have to then compensate for title bar thickness by calling GetTitleBarInfo().rcTitleBar.(bottom - top) first :S
    AdjustWindowRect() //calcs the window size based on the supplied/required client area and window style.

    This can then be passed to SetWindowPos() ect.
    Last edited by novacain; 10-15-2007 at 12:27 AM.
    "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

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. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM