screen coordinates from MSG

This is a discussion on screen coordinates from MSG within the Windows Programming forums, part of the Platform Specific Boards category; How do you get them? Code: while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } cout << Msg.(&pt) <<"\n"; ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    764

    screen coordinates from MSG

    How do you get them?

    Code:
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
              TranslateMessage(&Msg);
              DispatchMessage(&Msg);
        }
    
     cout << Msg.(&pt) <<"\n";
     or
     cout << Msg->pt <<"\n";
    These dont work.
    Compiler MSVC++ 2010 with Code::Blocks.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Usually you process messages in the callback.

    Would be easier if you gave more detail of what you want to do (you seem unfamilar with event driven apps). The while loop you posted is a 'message pump'. The only time that while loop ends is when the app closes.

    If you just want to get the current mouse position use GetCursorPos().
    [note that the point returned is in screen coords]

    The trouble is knowing when you need to get the pos....
    Last edited by novacain; 12-10-2009 at 06:14 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

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    764
    Thank you Novocain!

    Yeah thats ok im just checking out the messages sent to the window just for fun.

    I could check out

    Code:
    cout << Msg.wParam <<"\n";
    and all the rest in the MSG structure except im having trouble with pt.

    So i guess i should know if it has two or four coordinates, its not said on msdn.

    MSG Structure ()
    Compiler MSVC++ 2010 with Code::Blocks.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Each message has different values sent in the wParam and lParam.

    Generally mouse click coord are in the lParam, two ints 'packed' into the DWORD. You have to check what to expect from each msg as some do not send either or both.

    Mouse msgs are generally client coords (0,0 is the top left of your dialog, not the screen).

    Code:
    //for WM_LBUTTONDOWN etc
    
    cout << LOWORD(msg.lParam) <<" \n"; //or GET_X_LPARAM()
    cout << HIWORD(msg.lParam) <<" \n";
    Last edited by novacain; 12-10-2009 at 09:33 PM.
    "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

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    764
    Thanks to you!
    Compiler MSVC++ 2010 with Code::Blocks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  2. Screen coordinates and mouse pointer manipulation
    By Zewu in forum Windows Programming
    Replies: 1
    Last Post: 03-25-2005, 04:30 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM

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