Hooking mouse things like wheel up from another window.

Hello!

I need to somehow hook the SDL created window mouse events ( wheel up and down )
Somehow, in sdl mouse wheel does not seems to work at all...
Found the function: FindWindow
Now i have to get msg somehow.

How can i do this?
Thanks!
You can use GetWindowLongPtr and SetWindowLongPtr to get/change a window's WindowProc function. From there you can catch the messages and do your own processing.

Though I never tried to do this out of the current process. It might not work due to security issues.
Last edited on
Security might a problem depending on the platform. In Windows you should be able to get away with this if you enable the "SeDebugPrivilege" in Explorer.exe and as long as your hook process resides in the same session as the target window.

EDIT: If that doesn't work then an injected thread or DLL should have access to the target processes message queue.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
LONG_PTR CALLBACK testcallback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

LONG_PTR CALLBACK testcallback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	// cout << "got callback!" << endl;
	cout << "uMsg:" << uMsg << endl;
	return -1;
}


HWND test = FindWindow(NULL, L"mytestwind");
LONG_PTR dontknowwhattodowithit = SetWindowLongPtr(test, GWLP_WNDPROC, (LONG_PTR)testcallback);


It is working but it break my loop.
After registering this testcallback get callback everyframe like this is my new loop.
It is stopping all sdl works, opengl wont work because of that.

I cant somehow stop it. I have no idea what to do next.
I guess i must find a way to hook that mouse wheel up and down in sdl somehow. Im out of ideas...
Last edited on
After registering this testcallback get callback everyframe like this is my new loop.


Well.. yeah...

Your callback is being called for every single message that the window receives. You'll have to filter out the messages you're interested in by looking at the uMsg parameter (ie: look for WM_MOUSEWHEEL)

You'll probably want to call the original window's message handler as well.. so the actual window doesn't just stop responding.
Can you give me an example code?
Im kind a new in c++.
I did it!
1
2
3
4
5
	// cout << "got callback!" << endl;
	cout << "uMsg:" << uMsg << endl;
	DefWindowProc(hwnd, uMsg, wParam, lParam);
	fp_gameframe();
	return 0;


Now sdl is not responsing.
Functions of sdl wont work.
When you call SetWindowPtrLong to change the window proc, that's exactly what you are doing... you are changing the window proc.

This means that whatever window you're looking at will no longer have messages sent to its window proc. Windows will be calling YOUR function instead.

So you need to use GetWindowPtrLong to get the original window proc... and forward all these messages to it after you do your own processing.
Topic archived. No new replies allowed.