Windows Hook to catch WM_MDITILE (using good old C++)
I know everyone is off to great mobile or web type work. Well, I'm stuck here on some good old C++. Here's whats bugging me.
I want my application to do a certain thing when开发者_如何转开发 the user presses the menu "Tile Vertically" in another app (in another process). (Many apps have a menu "Windows" and underneath that is a sub menu "Tile Vertically"). I'm under the assumption that I need to setup a global hook using SetWindowsHookEx. I tried doing that using "WH_CALLWNDPROC" and was only able to hook to "in process" messages, not "out of process". I tried WH_GETMESSAGE as well. I tried catching WM_SIZE, that also did not work out of process. In fact, even in process, WM_SIZE didn't work on all windows , only on some of them.
So now there are a few questions:
1- What is the right type of hook (WH_CALLWNDPROC or WH_GETMESSAGE or perhaps one of the other hook types that can be used)?
2- How do I get it to pick up out of process messages?
3- Any tips where I can get sample hook code for WM_MDITILE?
4- I tried doing a keyboard hook and that worked, why doesn't this work?
5- I'm using a win 32 dll with the DllMain code below. Is there anything wrong with it?
HINSTANCE hinst;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//
// Capture the application instance of this module to pass to
// hook initialization.
//
if (hinst == NULL)
{
hinst = hModule;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Any tips or suggestions?
Thanks
May be you should try WH_MSGFILTER or WH_SYSMSGFILTER? It looks like these IDs are dedicated to monitor messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar.
For more details reffer to link below:
http://msdn.microsoft.com/en-us/library/ms644990(v=vs.85).aspx
精彩评论