工具栏上创建ComboBox组合框控件,框架响应消息(一)之后续:用列表项控制工具栏上的按纽

前面介绍 了在工具栏上创建ComboBox组合框控件,及程序主框架来响应消息.

因为在实际中业务需要时,工具栏上的某些按纽需要显示或灰化,比如操作时间控件时,很多时候在它前面或

旁边加个Button 吧.我们就拿这个问题来解释?

    程序框架还是依照前面的代码,在工具栏上增加2个按纽. 然后在框架中利用向导加ON_UPDATE_COMMAND_UI(...)函数,利用pCmdUI->Enable()函数即可.

   在此程序的ComboBox中,用下拉项来控制工具条按纽,只需在框架.h中声明一个变量 int m_nMode;

即可.

下面是实现代码:


// CMainFrame message handlers

void CMainFrame::OnSelchangeCombo()
{
 int nSel;
 nSel = m_wndToolBar.m_comboBox.GetCurSel();
 CString ss;

switch(nSel)
 {
 case 0:
  m_nMode = 1;
  ss.Format("m_nMode=%d",m_nMode);
  AfxMessageBox(ss);

  break;
 case 1:
  m_nMode = 2;
  ss.Format("m_nMode=%d",m_nMode);
  AfxMessageBox(ss);

  break;

 case 2:
  m_nMode = 3;
  ss.Format("m_nMode=%d",m_nMode);
  AfxMessageBox(ss);

  break;
 case 3:
  m_nMode = 4;
  ss.Format("m_nMode=%d",m_nMode);
  AfxMessageBox(ss);

  break;
 default:
  break;
 }
 
}

void CMainFrame::OnUpdateButton1(CCmdUI* pCmdUI)
{
 // TODO: Add your command update UI handler code here
 if ((m_nMode == 1) ||(m_nMode == 3) )
 {
  pCmdUI->Enable(FALSE);
 }
 else
 {
  pCmdUI->Enable(TRUE);
 }
}

void CMainFrame::OnUpdateButton2(CCmdUI* pCmdUI)
{
 // TODO: Add your command update UI handler code here
 if ((m_nMode == 2) ||(m_nMode == 4) )
 {
  pCmdUI->Enable(FALSE);
 }
 else
 {
  pCmdUI->Enable(TRUE);
 }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值