CMenu menu; HMENU hMenu = menu.GetSafeHmenu();
CWnd* pWnd = GetDlgItem(IDC_BUTTON); CMenu* pMenu = pWnd->GetMenu(); HMENU hMenu = pMenu->GetSafeHmenu();Explanation: This code retrieves the handle to a menu associated with a button control. First, it gets a pointer to the button control with GetDlgItem(). Then, it gets a pointer to the menu with GetMenu() which is a member function of CWnd class. Finally, it retrieves the handle to the menu with GetSafeHmenu(). Package Library: Microsoft Foundation Class (MFC)