c语言对话框的快捷添加按钮,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程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值