Toolbar makes a menu process detailed

zhaozj2021-02-16  49

Toolbar makes a menu process detailed

Now many user interfaces use toolbars to make a menu bar. The younger brother is recently interested in this, but it is helpful from the Internet, but most of the help is the source code of BCGControlbar or Sizablerebar's source code, for only hope to have its own interface. For a friend, this may be a good choice, just look at Demo, then call someone else's class library, but I am interested in this topic, I hope to understand the readers of the dragon, I will directly It is not easy to get out of the source code that is not explained in detail. It is not easy. At least for the rookie like me, this article is for this reason, I hope to seek this Help readers can provide some help. Below we look at:

When receiving the ToolbarButton Press the message, we generally use the TRACKPOPUPMENUEX pop-up menu. The key to the problem is that TRACKPOPUPMENUEX does not return and intercepts the mouse and keyboard messages. Use SPY to see, the toolbar at this time No news is not received, of course, there is no change from the hotspot, which requires us to detect the mouse position and close the previous menu when the mouse moves to the next hotspot and displays the next menu. Here we use the hook function SetWindowsHookEx mounted WH_MSGFILTER hook before the call TrackPupupMenuEx, code is as follows: m_hMsgHook = SetWindowsHookEx (WH_MSGFILTER, MessageProc, 0, GetCurrentThreadId ()); MssageProc a hook function, as follows: LRESULT CALLBACK MessageProc (int code, WPARAM wParam, LParam lParam) {if (code == msgf_menu) {hookMessageProc (lparam);} Return CallNexthooKex (M_HMSGHOK, CODE, WPARAM, LPARAM);} Function Check message, if it is from the menu, pass the message to the function hookMessageProc process, us What you have to do is to detect the message WM_MOUSEMOVE in this function, and test the mouse position. If the mouse has been moved to another button, close the menu and display the next menu, close the menu use message WM_CANCANCELMODE, when the menu is closed, we want to release Hook, reinstall the hook when the next menu is pop-up, pop-up sample code code as follows: void trackpopup (hwnd hwndtoolbar, int ibutton) {while (ibutton> = 0) {sendMessage (hwndtoolbar, tb_sethotitem, ibutton, 0); iPopup = ibutton; // install the hook g_hMsgHook = SetWindowsHookEx (WH_MSGFILTER, MessageProc, 0, GetCurrentThreadId ()); // pop-up menu TrackPopupMenuEx (...); // unloading hook UnhookWindowsHookEx (g_hMsgHook); iButton = iNextPop; // pop next item, if it is Negative, exit} sendMessage (hwndtoolbar, tb_sethotitem, -1,0) } (Experience and Suggestions: If Button uses styles TBStyle_Dropdown, do not call the function directly in the message TBN_DropDown, use the intermediate message, then use the PostMessa to send the message so that TBN_DropDown can return directly, otherwise eliminates the first high Bright hotspots are very troublesome.

转载请注明原文地址:https://www.9cbs.com/read-23566.html

New Post(0)