There may be a lot of people who, like me, are envious of the shadow effects of the menus in Office XP, which do not need to be shaded behind menus in Windows XP, and, of course, have full support for menu shading in Windows XP. Although it is not necessary for us to achieve this difficult effect on our own. But just as many people want to implement the IE-style menu bar, they can make our programs look different, even if they don't bring us more practical features. :)
menu is also a window, if we can get the handle of its window, to achieve the effect like adding shadows, it will not be difficult. It's a pity we can't find where this window was created, and it's not easy to get its window handle, it's even hard to believe it's a window, because I really can't find its window handle. I finally found a way to "study" the source code of many of the classes that others have already done. That is the universal hook, if said in the windows to catch "people", even the hook can not do, then I do not know what method to achieve, hehe.
Now let's take a look at how to catch these "damned" guys. In order to facilitate the transplant, we will write a special class, it is named Cmenuwndhook. Add two static members first:
static CMap m_WndMenuMap;
static HHOOK m_hMenuHook;
These guys we caught are definitely more than one, we need a mapping template class to hold pointers to their handles and corresponding Cmenuwndhook class objects. M_hmenuhook is the hook handle for the hook we are going to create. and initialize them in the CPP file:
CMap CMenuWndHook::m_WndMenuMap;
HHOOK CMenuWndHook::m_hMenuHook = NULL;
Here are two more functions for installing and uninstalling hooks, all of which are static functions: void CMenuWndHook::InstallHook()
{
if (m_hMenuHook == NULL)
{
m_hMenuHook = ::SetWindowsHookEx(WH_CALLWNDPROC,
WindowHook,
AfxGetApp()->m_hInstance,
::GetCurrentThreadId());
}
}
Windows is typically installed with the SetWindowsHookEx API function above to install hooks, and its function prototype is as follows: