Thread: Cursor Position

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Cursor Position

    Quick question?

    What class in MFC holds all the mouse functions if there is one????? I need to retrieve the mouse coordinates as soon as the left mouse button is pressed and set the mouse position to those same coordinates when the screen is refreshed. This is in an MFC app. Any suggestions????????

    Thanks,
    Kendal

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    I think the mouse message returns the coordinates of the mouse in the lparam and wparam. Not sure exactly.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    5
    Yup.

    Code:
    afx_msg void OnLButtonDown(
       UINT nFlags,
       CPoint point 
    );
    The second param specifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Of course you can always call into the WinAPI directly. GetCursorPos is what you want.

    There IS a method of some class in MFC too, but I can't remember it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Here is an addition to the question.

    The GetCursorPos and SetCursorPos works, but I need to get and set the cursor position in relation to the window, not the screen. What function or method do I need to go about getting the position in the window and not the screen??????


    Thanks,
    Kendal

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    I am sorry.

    I just realized that I should have posted this thread in the Windows Programming Forum. Forgive Me.

    Kendal

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I'm too lazy to search for the new thread now (if there is one), use ScreenToClient and ClientToScreen to convert between screen and window coordinates.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    5
    My responce was the name of the method in CWnd.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That's just a message handler Gareth. Of course he can use it to keep a constantly updated mouse position, but why when windows does it too?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    WM_LBUTTON or OnLButtonDown WM_LBUTTONUP msgs

    look at

    SetCapture()
    ReleaseCapture()
    ClipCursor()

    ect
    "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