您的位置:首页 > 其它

VC ToolTip提示工具的实现

2010-05-28 17:37 246 查看
1、tooltip是很不错的提示信息,很多程序都需要用到这个信息提示。

2、用VC建立一个Dialog得工程,在Dialog上面拖放一个Button按钮,ID为IDC_BUTTON1。

CToolTipCtrl m_tooltip;

virtual BOOL PreTranslateMessage(MSG* pMsg);


 

BOOL CToolTipDlg::PreTranslateMessage(MSG* pMsg)
{
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}


 

在CToolTipDlg::OnInitDialog()函数写入如下代码:

m_tooltip.Create(this);
m_tooltip.Activate(TRUE);

m_tooltip.AddTool(GetDlgItem(IDC_BUTTON1), ">text<");
m_tooltip.AddTool(GetDlgItem(IDC_STA), ">text123<  /r/n adfdfsdfs");

m_tooltip.SetDelayTime(200);//设置延迟时间
m_tooltip.SetTipBkColor(COLORREF(RGB(100,0,0)));//设置提示背景色
m_tooltip.SetTipTextColor(RGB(0,0,255));//设置提示文本颜色
m_tooltip.SetMaxTipWidth(100);//设置提示的最大宽度(使用多行需要设置此项)


 

IDC_STA,是静态的文本控件,则需要设置 静态文本Notify属性为TRUE

 

class CToolTipCtrl : public CWnd
{
DECLARE_DYNAMIC(CToolTipCtrl)

// Constructors
public:
CToolTipCtrl();
BOOL Create(CWnd* pParentWnd, DWORD dwStyle = 0);

// Attributes
void GetText(CString& str, CWnd* pWnd, UINT nIDTool = 0) const;
BOOL GetToolInfo(CToolInfo& ToolInfo, CWnd* pWnd, UINT nIDTool = 0) const;
void SetToolInfo(LPTOOLINFO lpToolInfo);
void SetToolRect(CWnd* pWnd, UINT nIDTool, LPCRECT lpRect);
int GetToolCount() const;
int GetDelayTime(DWORD dwDuration) const;
void SetDelayTime(DWORD dwDuration, int iTime);
void GetMargin(LPRECT lprc) const;
void SetMargin(LPRECT lprc);
int GetMaxTipWidth() const;
int SetMaxTipWidth(int iWidth);
COLORREF GetTipBkColor() const;
void SetTipBkColor(COLORREF clr);
COLORREF GetTipTextColor() const;
void SetTipTextColor(COLORREF clr);

// Operations
void Activate(BOOL bActivate);

BOOL AddTool(CWnd* pWnd, UINT nIDText, LPCRECT lpRectTool = NULL,
UINT nIDTool = 0);
BOOL AddTool(CWnd* pWnd, LPCTSTR lpszText = LPSTR_TEXTCALLBACK,
LPCRECT lpRectTool = NULL, UINT nIDTool = 0);

void DelTool(CWnd* pWnd, UINT nIDTool = 0);

BOOL HitTest(CWnd* pWnd, CPoint pt, LPTOOLINFO lpToolInfo) const;
void RelayEvent(LPMSG lpMsg);
void SetDelayTime(UINT nDelay);
void UpdateTipText(LPCTSTR lpszText, CWnd* pWnd, UINT nIDTool = 0);
void UpdateTipText(UINT nIDText, CWnd* pWnd, UINT nIDTool = 0);
void Update();

void Pop();

// Implementation
public:
void FillInToolInfo(TOOLINFO& ti, CWnd* pWnd, UINT nIDTool) const;
virtual ~CToolTipCtrl();
#ifndef _AFXDLL
virtual BOOL DestroyToolTipCtrl();
#else
BOOL DestroyToolTipCtrl();
#endif

protected:
//{{AFX_MSG(CToolTipCtrl)
afx_msg LRESULT OnDisableModal(WPARAM, LPARAM);
afx_msg LRESULT OnWindowFromPoint(WPARAM, LPARAM);
afx_msg LRESULT OnAddTool(WPARAM, LPARAM);
afx_msg void OnEnable(BOOL bEnable);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

CMapStringToPtr m_mapString;

friend class CWnd;
friend class CToolBar;
};


 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  工具 button dialog class null