Problem: Under normal circumstances we use Update_Command_UI to modify the status of the menu (Enable / Disable, CHECK / Uncheck, Change Text), but this method is in a dialog-based menu, but there is no effect. Void ctestdlg :: onupdatefileExit (ccmdui * pcmdui) {pcmdui-> enable (false); pcmdui-> setcheck (true); pcmdui-> setRadio (TRUE); pcmdui-> settext ("close"); // More method MDI and SDI programs can work, but there is no effect in the dialog box, and this function is not called. } Cause Analysis: When a drop-down menu is displayed, the WM_INITMENUPOPUP message will be sent before the menu is displayed. The cframeWnd :: OnInitMenup function refreshes this menu item, and if there is an Update_command_UI response function, call it. By updating the appearance of the reaction (Enabled / Disabled, Checked / Unchecked). In a dialog-based program, because there is no oninitMenupupUp function, the Update_Command_UI response function is not called, but use the CWND class. Default processing, this processing does not call the UPDATE_COMMAND_UI response function.
The solution is as follows: Step 1: In the .cpp file in the dialog box, add an on_WM_INITMENUPOPUP entry to message mapping Begin_MESSAGE_MAP (CTESTDLG, CDIALOG) //}} AFX_MSG_Mapon_WM_INITMENUPOPUP () end_MESSAGE_MAP () Step 2: In dialog box .h file Add message function declaration. // Generated message map functions // {{AFX_MSG (CDisableDlgMenuDlg) afx_msg void OnInitMenuPopup (CMenu * pPopupMenu, UINT nIndex, BOOL bSysMenu); //}} AFX_MSGDECLARE_MESSAGE_MAP () Step 3: Add the following dialog class file .cpp Function code (most code from winfrm.cpp file "CFRAMEWND :: OnInitMenupup): void c ****** DLG :: OnIitMenupopup (cmenu * PpopupUpU, uint nindex, bool bsysmenu) {assert (ppopupmenu! = Null ); // check the enabled state of various menu items.
CCMDUI State; state.m_pmenu = ppopupmenu; assert (state.m_pother == null); assert (state.m_pparentMenu == null);
// Determine if menu is popup in top-level menu and set m_pOther to // it if so (m_pParentMenu == NULL indicates that it is secondary popup) HMENU hParentMenu;. If (AfxGetThreadState () -> m_hTrackingMenu == pPopupMenu-> m_hmenu) state.m_pparentMenu = ppopupmenu; ??? // parent == Child for Tracking Popup. Else IF ((hparentMenu = :: getMenu (m_hwnd))! = null) {cwnd * pparent = this; // child windows Don 'T Have Menus - Need to Go To The Top! IF (PParent! = NULL && (HParentMenu = :: getMenu (pParent-> m_hwnd))! = null) {int NINDEXMAX = :: getMenuItemcount (HParentMenu); for int nIndex = 0; nIndex
Assert (state.m_pother == null); assert (state.m_pmenu! = Null); if (state.m_nid == (uint) -1) {// POSSIBLY A Popup Menu, Route to First Item of That Popup. State .m_psubmenu = ppopupMenu-> getSubmenu (state.m_nindex); if (state.m_psubmenu == Null || (state.m_nid = state.m_psubmenu-> getMenuitemid (0)) == 0 || State.m_nid == (uint ) -1) {Continue; // first item of popup can't be routed to.} State.doupdate (this, true); ?? // popups are never auto disabled.} Else {// Normal Menu Item. / / Auto enable / disable if frame window has m_bAutoMenuEnable // set and command is _not_ a system command state.m_pSubMenu = NULL;. state.DoUpdate (this, FALSE);.} // Adjust for menu deletions and additions UINT nCount = pPopupMenu -> getMenuItemCount (); if (ncount
More detailed information can be referred to http://support.microsoft.com/default.aspx?scid=kb;n-us;242577