Jump to content
  • Advertisement
Sign in to follow this  
irreversible

Is there any way to pass a user-defined variable to a windows hook proc?

This topic is 2569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm hooking a menu window and I need to identify the menu object (or even just the original proc will do) in the eventual subclassed proc. However, since I don't know the menu's HWND handle before I reach the actual subclassed proc and I can't pass a user-defined parameter to CreateWindowsHookEx, I can't match the window handle I'm getting to even a globally stored proc or object/menu handle stack, since there's simply no way to correlate between the two (as far as I can see).


Note that this is relevant, because I'm working with more than one menu at a time.

Any ideas or clues?

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure of I followed 100%, but might it be possible to use SetWindowLongPtr http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898(v=vs.85).aspx with GWLP_USERDATA to attach custom identifier data to the window?

Share this post


Link to post
Share on other sites
That's the big problem. Allow me to elaborate:

Step 1)
HMENU m = CreatePopupMenu();
SetWindowsHookExW(WH_CALLWNDPROC, (HOOKPROC)HookProc, 0, GetCurrentThreadId());

Step 2)
In the hook proc, intercept HC_ACTION and call SetWindowLong() to subclass the window when the desired window class is created (by intercepting WM_CREATE)

Problem is, in the hook proc there is no longer a way to know what (eg which instance of the calling class) is initiating the call, because sending data between the two is impossible. In effect there's no way to set GWL_USERDATA, because in step 1 you only have a HMENU and no corresponding HWND and in step two you have a HWND and no corresponding HMENU. Moreover, there's no way to pass user data to SetWindowsHookEx(). Effectively, I don't see a way to link a HMENU to its hooked HWND, which is what I need.

I hope that's more clear :)

Share this post


Link to post
Share on other sites
If you don't mind me asking, I'm curious what you want to do that makes the menu's window's Proc unsuitable? I'm mainly asking because this is my first encounter of SetWindowsHookEx.

Share this post


Link to post
Share on other sites
Perhaps you can use SetMenuInfo to associate custom identifying data with the HMENU you created: http://msdn.microsoft.com/en-us/library/windows/desktop/ms647997(v=VS.85).aspx

Then in the handler, query the HMENU associated with the HWND that you receive using GetMenu: http://msdn.microsoft.com/en-us/library/windows/desktop/ms647640(v=VS.85).aspx

It might be possible to also query the HWND associated with a HMENU by using FindWindow: http://stackoverflow.com/questions/4347488/how-to-get-the-hwnd-from-hmenu , but I'm not completely certain that it will work.




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!