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

2025-05-29 0 73

本文实例讲述了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);

}

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

?

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程序设计有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 MFC对话框中添加状态栏的方法 https://www.kuaiidc.com/107375.html

相关文章

发表评论
暂无评论