MouseWheel Event

Posts 1–6 of 6 · Page 1 of 1
MouseWheel Event
Hi all, I'm trying to handle the mousewheel event without any succes... Does someone know how to do it?
Handling? Do you mean something like this:

Code:
#include <iostream>
#include <windows.h>

using namespace std;

HHOOK hHock = NULL;
LRESULT CALLBACK LowLevelMHook( int nCode , WPARAM wParam , LPARAM lParam);

int WINAPI main(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdParam, int iCmdShow)
{
    MSG msg;

    hHock = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMHook , 0,0);

    while(!GetMessage(&msg, 0, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    UnhookWindowsHookEx(hHock);
    return 0;
}

LRESULT CALLBACK LowLevelMHook ( int nCode , WPARAM wParam , LPARAM lParam)
{
    MSLLHOOKSTRUCT LLMouseStruct = *(MSLLHOOKSTRUCT*)lParam;
    if(wParam==WM_MOUSEWHEEL)
    {
        int MouseData = (int)LLMouseStruct.mouseData;
        if(MouseData < 0)
        {
            cout << "MW DOWN!\n";
        }
        else
        {
            cout << "MW UP!\n";
        }
    }
    return CallNextHookEx(hHock, nCode, wParam, lParam);
}
If not, please tell us what you want to do!
Yes, this is what I meant. Thanks.

Does this work on console? Because I'm getting the unresolved external symbol error for the main function...
Quote Originally Posted by Sixx93 View Post
Yes, this is what I meant. Thanks.

Does this work on console? Because I'm getting the unresolved external symbol error for the main function...
Code:
#include <iostream>
#include <windows.h>

using namespace std;


HHOOK hHock = NULL;
LRESULT CALLBACK LowLevelMHook( int nCode , WPARAM wParam , LPARAM lParam);

int main()
{
    MSG msg;

    hHock = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMHook , 0,0);

    while(!GetMessage(&msg, 0, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    UnhookWindowsHookEx(hHock);
    return 0;
}

LRESULT CALLBACK LowLevelMHook ( int nCode , WPARAM wParam , LPARAM lParam)
{
    MSLLHOOKSTRUCT LLMouseStruct = *(MSLLHOOKSTRUCT*)lParam;
    if(wParam==WM_MOUSEWHEEL)
    {
        int MouseData = (int)LLMouseStruct.mouseData;
        if(MouseData < 0)
        {
            cout << "MW DOWN!\n";
        }
        else
        {
            cout << "MW UP!\n";
        }
    }
    return CallNextHookEx(hHock, nCode, wParam, lParam);
}
That should work.
Quote Originally Posted by Harava View Post
That should work.
Yeah! Thanks dude, this is what I've been looking for
One last thing...

I'm having some problem with the window closing, I mean, when I press the "x" button of the app, it doesn't close. Maybe because that event isn't handled because of the hook?

Edit:

Solved, request close.
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us