Thread: screen coordinates from MSG

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

    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.
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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 07: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
    930
    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 ()
    Using Windows 10 with Code Blocks and MingW.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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 10: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
    930
    Thanks to you!
    Using Windows 10 with Code Blocks and MingW.

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, 04:56 PM
  2. Screen coordinates and mouse pointer manipulation
    By Zewu in forum Windows Programming
    Replies: 1
    Last Post: 03-25-2005, 05:30 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10: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