Click here to Skip to main content
Licence 
First Posted 15 Mar 2007
Views 21,010
Downloads 673
Bookmarked 21 times

Create In-Place ToolTips on yourself control

By | 22 Mar 2007 | Article
It is very easy to create In-Place ToolTips on yourself control like treeview control.

Introduction

It is very easy to create In-Place ToolTips on yourself control like treeview control.

Screenshot - tooltipsdemo.jpg

Using the code

Step 1

In the window's header file you must add a CToolTipCtrl instance and TOOLINFO member, and add message map to handle the mouse messages.

protected:
     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
     afx_msg void OnMouseLeave(WPARAM wPawam, LPARAM lParam);
     //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
     CToolTipCtrl m_toolTip;
     TOOLINFO m_ti;

Step 2

In window's implementation file add the following to the end of Createto set the tooltips.

m_toolTip.Create(this);
m_ti.cbSize = sizeof(m_ti);
m_ti.uFlags = TTF_IDISHWND|TTF_TRACK|TTF_ABSOLUTE |TTF_TRANSPARENT ;
m_ti.hwnd = m_hWnd;
m_ti.hinst = NULL;
m_ti.uId = (UINT)m_hWnd;
m_ti.lpszText = LPSTR_TEXTCALLBACK;
m_ti.rect.left = 0; 
m_ti.rect.top = 0;
m_ti.rect.right = 0;
m_ti.rect.bottom = 0;

m_toolTip.SendMessage(TTM_ADDTOOL, 0, (LPARAM)&m_ti);

At the bottom of the message map add the following:

    ON_WM_MOUSEMOVE()
    ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
END_MESSAGE_MAP()

Finally add the message handler method as entered in the message map:

void CChildView::OnMouseMove(UINT nFlags, CPoint point) 
{
     CDemoItem* pItem = GetItemAtPt(point);
     if(pItem == NULL)
     {
          m_toolTip.SendMessage(TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ti);
          return; 
     }
     RECT rect;
     GetItemRect(pItem, &rect);
     POINT pt;
      
     TRACKMOUSEEVENT tk;
     tk.cbSize = sizeof(tk);
     tk.dwFlags = TME_LEAVE;
     tk.dwHoverTime = 0;
     tk.hwndTrack = m_hWnd;
     _TrackMouseEvent(&tk);
     pt.x = rect.left - 3;
     pt.y = rect.top - 2;
     ClientToScreen(&pt);
     m_toolTip.SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
     m_toolTip.SendMessage(TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ti);
}

void CChildView::OnMouseLeave(WPARAM wPawam, LPARAM lParam)
{
     m_toolTip.SendMessage(TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ti);
}

 

Contacting the Author

Auto Debug software is an api monitor tool which can automatic tracing all apis and activex interface input and output parameters. Easy set which api want to monitor, this application will auto trace the target program and monitor the input and output of function call. Monitor any dll and activex interface, automatic analysis pdb files.

http://www.autodebug.com

History

2007-3-23: Add WTL version source files

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

autodebug



China China

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionDoes not work under VS2008, any ideas? PinmemberDave Streeter23:09 25 Aug '09  
AnswerRe: Does not work under VS2008, any ideas? Pinmemberda_buzz10:52 12 Feb '10  
QuestionHow to change the tooltip show delay?? PinmemberC++ Matter5:54 22 Mar '07  
AnswerRe: How to change the tooltip show delay?? Pinmemberautodebug15:23 22 Mar '07  
GeneralRe: How to change the tooltip show delay?? Pinmemberyotamwimmer12:08 12 Dec '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 22 Mar 2007
Article Copyright 2007 by autodebug
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid