MFC对话框中添加状态栏的方法
本文实例讲述了MFC对话框中添加状态栏的方法。分享给大家供大家参考。具体如下:
1.在对话框的dlg实现类里添加成员变量:
CXTPStatusBarm_wndStatusBar; //状态栏(或者是CStatusBar) //在OnInitDialog方法中初始化: staticUINTindicators[]= { ID_SEPARATOR,//statuslineindicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; //添加状态栏 if(!m_wndStatusBar.Create(this)|| !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failedtocreatestatusbar\n"); return-1;//failtocreate }
2.添加OnKickIdle事件(在对话框的dlg的头文件加上):
afx_msgLRESULTOnKickIdle(WPARAM,LPARAM); afx_msgvoidOnUpdateKeyIndicator(CCmdUI*pCmdUI); DECLARE_MESSAGE_MAP()
3.在实现类中添加对应的两个方法:
LRESULTCDialogPanesDlg::OnKickIdle(WPARAM,LPARAM) { m_wndStatusBar.SendMessage(WM_IDLEUPDATECMDUI,TRUE); return0; } voidCDialogPanesDlg::OnUpdateKeyIndicator(CCmdUI*pCmdUI) { UINTnVK; UINTflag=0×0001; switch(pCmdUI->m_nID) { caseID_INDICATOR_CAPS: nVK=VK_CAPITAL; break; caseID_INDICATOR_NUM: nVK=VK_NUMLOCK; break; caseID_INDICATOR_SCRL: nVK=VK_SCROLL; break; default: TRACE1("Warning:OnUpdateKeyIndicator–unknownindicator0x%04X.\n", pCmdUI->m_nID); pCmdUI->ContinueRouting(); return;//notforus } pCmdUI->Enable(::GetKeyState(nVK)&flag); //enablestatictextbasedontoggledkeystate ASSERT(pCmdUI->m_bEnableChanged); }
4.运行发现看不见状态栏,添加对话框的WM_SIZE事件:
voidCDialogPanesDlg::OnSize(UINTnType,intcx,intcy) { CDialog::OnSize(nType,cx,cy); //TODO:Addyourmessagehandlercodehere CRectrcClient(0,0,cx,cy); RepositionBars(0,0xffff,AFX_IDW_PANE_FIRST,0,0,&rcClient); RepositionBars(0,0xffff,AFX_IDW_PANE_FIRST,reposQuery,&rcClient,&rcClient); }
希望本文所述对大家的MFC程序设计有所帮助。