|
Support
ActiveX / COM
Visual C++ / MFC
Customer Spotlight
Corporate Partners
Contact Sales
Call center available M-F 9:00 - 6:00 US Eastern Time. U.S. and Canada International Email |
Handling ON_COMMAND and ON_UPDATE_COMMAND_UI messages
Author: Kirk Stowell
Posted: November 16, 2004
Environment: Visual C++ MFC
(Part I) using ON_UPDATE_COMMAND_UI: BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ... //}}AFX_MSG_MAP ON_UPDATE_COMMAND_UI(ID_EDIT_STATE,OnUpdateEditState) END_MESSAGE_MAP()
[...]
void CMainFrame::OnUpdateEditState(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bCheck); pCmdUI->Enable(TRUE); } You can cause a control to be updated from CCmdUI. void CMainFrame::OnUpdateEditState(CCmdUI* pCmdUI) { CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmdUI->m_pOther; if (pToolBar) { CXTPContro* pControl = pToolBar->GetControls()->GetAt(pCmdUI->m_nIndex); pControl->SetIconId(ID_FILE_NEW); } } You can also manually update the control using the xtpFlagManualUpdate flag. pButton->SetFlags(xtpFlagManualUpdate); pButton->SetChecked(TRUE); (Part II) using ON_COMMAND: BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ... //}}AFX_MSG_MAP ON_COMMAND(ID_THEME_DEFAULT, OnSwitchDefault) END_MESSAGE_MAP()
[...]
void CMainFrame::OnSwitchDefault() { CXTPPaintManager::SetTheme(xtpThemeOffice2000); GetCommandBars()->RedrawCommandBars(); } (Part III) using ON_XTP_EXECUTE: BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ... //}}AFX_MSG_MAP ON_XTP_EXECUTE(ID_EDIT_STATE, OnEditState) END_MESSAGE_MAP()
[...]
void CMainFrame::OnEditState(NMHDR* pNMHDR, LRESULT* pResult) { CXTPControl* pControl = ((NMXTPCONTROL*)pNMHDR) ->pControl; if (pControl->GetType() == xtpControlSplitButtonPopup) { … … *pResult = TRUE; } } |
