1. Create and display menus
SHMENUBARINFO mbi; <br/> ZeroMemory (& mbi, sizeof (SHMENUBARINFO); <br/> mbi. cbSize = sizeof (SHMENUBARINFO); <br/> mbi. hwndParent = m_hWnd; <br/> mbi. hInstRes =: AfxGetInstanceHandle (); <br/> mbi. dwFlags = SHCMBF_HMENU | SHCMBF_HIDESIPBUTTON; // hide the SIP <br/> mbi. nToolBarId = IDR_MYMENU; <br/> SHCreateMenuBar (& mbi );
2. Hide the menu
HWND hwnd =: SHFindMenuBar (m_hWnd); <br/> if (hwnd! = NULL) <br/>: ShowWindow (hwnd, SW_HIDE );
3. Hide a sub-menu item
TBBUTTONINFO tbbi = {0}; <br/> tbbi. cbSize = sizeof (TBBUTTONINFO); <br/> tbbi. dwMask = TBIF_LPARAM | TBIF_BYINDEX; <br/>: SendMessageW (mbi. hwndMB, TB_GETBUTTONINFO, 0, (LPARAM) & tbbi); // 0 is SK1, 1 is SK2 (that is, left and right soft keys) <br/> g_hMenu = (HMENU) tbbi. lParam; // g_hMenu is the global variable, so that the sub-menu can be hidden anywhere. <br/>
4. Make a SK (Soft Key) unavailable
: SHEnableSoftkey (mbi. hwndMB, 0, TRUE, FALSE );
5. Check the sub-menu
HMENU hMenu; <br/> HWND hwndMenuBar =: SHFindMenuBar (m_hWnd); // m_hWnd is the window handle <br/> tbbi. cbSize = sizeof (tbbi); <br/> tbbi. dwMask = TBIF_LPARAM | TBIF_BYINDEX; <br/> // The third parameter 1 indicates the right menu, and 0 indicates the left menu <br/>: SendMessage (hwndMenuBar, TB_GETBUTTONINFO, 1, (LPARAM) & tbbi); <br/> hMenu = (HMENU) tbbi. lParam; // The hMenu handle is a commonly used handle for menu operations. It is very useful to obtain this handle. <Br/> DWORD ack = CheckMenuItem (hMenu, ID_STARTUP, MF_BYCOMMAND | MF_CHECKED );