MFC對話框中添加狀況欄的辦法。本站提示廣大學習愛好者:(MFC對話框中添加狀況欄的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是MFC對話框中添加狀況欄的辦法正文
本文實例講述了MFC對話框中添加狀況欄的辦法。分享給年夜家供年夜家參考。詳細以下:
1.在對話框的dlg完成類裡添加成員變量:
CXTPStatusBar m_wndStatusBar; //狀況欄(或許是CStatusBar) //在OnInitDialog辦法中初始化: static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; //添加狀況欄 if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create }
2.添加OnKickIdle事宜(在對話框的dlg的頭文件加上) :
afx_msg LRESULT OnKickIdle(WPARAM, LPARAM); afx_msg void OnUpdateKeyIndicator(CCmdUI* pCmdUI); DECLARE_MESSAGE_MAP()
3.在完成類中添加對應的兩個辦法:
LRESULT CDialogPanesDlg::OnKickIdle(WPARAM, LPARAM) { m_wndStatusBar.SendMessage(WM_IDLEUPDATECMDUI, TRUE); return 0; } void CDialogPanesDlg::OnUpdateKeyIndicator(CCmdUI* pCmdUI) { UINT nVK; UINT flag = 0×0001; switch (pCmdUI->m_nID) { case ID_INDICATOR_CAPS: nVK = VK_CAPITAL; break; case ID_INDICATOR_NUM: nVK = VK_NUMLOCK; break; case ID_INDICATOR_SCRL: nVK = VK_SCROLL; break; default: TRACE1("Warning: OnUpdateKeyIndicator – unknown indicator 0x%04X.\n", pCmdUI->m_nID); pCmdUI->ContinueRouting(); return; // not for us } pCmdUI->Enable(::GetKeyState(nVK) & flag); // enable static text based on toggled key state ASSERT(pCmdUI->m_bEnableChanged); }
4.運轉發明看不見狀況欄,添加對話框的WM_SIZE事宜:
void CDialogPanesDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here CRect rcClient(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法式設計有所贊助。