首    页 界面/窗口 网络/通讯 数据库 组件开发 图像/多媒体 NET/Web 其它技术 源码下载 资料下载 软件共享 软件外包 曲艺杂谈
栏目导航:  首    页  |  界面/窗口  |  组合框   


用列表项控制工具栏上的按纽


原作者:chinawei0710    源出处:CSDN    发布者:施昌权    发布类型:转载    发布日期:2008-10-15

              

前面介绍 了在工具栏上创建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);
  }
}


关于我们 版权声明 广告服务 联系我们 友情链接 加入收藏
站长:施昌权    Email:scq2099yt@163.com    MSN:scq2099yt@live.cn    QQ:14046300    本站QQ群:67202409
Copyright © 2008     卓为VC(www.joyvc.cn)    All Rights Reserved    建议分辨率 1024×768
本站由施昌权制作维护
京ICP备09012297号