
Introduction
This article describes what is in my opinion the simplest and best way to add tool tips to the menu items. All you have to do is simply include the header file and call Create
and hook the WM_MENUSELECT
message.
Call this Create
function in OnInitDialog
or OnCreate
functions of your main window
myMenuToolTip.Create(m_hWnd, _T("Sample Menu Text"),
AfxGetResourceHandle(), TTS_NOPREFIX | TTS_BALLOON
, _T("My Best Tool Tip Title")
);
When your window receives WM_MENUSELECT
, call OnMenuSelect
function to notify my helper class
myMenuToolTip.OnMenuSelect(nItemID, nFlags, hSubMenu);
Helper Class implementation
- Creates a tool tip window and adds the parent as tool to tooltip window
- Makes the tool as trackable tool
- On
MenuSelect
(Highlight) based on selected item, helper class activates the tooltip and positions it next selected menu item.
- On
MenuSelect
(Unhighlight) deactivates the tooltip
Instead of just calling OnMenuSelect
you could handle the menu messages by looking at default implementation in the helper class
Note: Tip text is extracted from resource just like MFC/WTL extracts text for status bar messages.