Skip to content

Instantly share code, notes, and snippets.

@vshmoylov
Last active July 10, 2018 23:21
Show Gist options
  • Save vshmoylov/4bb2c59257a7222e1f9a060d772c8f24 to your computer and use it in GitHub Desktop.
Save vshmoylov/4bb2c59257a7222e1f9a060d772c8f24 to your computer and use it in GitHub Desktop.
Smart scrolling hook dll for win2k - win7. Compile: cl XScrollHook.c /MD /LD /link User32.lib
#include <Windows.h>
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpReserved)
{
return 1;
}
LRESULT CALLBACK MouseXScrollHook(int code, WPARAM wParam, LPARAM lParam ) {
POINT cursorPosition = {0};
HWND desiredWindow = 0;
DWORD processId = 0;
if ( code >= 0 ) {
if ( lParam ) {
PMSG message = (PMSG)lParam;
if ( message->message == WM_MOUSEWHEEL ) {
GetCursorPos(&cursorPosition);
desiredWindow = WindowFromPoint(cursorPosition);
if ( desiredWindow && message->hwnd != desiredWindow ) {
SendMessageA(desiredWindow, WM_MOUSEWHEEL, message->wParam, message->lParam);
message->message = WM_NULL;
message->wParam = 0;
message->lParam = 0;
}
}
}
}
return CallNextHookEx(NULL, code, wParam, lParam);
}
__declspec(dllexport) HHOOK __cdecl BindXScrollHook(HINSTANCE myInstance){
return SetWindowsHookExA(WH_GETMESSAGE, MouseXScrollHook, myInstance, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment