CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    15

    How do I use a "dynamic" tool tip in a CView?

    I have a standard doc-view app, and i want to display a tool tip whenever the mouse moves on the view. the tip is going to display the coordinates of the mouse. what is the best way to do this?


  2. #2
    Join Date
    May 1999
    Posts
    36

    Re: How do I use a "dynamic" tool tip in a CView?

    Hi,

    There is an excellent article in the back issues of Microsoft System Journal (MSJ). I think it's either in MSJ April 97 or 98. There is a picture on the cover. You can download the source from microsoft. Works well.

    HTH,

    Harvey

    Harvey Hawes

    Software Engineer
    BioScience Analysis Software Ltd.

    Masters Candidate
    Cardiovascular/Respiratory Sciences
    Faculty of Medicine
    University of Calgary
    Calgary, Alberta, Canada

  3. #3
    Join Date
    Apr 1999
    Location
    WA, USA
    Posts
    15

    Re: How do I use a "dynamic" tool tip in a CView?

    In the view class declare following variables (i declared it as public, you can decide on that):

    class CMyView : public CView
    {
    .....
    ....
    public:
    CRect toolRect;
    CToolTipCtrl m_ToolTip;
    CPoint oldPt;
    ....
    ...
    };

    void CMyView::OnInitialUpdate()
    {

    .....
    ....
    ....

    //initialize oldPt to (0,0)
    oldPt.x = 0;
    oldPt.y = 0;

    //create the tooltipctrl
    m_ToolTip.Create(this,TTS_ALWAYSTIP);
    this->GetWindowRect(&toolRect);
    ScreenToClient(&toolRect);
    }


    BOOL CMyView::PreTranslateMessage(MSG* pMsg)
    {
    POINT pTemp = pMsg->pt;
    CString cstrToolTip;
    switch (pMsg->message)
    {
    case WM_MOUSEMOVE:
    if((oldPt.x != pMsg->pt.x) ||(oldPt.y != pMsg->pt.y))
    {
    m_ToolTip.DelTool(this, IDD_VIEW_ID);

    cstrToolTip.Format("[%d ,%d]",pTemp.x, pTemp.y);




    //id of the form view in resource is needed for addtool call below.

    m_ToolTip.AddTool(this, (LPCTSTR)cstrToolTip, &toolRect, IDD_VIEW_ID);
    m_ToolTip.Activate(TRUE);
    m_ToolTip.SetDelayTime(1000);
    m_ToolTip.RelayEvent(pMsg);

    oldPt.x = pMsg->pt.x;
    oldPt.y = pMsg->pt.y;
    }
    default:
    break;
    }
    return

    //depends on the view you derive from, call its pretranslatemessage....
    CFormView::PreTranslateMessage(pMsg);

    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured