视图中根据不同位置,响应提示窗口(Tooltip)
2009-11-08 18:53
357 查看
在MFC工程中,添加如下代码即可。
然后在你的视图(CYourView)中,添加如下代码
cpp的OnDraw()函数中添加如下代码:
其中,宏IDT_RECTANGLE1和宏IDT_RECTANGLE2需要你自己定义(不与系统冲突即可)
/ MyToolTipCtrl.h : header file // ///////////////////////////////////////////////////////////////////////////// // CMyToolTipCtrl window class 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 handlers BOOL 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); }
然后在你的视图(CYourView)中,添加如下代码
#include "MyToolTipCtrl.h" // Added by ClassView public: CMyToolTipCtrl m_ctlTT;
cpp的OnDraw()函数中添加如下代码:
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需要你自己定义(不与系统冲突即可)
相关文章推荐
- 根据IE的不同,调用不同的无提示关闭窗口的方法,
- html5学习canvas基本使用:div在js前面;localStorage存储根据浏览器在不同的位置;应用程序缓存;placeholder 属性提供一种提示(hint),描述输入域所期待的值。
- Winform不同窗口的Button响应同一个点击事件
- jQuery探测位置的提示弹窗(toolTip box)详细解析
- 封装TOOLTIP, 打造不同Delphi自身提供hint的提示信息
- PCL_1.8配置VS2013步骤(根据文件所在位置不同更改文件名)
- gvim窗口根据gnome-terminal位置定位
- VC 控件根据窗口大小变化改变大小和位置。(EasySize)
- MVC扩展ActionInvoker,自定义ActionInvoker,根据请求数据返回不同视图
- ASP.NET提示框,且根据用户选择执行不同代码的实现
- UIButton按钮点击无响应(按钮的位置在父视图之外的解决方法),传递响应链
- Label:根据文字自动调整大小 并 添加tooltip提示
- PHP实现根据图片色界在不同位置加水印的方法
- jQuery探测位置的提示弹窗(toolTip box)详细解析
- 本地调试正常,发布后提示:未找到视图“xxx.cshtml”或其母版视图,或没有视图引擎支持搜索的位置。
- HandlerExceptionResolver 异常视图根据异常种类返回不同形式
- 根据登录的不同权限,登录不同的窗口!
- VC++单文档分割窗口、在视图中添加控件,并响应该控件的事件
- JS图像映射的应用,在一个图片点击或移动到不同位置有不同响应
- 根据浏览器窗口(或不同设备)宽度缩放图片