Click here to Skip to main content
15,881,709 members
Articles / Desktop Programming / MFC
Article

Display ToolTip in any place on the screen

Rate me:
Please Sign up or sign in to vote.
4.51/5 (32 votes)
1 Sep 2002 200.8K   7.3K   56   41
This article shows how to display tooltips at any location on the screen

Sample ToolTip

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:

C++
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

C++
SendMessage (hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) *ti);

Then we send a TTM_TRACKPOSITION message  which sets the coordinates of ToolTip

C++
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

C++
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

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


Written By
Software Developer
Belarus Belarus
I work as the programmer. I live in Belarus in Minsk. At me higher education. I have experience development programs at use TCP/IP, Win32, MFC, HTTP, SNMP, HASP4, eToken, OpenGl, Hooks. Recently I use packages of development Visual Studio 6.0 and .Net.

Comments and Discussions

 
GeneralRe: Thanks very much! Pin
Zarembo Maxim29-Jul-04 1:21
Zarembo Maxim29-Jul-04 1:21 
GeneralWrapping the text Pin
Balkrishna Talele22-Apr-04 0:49
Balkrishna Talele22-Apr-04 0:49 
GeneralRe: Wrapping the text Pin
Zarembo Maxim22-Apr-04 2:56
Zarembo Maxim22-Apr-04 2:56 
GeneralUnregistering Tooltips rect Pin
Majid Shahabfar16-Dec-02 1:28
Majid Shahabfar16-Dec-02 1:28 
GeneralExcellent article Pin
dabs3-Sep-02 0:36
dabs3-Sep-02 0:36 
GeneralAdding tooltip to picture control Pin
Anonymous2-Sep-02 0:38
Anonymous2-Sep-02 0:38 
GeneralRe: Adding tooltip to picture control Pin
Chopper18-Dec-02 0:27
Chopper18-Dec-02 0:27 
Generalres directory missing from source Pin
Andreas Saurwein1-Sep-02 22:59
Andreas Saurwein1-Sep-02 22:59 
You should repackage the source zip because it is missing the ./res directory. Although it doesnt contain any unique files, they are necessary to compile it.

int x=1, y=5; 
x^=y^=x^=y; // whats the content of x and y now?
<a href="http://www.codeproject.com/tips/StupidXORTrick.asp" target="_blank">ClickHereForHelp();</a>

GeneralRe: res directory missing from source Pin
Anonymous1-Sep-02 23:47
Anonymous1-Sep-02 23:47 
GeneralC++ .NET question Pin
Anonymous12-Aug-02 3:45
Anonymous12-Aug-02 3:45 
GeneralRe: C++ .NET question Pin
Anonymous12-Aug-02 21:19
Anonymous12-Aug-02 21:19 
GeneralRe: C++ .NET question Pin
Anonymous2-Sep-02 0:05
Anonymous2-Sep-02 0:05 
GeneralRe: C++ .NET question Pin
Edwin Geng18-Sep-02 6:42
Edwin Geng18-Sep-02 6:42 
GeneralRe: C++ .NET question Pin
Anonymous16-Oct-02 17:01
Anonymous16-Oct-02 17:01 
GeneralRe: C++ .NET question Pin
JaseNet2-Dec-04 23:51
JaseNet2-Dec-04 23:51 
GeneralRe: C++ .NET question Pin
k_snow18-Jan-05 3:33
k_snow18-Jan-05 3:33 
GeneralRe: C++ .NET question Pin
panzerdivisionmarkus22-Dec-05 4:44
panzerdivisionmarkus22-Dec-05 4:44 
GeneralRe: C++ .NET question Pin
Morten Fjeldstad25-Jan-06 0:44
Morten Fjeldstad25-Jan-06 0:44 
GeneralRe: C++ .NET question Pin
lin2alan15-Jun-06 17:20
lin2alan15-Jun-06 17:20 
GeneralRe: C++ .NET question PinPopular
_FKS_3-May-07 4:45
_FKS_3-May-07 4:45 
GeneralRe: C++ .NET question Pin
zengkun1008-Dec-09 22:43
zengkun1008-Dec-09 22:43 
GeneralGood Job! Pin
Ed Gadziemski11-Jun-02 2:54
professionalEd Gadziemski11-Jun-02 2:54 

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

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