Get window position plus borders

This is a discussion on Get window position plus borders within the Windows Programming forums, part of the Platform Specific Boards category; How would I get a windows position, which includes its borders, of any window, whether that be a parent or ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    2

    Get window position plus borders

    How would I get a windows position, which includes its borders, of any window, whether that be a parent or child window? Now, I know about GetWindowRect, but that seems to be giving me the wrong coordinates. I tried using it on a button in a parent window with its x and y coordinates set to 0, and instead of the left and top returning 0, GetWindowRect took into account the absolute screen coordinates of the button, instead of the client coordinates plus the borders. Is there a function that does this, or a way to do this? I'm using c++. Thanks.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,025
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    GetWindowRect returns screen coordinates. You can convert to client coordinates with ScreenToClient.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,025
    GetClientRect returns client coordinates, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Quote Originally Posted by Elysia View Post
    GetClientRect returns client coordinates, as well.
    True, but GetClientRect will not include the borders etc.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,025
    I suppose that may be true...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    2
    Thanks! ScreenToClient worked perfectly.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Keep in mind there will be times when you want the opposite and you will use ClientToScreen(). Thankfully MS had the foresight to put these functions in b/c computing all that manually would be a major pain.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Something tells me you might find AdjustWindowRect() helpful.
    "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. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. Complete compilable createProcess Example needed
    By Extolfreak in forum Windows Programming
    Replies: 6
    Last Post: 01-17-2006, 04:52 AM
  5. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 08:23 AM

Tags for this Thread


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