Sign in to follow this  
owl

Ms. Windows Hooking. Can I stop an app from recieving a shortcut message?

Recommended Posts

Yes sorry:

I want to catch an application defined shortcut (hot-key) command message before it reaches the target window. (if that's really the way hotkeys work, I've seen that Spy++ catchs WM_ messages related to shortcuts but I'm not really sure if they are the same).

I'm using hooking in a plug-in that hides an application's menu, but in some special parts of this app, there is a hot key that re-enables the menu, and I don't want that to happen.

Share this post


Link to post
Share on other sites
you can do everything.
inject the dll in the target process, subclass the window, if you recognize a message you want to trap, just don't forward it to the original wiindow procedure..
that helps ?

Share this post


Link to post
Share on other sites
heh, yes. My mind just made the "click".

Once I hook the thread I want, I just set my own wndproc as I would normally do with my own windows? Isn't? I guess that's what hooking is all about :) I'm new to this stuff...

So inside my DLL I would catch all messages and if the window that message is going to has the title I want, I just set my own wndproc to that window like this:



(WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)MyOwnWndProc);



Thank you. You've just been rated.

Share this post


Link to post
Share on other sites
yes, that's about it, once you get your dll injected in the target process, you can access all its memory, a simple (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)MyOwnWndProc); will do the job fine. don't forget to restore the original proc when you quit if you don't want the target process to crash.

one thing that bugged me : SetWindowLong will return a HANDLE to the previous window proc, on some win32 platforms, this HANDLE is nothing more than the pointer to the procedure, and on some other win32 platforms, it's really a HANDLE.. then always use the CallWindowProc(...) API to forward the messages.

in fact, hooking is only used to inject the dll in the target process space, but you could do it diferently.
replacing a window proc is called subclassing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this