How to use Windows ToolTip Control without bounding to a tool How to use Windows ToolTip Control without bounding to a tool windows windows

How to use Windows ToolTip Control without bounding to a tool


You need to call TTM_ADDTOOL at least once, you can't call TTM_SETTOOLINFO or get TTN_GETDISPINFO without it AFAIK.

If your target it XP+ you can get away with using TTM_POPUP to display the tip at any position and at any time (But you need to handle the initial delay yourself unless you want a tracking tooltip)

Generally you call TTM_ADDTOOL and associate it with a rectangle (TOOLINFO.rect) or a child window, or you can set the text to LPSTR_TEXTCALLBACK and handle TTN_GETDISPINFO if everything has a tip. MSDN has some sample code you should take a look at...


Addition Windows 10 (Visual Studio 2015, Win32 Console Application)

#include "Commctrl.h"                   #pragma comment (lib,"comctl32.lib")    #pragma comment(linker,"\"/manifestdependency:type='win32' \name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")TOOLINFOW ti = {};ti.cbSize = sizeof(TOOLINFOW);ti.uFlags = TTF_ABSOLUTE | TTF_IDISHWND | TTF_TRACK ; // WITH TTF_TRACK! Otherwise the tooltip doesn't follow TTM_TRACKPOSITION message!ti.hwnd = toolTipWnd;                       ti.hinst = 0;ti.uId = (UINT)toolTipWnd;ti.lpszText = L"";LRESULT result; int error; if (!SendMessageW(toolTipWnd, TTM_ADDTOOLW, 0, (LPARAM)&ti)) {    MessageBox(NULL, L"Couldn't create the ToolTip control.", L"Error", MB_OK);    error = 0;    error = GetLastError();}if (!SendMessageW(toolTipWnd, TTM_SETMAXTIPWIDTH, 0, (LPARAM)350)) {    MessageBox(NULL, L"Couldn't create the ToolTip control.", L"Error", MB_OK);    error = 0;    error = GetLastError();}