为对话框中的控件提供提示信息

  [问题提出]
  当用户不知道你的按钮的具体功能时,工具条提示是一个不错的方法.
  [解决方法]
  提示功能是由MFC类库中的CToolTipCtrl来实现的.
  [实现程序]
  假设你有了名为My的对话框的工程.首先建立一个Button,方法:在ResourceView中双击Dialog,添加Button采用默认值:IDC_BUTTON1.实现PreTranslateMessage消息的相应函数.
  class CMyDlg : public CDialog
  {
  public:
  CToolTipCtrl m_ToolTips;
  ...............
  };

  BOOL CMyDlg::OnInitDialog()
  {
  CDialog::OnInitDialog();

  // TODO: Add extra initialization here

  CButton *pButton;
  pButton=(CButton *)GetDlgItem(IDC_BUTTON1);
    m_ToolTips.Create(this);
  m_ToolTips.AddTool(pButton,"This is a ToolTips text for this Button");
  return TRUE;  // return TRUE  unless you set the focus to a control
  }

  BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) 
  {
  // TODO: Add your specialized code here and/or call the base class
  switch(pMsg->message)
  {
  case WM_LBUTTONDOWN:
  case WM_LBUTTONUP:
  case WM_MOUSEMOVE:
      m_ToolTips.RelayEvent(pMsg);
  }
  return CDialog::PreTranslateMessage(pMsg);
  }
  好了,运行看看. 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值