Introduction
This article shows how to display tooltips at any location on the screen.
To create a tooltip it is necessary to create a window of class TOOLTIPS_CLASS
, then to fill
a TOOLINFO
structure:
typedef struct tagTOOLINFO{
UINT cbSize;
UINT uFlags;
HWND hwnd;
UINT_PTR uId;
RECT rect;
HINSTANCE hinst;
LPTSTR lpszText;
#if (_WIN32_IE >= 0x0300)
LPARAM lParam;
#endif
} TOOLINFO, NEAR *PTOOLINFO, FAR *LPTOOLINFO;
We determine two parameters in this structure which are interesting to us: uFlags
and lpszText
.
uFlags
it is chosen equal TTF_TRACK
, that gives us an opportunity of use
message sending to choosing a position for ToolTip and control visibility.
lpszText
- the task of the text which we want display.
Now we send the message in system, about desire to create the emerging help where we transfer the reference to our structure TOOLINFO
SendMessage (hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) *ti);
Then we send a TTM_TRACKPOSITION
message which sets the coordinates of ToolTip
SendMessage (hwndTT, TTM_TRACKPOSITION, 0, (LPARAM) (DWORD) MAKELONG (m_x, m_y));
where
m_x
and
m_y
coordinates x and y on the screen.
And finally we send the message to activate the ToolTip
SendMessage (hwndTT, TTM_TRACKACTIVATE, true, (LPARAM) (LPTOOLINFO) *ti);
where
the
true
value indicates we will display the ToolTip. If we specified
false
, the ToolTip will be
hidden.
History
1 Sep 2002 - updated source code