Thread: GetClientRect not pixel-perfect...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up (Win32) GetClientRect not pixel-perfect...

    I've been making a 2D game with D3D and I'd like to implement the mouse to work with it. I've come up with an algorithm that works fine but the only problem is, is that I'm basing it off the size of the client area of the window. After looking long and hard to what is wrong, I found that getting the coordinates from GetClientRect() is slightly off. The X value is fine but the Y is off by ~20 when the window is at 800x800 (I have no menus or anything else special on the window). Is this true or am I going crazy and is there a way around this, because this takes away a lot of accuracy from the cursor.

    Cheers.
    Last edited by yaya; 10-05-2009 at 04:57 PM.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Sounds like you either need to convert from screen coords to client coords or vice versa.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Just to note as well.....

    Toolbars are included in the client area, that is; Y==0 is under the toolbar.
    "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

  4. #4
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    There's no toolbars or anything in there. I'll go back through my code later and make sure (I'm probably wrong). If there is, I'll try and rack up some proof.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    As Bubba said it is probably a screen to client issue.

    Mouse coords are relative to the top left of the screen (in screen coords).

    Client rects are relative to the top left of the window's client area (excluding menu but not toolbar).

    If your window is almost full screen you may not have noticed this.

    Try converting using ClientToScreen() or ScreenToClient() .
    "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. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. Pixel perfect collision / "terrain" destruction
    By cboard_member in forum Game Programming
    Replies: 1
    Last Post: 09-09-2006, 12:54 PM
  3. 2D pixel perfect collision detection
    By Warlax in forum Game Programming
    Replies: 0
    Last Post: 06-22-2006, 07:39 AM
  4. Pixel perfect 2D collision detection with Allegro
    By Warlax in forum C++ Programming
    Replies: 1
    Last Post: 06-21-2006, 02:14 PM
  5. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 11:09 AM