本文实例讲述了MFC对话框中添加状态栏的方法。分享给大家供大家参考。具体如下:
1.在对话框的dlg实现类里添加成员变量:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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的头文件加上) :
?
1
2
3
|
afx_msg LRESULT OnKickIdle( WPARAM , LPARAM );
afx_msg void OnUpdateKeyIndicator(CCmdUI* pCmdUI);
DECLARE_MESSAGE_MAP()
|
3.在实现类中添加对应的两个方法:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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);
}
|
?
1
2
3
4
5
6
7
8
|
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程序设计有所帮助。
相关文章
猜你喜欢
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 75
-
2025-06-05 90
-
2025-05-25 40
-
2025-05-25 66
-
2025-05-24 60
热门评论