Menu background color settings, mainly used functionsSetmenuinfo
Function prototype: bool setmenultemlnfo (hmenu, uint uitem, bool fbyposition, lpmenuiteminfo lpmii); parameter: hmenu: handle containing the menu item. Ultem: identifier or location of the menu item to be modified. The meaning of this parameter is determined by the fbyposition parameter. Fbyposition: specifies the meaning value of the ultem parameter. If this parameter is set to false, ultem indicates the identifier of the menu item. Otherwise, it indicates the position of the menu item. Lpmii: pointer to the menuiteminfo structure. This structure contains menu item information and specifies the attributes of the menu item to be modified. Return Value: If the function call is successful, a non-zero value is returned. If the function call fails, the return value is zero.
Menu bitmap loading, mainly used functionsSetmenuitembitmaps.
Cmenu: setmenuitembitmapsBoolsetmenuitembitmaps
(
Uint
Nposition
,
Uint
Nflags
,
Const
Cbitmap *
Pbmpunchecked
,
Const
Cbitmap *
Pbmpchecked
);
Return Value: If the call is successful, a non-zero value is returned. Otherwise, the value is 0.
Parameters:The value of nposition is determined by the value of nflags. If the value of the second parameter is mf_byposition, that is, the position index is used, the first parameter is the position index of the menu item. If the value of the second parameter is mf_bycommand, the first parameter indicates the menu item, and the ID of the menu item should be used. The last two parameters are cbitmap class pointers used to set two bitmaps associated with the menu item. The third parameter indicates the bitmap when the menu item is not selected, the fourth parameter indicates the displayed bitmap after the menu item is selected. The main code is as follows:
1 // menu array 2 const int g_menuidarray [] = 3 {4 id_rmenu_run, 5 id_rmenu_add, 6 id_rmenu_remove, 7 id_rmenu_seekfile, 8 id_tmenu_view, 9 reviews }; 11 12 // bitmap array 13 const int g_bmp idarray [] = 14 {15 idb_bitmap_run, 16 idb_bitmap_add, 17 idb_bitmap_remove, 18 idb_bitmap_seekfile, 19 idb_bitmap_view, 20 bytes };
1 // initialize the relationship between consumer ID and bitmap 2 void ctoolboxdlg: initbmp map () 3 {4 for (INT I = 0; I <sizeof (g_menuidarray) /sizeof (g_menuidarray [0]); I ++) 5 {6 cbitmap * BMP = new cbitmap; 7 BMP-> loadbitmap (g_bmp idarray [I]); 8 m_bmp map [g_menuidarray [I] = BMP; 9} 10}
1 // set menu Background 2 void ctoolboxdlg: setmenubkcolor (cmenu * pmenu) 3 {4 If (null = pmenu) 5 {6 return; 7} 8 9 menuinfo; 10 memset (& menuinfo, 0, sizeof (menuinfo); 11 menuinfo. cbsize = sizeof (menuinfo); 12 menuinfo. hbrback = m_brush; 13 menuinfo. fmask = mim_background; 14: setmenuinfo (pmenu-> m_hmenu, & menuinfo); 15} 16 17 // load menu bitmap 18 void ctoolboxdlg: setmenubmp (cmenu * pmenu) 19 {20 for (uint I = 0; I <pmenu-> getmenuitemcount (); I ++) 21 {22 int nmenuid = pmenu-> getmenuitemid (I ); 23 24 if (0 <nmenuid) 25 {26 pmenu-> setmenuitembitmaps (nmenuid, mf_bycommand, 27 m_bmp map [nmenuid], m_bmp map [nmenuid]); 28} 29} 30}
1 // set the menu background color and bitmap 2 void ctoolboxdlg: setmenubkinfo (cmenu * pmenu) 3 {4 setmenubkcolor (pmenu); 5 setmenubmp (pmenu); 6}
1 // right-click the list box, and right-click the menu. 2 void ctoolboxdlg: onnmrclicklisttoolbox (nmhdr * pnmhdr, lresult * presult) 3 {4 lpnmitemactivate pnmitemactivate = (lpnmhdr ); 5 6 cpoint pt; 7 8 getcursorpos (& pt); 9 10 cmenu menu; 11 menu. loadmenu (idr_menu_right); 12 13 cmenu * ppopup = menu. getsubmenu (0); 14 15 setmenubkinfo (ppopup); 16 17 int nselectindex = pnmitemactivate-> iItem; 18 19 if (not_find! = Nselectindex) 20 {21 ppopup-> enablemenuitem (optional, mf_bycommand | mf_enabled); 22 ppopup-> enabled (optional, mf_bycommand | mf_enabled); 23 ppopup-> enabled (optional, mf_bycommand | mf_enabled); 24} 25 else26 {27 ppopup-> enablemenuitem (enabled, mf_bycommand | mf_disabled); 28 ppopup-> enablemenuitem (disabled, mf_bycommand | mf_disabled ); 29 ppopup-> enablemenuitem (id_rmenu_seekfile, mf_bycommand | mf_disabled); 30} 31 32 ppopup-> trackpopupmenu (tpm_leftalign, PT. x, PT. y, this); 33 34 * presult = 0; 35}
Tool Management-menu bitmap Loading