Using hook to implement menu shadow effect

Source: Internet
Author: User
Tags function prototype

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.