实现以下功能:我点视图中的任何一个位置,就会显示一个windows的提示框,怎么实现?

解决方案 »

  1.   

    响应WM_LBUTTONDOWN消息。void CMfcsdocView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default

    MessageBox("Mouse down!") ;
    CView::OnLButtonDown(nFlags, point);
    }
      

  2.   

    如果点击实现,相应鼠标消息。如WM_LBUTTONDOWN消息。
    如果停留一定时间显示提示框,用Tip类,网上很多。
      

  3.   

    在类的头文件类声明中加入
    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)
    {
    }
      

  4.   

    / MyToolTipCtrl.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // 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);
    }
      

  5.   

    在你的视图中添加如下代码:
    #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需要自己先定义
      

  6.   

    对,用CToolTipCtrl控件可方便实现,你看一下MSDN即可明白!
      

  7.   

    IDT_RECTTANGLE2这个属于什么控件啊?我希望鼠标停留在客户区,。就会出现一个tip来显示改坐标值!能不能在说明白一点,很不好意思的说,msdn我不知道怎么用啊?