首页 > 编程 > C++ > 正文

MFC对话框中添加状态栏的方法

2020-05-23 14:17:44
字体:
来源:转载
供稿:网友

这篇文章主要介绍了MFC对话框中添加状态栏的方法,实例分析了MFC对话框添加状态栏所涉及的相关成员变量与事件实现技巧,需要的朋友可以参考下

本文实例讲述了MFC对话框中添加状态栏的方法。分享给大家供大家参考。具体如下:

1.在对话框的dlg实现类里添加成员变量:

 

 
  1. CXTPStatusBar m_wndStatusBar;  
  2. //状态栏(或者是CStatusBar) 
  3. //在OnInitDialog方法中初始化: 
  4. static UINT indicators[] = 
  5. ID_SEPARATOR, // status line indicator 
  6. ID_INDICATOR_CAPS, 
  7. ID_INDICATOR_NUM, 
  8. ID_INDICATOR_SCRL, 
  9. }; 
  10. //添加状态栏 
  11. if (!m_wndStatusBar.Create(this) || 
  12. !m_wndStatusBar.SetIndicators(indicators, 
  13. sizeof(indicators)/sizeof(UINT))) 
  14. TRACE0("Failed to create status bar/n"); 
  15. return -1; // fail to create 

2.添加OnKickIdle事件(在对话框的dlg的头文件加上) :

 

 
  1. afx_msg LRESULT OnKickIdle(WPARAM, LPARAM); 
  2. afx_msg void OnUpdateKeyIndicator(CCmdUI* pCmdUI); 
  3. DECLARE_MESSAGE_MAP() 

3.在实现类中添加对应的两个方法:

 

 
  1. LRESULT CDialogPanesDlg::OnKickIdle(WPARAM, LPARAM) 
  2. m_wndStatusBar.SendMessage(WM_IDLEUPDATECMDUI, TRUE); 
  3. return 0; 
  4. void CDialogPanesDlg::OnUpdateKeyIndicator(CCmdUI* pCmdUI) 
  5. UINT nVK; 
  6. UINT flag = 0×0001; 
  7. switch (pCmdUI->m_nID) 
  8. case ID_INDICATOR_CAPS: 
  9. nVK = VK_CAPITAL; 
  10. break
  11. case ID_INDICATOR_NUM: 
  12. nVK = VK_NUMLOCK; 
  13. break
  14. case ID_INDICATOR_SCRL: 
  15. nVK = VK_SCROLL; 
  16. break
  17. default
  18. TRACE1("Warning: OnUpdateKeyIndicator – unknown indicator 0x%04X./n"
  19. pCmdUI->m_nID); 
  20. pCmdUI->ContinueRouting(); 
  21. return// not for us 
  22. pCmdUI->Enable(::GetKeyState(nVK) & flag); 
  23. // enable static text based on toggled key state 
  24. ASSERT(pCmdUI->m_bEnableChanged); 

4.运行发现看不见状态栏,添加对话框的WM_SIZE事件:

 

 
  1. void CDialogPanesDlg::OnSize(UINT nType, int cx, int cy) 
  2. CDialog::OnSize(nType, cx, cy); 
  3. // TODO: Add your message handler code here 
  4. CRect rcClient(0, 0, cx, cy); 
  5. RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, 0, 0, &rcClient); 
  6. RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rcClient, &rcClient); 

希望本文所述对大家的MFC程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表