vc使用CToolTipCtrl类实现提示信息效果

来源:互联网 发布:关爱老人的网络用语 编辑:程序博客网 时间:2024/05/10 06:21

使用CToolTipCtrl类实现提示信息效果

http://blog.hehehehehe.cn/a/6438.htm在某些应用程序中,当鼠标置于某些控件(或子窗口)上时,会弹出一个如图15.11所示的信息框,向使用者提示相关信息,使用MFC中的CToolTipCtrl类可以产生上述效果。下面介绍使用CToolTipCtrl的一般过程
(1)创建基于对话框的MFC应用程序。
(2)在主对话框中放入一个Edit控件和一个Button控件,如图15.12所示。
[喝小酒的网摘]http://blog.hehehehehe.cn/a/6438.htm
图15.11 提示信息效果
这里写图片描述

图15.12 对话框布局
这里写图片描述
(3)使用向导为步骤(2)中创建的控件添加控件类型变量,代码如下:
CEdit m_editBox;
CButton m_btnBtn;

(4)在主对话框类中添加CToolTipCtrl类对象,并重载PreTranslateMessage函数,代码如下(有省略):
class CMFCDlg : public CDialog
{
// Construction
public:
CMFCDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CMFCDlg)
enum { IDD = IDD_MFC_DIALOG }; CEdit m_editBox;
CButton m_btnBtn; //}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMFCDlg)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);// 省略部分代码
protected:
CToolTipCtrl m_tooltip;
};
(5)修改主对话框类的OnInitDialog成员函数,实现提示信息效果,代码如下:
BOOL CMFCDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // 省略相关代码 //设置父窗口指针
m_tooltip.Create(this);
//设置延时显示提示信息的时间
m_tooltip.SetDelayTime(200);
//设置提示消息的背景颜色为紫红色
m_tooltip.SetTipBkColor(RGB(255,0,255));

//设置控件提示信息
m_tooltip.AddTool(&m_btnBtn,_T(“这是一个按钮”));
m_tooltip.AddTool(&m_editBox,_T(“这是一个编辑框”));

return TRUE; // return TRUE unless you set the focus to a control
}
(6)按Ctrl+F5键编译并运行程序,效果如图15.13所示。
这里写图片描述
图15.13 CToolTipCtrl产生提示信息效果[喝小酒的网摘]http://blog.hehehehehe.cn/a/6438.htm

0 0
原创粉丝点击