GetClientRect not pixel-perfect...

This is a discussion on GetClientRect not pixel-perfect... within the Windows Programming forums, part of the Platform Specific Boards category; I've been making a 2D game with D3D and I'd like to implement the mouse to work with it. I've ...

  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 05:57 PM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    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,859
    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,859
    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, 09:55 AM
  2. Pixel perfect collision / "terrain" destruction
    By cboard_member in forum Game Programming
    Replies: 1
    Last Post: 09-09-2006, 01:54 PM
  3. 2D pixel perfect collision detection
    By Warlax in forum Game Programming
    Replies: 0
    Last Post: 06-22-2006, 08:39 AM
  4. Pixel perfect 2D collision detection with Allegro
    By Warlax in forum C++ Programming
    Replies: 1
    Last Post: 06-21-2006, 03:14 PM
  5. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 12:09 PM

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