This SO Answer 提到可以使用TTM_POPUP message 调出工具提示,使用TTM_TRACKPOSITION 设置工具提示的位置。
编辑:我对此有点好奇,并尝试制作一个工作示例:
a) 在清单中包含常用控件或在源代码中使用以下行
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
b) 创建和设置工具提示窗口
hWndtoolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, 0, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, hWndParent, 0, hInstance, 0);
SetWindowPos(hWndtoolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
TOOLINFO ti = {};
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hWndParent;
ti.hinst = hInstance;
ti.uId = (UINT)hWndtoolTip;
ti.lpszText = L"tool-tip";
GetClientRect(hWndParent, &ti.rect);
SendMessage(hWndtoolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
c) 在特定位置显示工具提示(例如,x=300,y=300):
SetCursorPos(300, 300);
SendMessage(hWndtoolTip, TTM_POPUP, 0, 0);