重绘控件提示的使用
今天,找到了一种重绘控件提示的类CMFECToolTip,该类是由MFECToolTip.h头文件和MFECToolTip.cpp组成。详细代码如下:http://download.youkuaiyun.com/detail/ilikehigame/8858301点击打开链接
其接口:
void CreateTab(CWnd* pWnd);<span style="white-space:pre"> </span>//创建该类的对象。
BOOL AddControlInfo( UINT, CStringArray&, COLORREF back=IVORY, COLORREFtext=BLACK );//将控件添加到该提示控件对象中
void ShowToolTip( UINT nControlID );
void ShowToolTip( CPoint& ); <span style="white-space:pre"> </span> //两种显示的方法,一种是靠控件ID来实现,一种是靠鼠标地址来实现
void ErasePreviousToolTipDisplay( UINT );<span style="white-space:pre"> </span>//显示前一种的提示
其使用方法:
1. 加头文件
#include "MFECToolTip.h"
2. 在Dlgl类中添加对象声明
CMFECToolTip m_toolTip;
3. 获取提示字符串,加入控件元素
<span style="white-space:pre"> </span>m_toolTip.CreateTab( this);
<span style="white-space:pre"> </span>CStringArray straInfo;
<span style="white-space:pre"> </span>straInfo.RemoveAll();
<span style="white-space:pre"> </span>straInfo.Add( "Test");
<span style="white-space:pre"> </span>straInfo.Add("helloworld");
<span style="white-space:pre"> </span>straInfo.Add("goodman yuan");
<span style="white-space:pre"> </span> m_toolTip.AddControlInfo( IDC_BTN_TEST,straInfo, RGB(255,0,0), RGB(255,255,255) );
4. 添加虚函数PreTranslateMessage,截取消息。
BOOL CTapDemoDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_MOUSEMOVE )
{
POINT pt = pMsg->pt;
ScreenToClient( &pt );
m_toolTip.ShowToolTip( (CPoint)pt );
}
return CDialogEx::PreTranslateMessage(pMsg);
}
5. 移除控件提示消息
m_toolTip.RemoveControlInfo( IDC_BTN_TEST );
在此代码中,认识了两个类: CObArray 类和 CStringArray类,以下是详细介绍。