GetCursor pos troubles

This is a discussion on GetCursor pos troubles within the Windows Programming forums, part of the Platform Specific Boards category; Okey dokey I'm having some problems with GetCursorPos, it's giving me really bad coordinates... or maybe it's something else I'm ...

  1. #1
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293

    GetCursor pos troubles

    Okey dokey I'm having some problems with GetCursorPos, it's giving me really bad coordinates... or maybe it's something else I'm unsure.

    Code:
     case WM_LBUTTONDOWN:
        {
            if(sel[0] == 1)
            {
              SetCapture(hwnd);
              GetCursorPos(&sPos);
              break;
            }
        }
        case WM_LBUTTONUP:
        {
            if(sel[0] == 1)
            {
              POINT pos;
              GetCursorPos(&pos);
              ScreenToClient(hwnd,&pos);
              ScreenToClient(hwnd,&sPos);
              DrawControl(sel[1],sPos,pos);
              ReleaseCapture();
              sel[0] = sel[1] = 0;
            }
        }
    sPos is defined at the top to keep it in scope for WM_LBUTTONUP.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Did you declare it as static? If not, chances are it'll contain garbage values for the UP message.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    Are you intentionally allowing case statements to "fall through" to the next case?
    Missing some "breaks" perhaps?

    gg

  4. #4
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    Yeah I had fixed that after posting, it was messing up some other switch's as well ... I tried setting static POINT pos; but still it's going weird.

    It's actually not realy sPos that's wrong I think, the start of the retangle is usually right but it's the width and height that are way out of whack.

  5. #5
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    [edit:] Doh! Of course, so stupid!

    pos.x -= sPos.x;
    pos.y -= sPos.y;

    I wasn't actually adding distance relative to sPos relative to parent.

    Thanks anyways!
    Last edited by Mithoric; 12-22-2003 at 01:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-15-2006, 05:14 AM
  2. Console-based file i/o troubles
    By Callith in forum C++ Programming
    Replies: 3
    Last Post: 12-25-2004, 09:22 PM
  3. sscanf troubles
    By williams75 in forum C Programming
    Replies: 5
    Last Post: 11-17-2002, 02:51 AM
  4. More Program Troubles...
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 06:40 AM
  5. having troubles
    By neandrake in forum C++ Programming
    Replies: 7
    Last Post: 03-07-2002, 09:31 PM

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