在你的视图中添加如下代码: #include "MyToolTipCtrl.h" // Added by ClassView public: CMyToolTipCtrl m_ctlTT; cpp中: m_ctlTT.Create (this); m_ctlTT.AddRectTool (this,_T("This is a rectangle1"),CRect(32,32,64,64),IDT_RECTANGLE1); m_ctlTT.AddRectTool (this,_T("This is a rectangle2"),CRect(100,100,164,164),IDT_RECTANGLE2);//IDT_RECTANGLE1 IDT_RECTANGLE2需要自己先定义
{
// TODO: Add your message handler code here and/or call default
MessageBox("Mouse down!") ;
CView::OnLButtonDown(nFlags, point);
}
如果停留一定时间显示提示框,用Tip类,网上很多。
afx_msg BOOL OnNeedToolTipText(UINT id, NMHDR *pTTTStruct, LRESULT *pResult);
将下面代码加入BEGIN_MESSAGE_MAP与END_MESSAGE_MAP之间的类消息表定义中
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnNeedToolTipText)YOURCLASS::OnNeedToolTipText(UINT id, NMHDR *pNMHdr, LRESULT *pResult)
{
}
///////////////////////////////////////////////////////////////////////////////
// CMyToolTipCtrl windowclass CMyToolTipCtrl : public CToolTipCtrl
{
// Construction
public:
CMyToolTipCtrl();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyToolTipCtrl)
//}}AFX_VIRTUAL// Implementation
public:
BOOL AddRectTool (CWnd* pWnd, LPCTSTR pszText, LPCRECT pRect, UINT nIDTool);
BOOL AddWindowTool (CWnd* pWnd, LPCTSTR pszText);
virtual ~CMyToolTipCtrl(); // Generated message map functions
protected:
//{{AFX_MSG(CMyToolTipCtrl)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};
// MyToolTipCtrl.cpp : implementation file
//#include "stdafx.h"
#include "GridDemo.h"
#include "MyToolTipCtrl.h"
CMyToolTipCtrl::CMyToolTipCtrl()
{
}CMyToolTipCtrl::~CMyToolTipCtrl()
{
}
BEGIN_MESSAGE_MAP(CMyToolTipCtrl, CToolTipCtrl)
//{{AFX_MSG_MAP(CMyToolTipCtrl)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyToolTipCtrl message handlersBOOL CMyToolTipCtrl::AddWindowTool(CWnd *pWnd, LPCTSTR pszText)
{
TOOLINFO ti;
ti.cbSize = sizeof (TOOLINFO);
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
ti.hwnd = pWnd->GetParent ()->GetSafeHwnd ();
ti.uId = (UINT) pWnd->GetSafeHwnd ();
ti.hinst = AfxGetInstanceHandle ();
ti.lpszText = (LPTSTR) pszText; return (BOOL) SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti);
}BOOL CMyToolTipCtrl::AddRectTool(CWnd *pWnd, LPCTSTR pszText, LPCRECT pRect, UINT nIDTool)
{
TOOLINFO ti;
ti.cbSize = sizeof (TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = pWnd->GetSafeHwnd ();
ti.uId = nIDTool;
ti.hinst = AfxGetInstanceHandle ();
ti.lpszText = (LPTSTR) pszText;
::CopyRect (&ti.rect, pRect); return (BOOL) SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti);
}
#include "MyToolTipCtrl.h" // Added by ClassView
public:
CMyToolTipCtrl m_ctlTT;
cpp中:
m_ctlTT.Create (this);
m_ctlTT.AddRectTool (this,_T("This is a rectangle1"),CRect(32,32,64,64),IDT_RECTANGLE1); m_ctlTT.AddRectTool (this,_T("This is a rectangle2"),CRect(100,100,164,164),IDT_RECTANGLE2);//IDT_RECTANGLE1 IDT_RECTANGLE2需要自己先定义