TIP: Create In-Place ToolTips on Your Own Controls

It is very easy to create in-place toolTips on your own control. For example, you can place one on a treeview control.

Step 1

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

   afx_msg void OnMouseMove(UINT nFlags, CPoint point);
   afx_msg void OnMouseLeave(WPARAM wPawam, LPARAM lParam);
   CToolTipCtrl m_toolTip;
   TOOLINFO   m_ti;

Step 2

In the window's implementation file, add the following to the end of Create to set the ToolTips.

m_ti.cbSize = sizeof(m_ti);
m_ti.hwnd = m_hWnd;
m_ti.hinst = NULL;
m_ti.uId = (UINT)m_hWnd;
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:


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);
   RECT rect;
   GetItemRect(pItem, &rect);
   POINT pt;

   tk.cbSize = sizeof(tk);
   tk.dwFlags = TME_LEAVE;
   tk.dwHoverTime = 0;
   tk.hwndTrack = m_hWnd;
   pt.x = rect.left - 3;
   pt.y = rect.top - 2;
   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);

About the Author

Unknown Unknown

Best API Monitor tool. automatic monitor any dll all api's input and output parameter. http://www.autodebug.com



  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date