Dialog-based MFC applications do NOT automatically update menu UI state (checkmarks, radio items, enable/disable) the way frame windows do. CFrameWnd has a full command routing loop that calls CCmdUI::DoUpdate() for each menu item, but CDialog does not. Because ColorCop is a dialog-based app with a menu, we must manually iterate the menu items and invoke DoUpdate() so that ON_UPDATE_COMMAND_UI ha
| 2315 | // Without this loop, menu items will NOT reflect the current application |
| 2316 | // state when the user opens a menu. |
| 2317 | void CColorCopDlg::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu) { |
| 2318 | // Preserve default MFC behavior (system menu handling, owner-draw, etc.) |
| 2319 | CDialog::OnInitMenuPopup(pMenu, nIndex, bSysMenu); |
| 2320 | |
| 2321 | // Manually trigger UI updates for each menu item. |
| 2322 | // This restores the behavior normally provided by CFrameWnd. |
| 2323 | CCmdUI cmdUI; |
| 2324 | cmdUI.m_pMenu = pMenu; |
| 2325 | cmdUI.m_nIndexMax = pMenu->GetMenuItemCount(); |
| 2326 | |
| 2327 | for (UINT i = 0; i < cmdUI.m_nIndexMax; ++i) { |
| 2328 | cmdUI.m_nIndex = i; |
| 2329 | cmdUI.m_nID = pMenu->GetMenuItemID(i); |
| 2330 | cmdUI.DoUpdate(this, FALSE); |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | void CColorCopDlg::OnUpdateOptionsAutocopytoclipboard(CCmdUI* pCmdUI) { |
| 2335 | pCmdUI->SetCheck(m_Appflags & AutoCopytoClip); |
nothing calls this directly
no outgoing calls
no test coverage detected