Thread: how to get mouse movement? e.g. (up, down, left, right)

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    13

    how to get mouse movement? e.g. (up, down, left, right)

    Hi to everyone,

    I need again your help, this is regarding in getting the movement of the MOUSE in the
    window/screen if it goes up, down, left, right, i can do send message to the window to
    move the scrollbar left, right, up and down such as like below, but this is for SCROLLBAR
    what i need now is the movement of the MOUSE if i move it up it will say up state and down then down state.

    Sample code for scrolling the scrollbar by sending message.

    Code:
    //for vertical scrollbar
    SendMessage(hWnd, WM_VSCROLL, SB_LINEUP, SB_PAGEUP); 
    SendMessage(hWnd, WM_VSCROLL, SB_LINEDOWN, SB_PAGEDOWN); 
    
    //for horizontal scrollbar
    SendMessage(hWnd, WM_HSCROLL,  SB_LINERIGHT, 0);
    SendMessage(hWnd, WM_HSCROLL,  SB_LINELEFT, 0);
    I am using VisualC++ Visual Studio 2010 as my IDE and application using Win32

    I need immediate response please and will be appreciated.

    Thank you!

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    By searching I found this code:
    Code:
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        PAINTSTRUCT paintContext;
        HDC deviceContext;
        stringstream output;
    
        switch(message)                   /* handle the messages */
        {
            case WM_MOUSEMOVE:
                output << GET_X_LPARAM(lParam) << ", " << GET_Y_LPARAM(lParam);
                text = output.str();
                InvalidateRect(hwnd, NULL, false);
                UpdateWindow(hwnd);
                break;
    .....
    So you just need to read the message WM_MOUSEMOVE. About GET_X_LPARAM if they don't exist as functions google it (probably half lParam is the x-pos and the other half the y-pos). Google also if they are absolute or not parameters.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    13
    Quote Originally Posted by C_ntua View Post
    By searching I found this code:
    Code:
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        PAINTSTRUCT paintContext;
        HDC deviceContext;
        stringstream output;
    
        switch(message)                   /* handle the messages */
        {
            case WM_MOUSEMOVE:
                output << GET_X_LPARAM(lParam) << ", " << GET_Y_LPARAM(lParam);
                text = output.str();
                InvalidateRect(hwnd, NULL, false);
                UpdateWindow(hwnd);
                break;
    .....
    So you just need to read the message WM_MOUSEMOVE. About GET_X_LPARAM if they don't exist as functions google it (probably half lParam is the x-pos and the other half the y-pos). Google also if they are absolute or not parameters.
    hi thank you for reply, i just tried it to my code, and i have a question:
    who will call to this CALLBACK FUNCTION? I think i need this to register first this CALLBACK.

    cheers!

  4. #4
    Novice
    Join Date
    Jul 2009
    Posts
    568
    You don't need to register the callback function (aka "window procedure"), you need to register the window class. When you create a window class, you associate a callback function, that will process all messages for this window class, with it.

    Odds are, you already have a callback function. You should probably put the code for mouse message processing in that.

    The callback function is called by Windows (the OS), for message processing.

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    13
    I didnt create a window class, i was just using the existing classes, handles, handles windows (hwnd) that already created such as applications like, IE, Notepad, VS2010, those are the windows/applications i am using by just pointing the mouse using the functions:

    Code:
    GetCursorPos(&pos);
    WindowFromPoint(POINT point)
    i can get the handle of the specified application, now i need to see if the mouse i am using while pointing to the said applications can give me there MOVEMENT if there is a function for that.

    ---------
    thank u

  6. #6
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Ah. So you want to see mouse events received by other applications?

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    13
    Yes, if you have an idea if there is a function that will tell me if it goes up or down, or left or right.

    ---------
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  2. Controlling Mouse movement?
    By raum in forum Windows Programming
    Replies: 6
    Last Post: 07-02-2004, 08:46 AM
  3. Mouse Movement
    By Extol in forum Windows Programming
    Replies: 6
    Last Post: 04-22-2003, 08:48 PM
  4. Movement of the mouse
    By nep in forum Windows Programming
    Replies: 1
    Last Post: 05-19-2002, 05:32 AM
  5. Need to read mouse movement in program
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 01-03-2002, 02:15 PM