1.创建ToolBar和StatusBar
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CreateSimpleToolBar();
CreateSimpleStatusBar();
return 0;
}
2.更新ToolBar && StautsBar
(1)定义控件更新时机
BEGIN_UPDATE_UI_MAP(CMainFrame)
UPDATE_ELEMENT(ID_VIEW_TOOLBAR, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
UPDATE_ELEMENT(ID_VIEW_STATUS_BAR, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
UPDATE_ELEMENT(IDC_START_STOP, UPDUI_MENUBAR)
END_UPDATE_UI_MAP()
(2)将控件句柄传给CUpdateUI,CUpdateUI提供了一些更改句柄状态的函数
UIAddToolBar(m_hWndToolBar);
UIAddMenuBar(m_hWnd);
(3)更改控件数据结构状态
UISetCheck(ID_VIEW_TOOLBAR, 1);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
(4)发送消息更新控件UI
BOOL CMainFrame::OnIdle()
{
UIUpdateToolBar();
UIUpdateMenuBar(FALSE, TRUE);
return FALSE;
}
(5)更新UI布局
比如隐藏和显示ToolBar时,就需要更新布局
LRESULT CMainFrame::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL bVisible = !::IsWindowVisible(m_hWndToolBar);
::ShowWindow(m_hWndToolBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
UISetCheck(ID_VIEW_TOOLBAR, bVisible);
UpdateLayout();
return 0;
}
(6)更新Menu文本
void CMainFrame::OnStartStopClock ( UINT uCode, int nID, HWND hwncCtrl )
{
if ( m_view.IsClockRunning() )
{
m_view.StopClock();
UISetText ( IDC_START_STOP, _T("&Start") );
}
else
{
m_view.StartClock();
UISetText ( IDC_START_STOP, _T("&Stop") );
}
}