dreijer
dreijer

Reputation: 675

Preventing WM_SETCURSOR and WM_NCHITTEST messages from being generated

I'm making an application that hooks itself in to a target application and, when activated by the user, prevents all keyboard and mouse window messages from reaching the target application's window proc. My application does this by translating the incoming input messages, such as WM_MOUSEMOVE, to WM_NULL, so that the window proc is unaware input happened.

The problem is that Windows also automatically sends WM_SETCURSOR and WM_NCHITTEST to the window proc (e.g. when the application calls PeekMessage) when mouse input occurs. These messages aren't posted to the window's message queue, so I can't change them to WM_NULL.

I initially worked around this by subclassing the window proc and simply ignoring WM_SETCURSOR and WM_NCHITTEST there, but subclassing seems to have compatibility issues with some of the applications I'm hooked in to.

My question is: How do I prevent WM_SETCURSOR and WM_NCHITTEST from being generated in the first place OR how do I prevent them from reaching the application's window proc.

Upvotes: 3

Views: 1653

Answers (1)

phyatt
phyatt

Reputation: 19112

Some Ideas to Try

I just finished implementing a global/system wide CallWndRetProc with a WH_CALLWNDPROCRET Windows Hook (like it describes in the past post of the link below).

http://help.lockergnome.com/windows2/Igor-SetCursor-SetWindowsHookEx--ftopict285504.html

Using that in combination with hiding all the system cursors using SetSystemCursor has effectively hidden the cursor for most applications.

If you wanted to continue hacking at this target application, you could try using API Monitor to diagnosis what is going on: http://www.rohitab.com/apimonitor

The guy at rohitab hints at releasing his source code eventually; his site seems to have some of the better forums about Hooking, Subclassing, Injecting, etc.

It sounds like you successfully used SetWindowLongPtr(), but there are a few different ways to get into the address space of the program you are working on...

Have you tried SetCapture()?

Other Links

Here are a few other links that may be useful:

http://support.microsoft.com/kb/31747

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646262(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633569%28v=vs.85%29.aspx#winproc_subclassing

http://msdn.microsoft.com/en-us/library/windows/desktop/ms648395(v=vs.85).aspx

Hope that helps. Good luck.

Upvotes: 1

Related Questions