Private g_hwndTT As Long
Private g_ti As TOOLINFOA
(OnCreate(hwnd
g_hwndTT=CreateWindow(TOOLTIPS_CLASS, nullptr,WS_POPUP Or TTS_ALWAYSTIP Or
(TTS_BALLOON,0,0,0, 0,hwnd,0,0,0
g_ti.uFlags=TTF_TRACK
g_ti.hwnd = hwnd
("g_ti.lpszText=TEXT("Hi there
SendMessage(g_hwndTT, TTM_ADDTOOL,0,
(LPARAM)&g_ti,
return TRUE
: On Char
Dim pt As POINTAPI
Select Case wparam
if GetCursorPos (pt) Then
SendMessage(g_hwndTT,TTM_TRACKPOSITION,0,MAKELPARAM(pt.x,
((pt.y,
SendMessage(g_hwndTT,TTM_TRACKACTIVATE,TRUE
((LPARAM)&g_ti,
Exit Function
case 27 ' ESCAPE
SendMessage(g_hwndTT,TTM_TRACKACTIVATE
(FALSE,0,
Exit Function
.At startup, we add the tool but do not show the balloon tooltip yet
When the user presses the space bar
we get the current cursor position and tell the tracking tooltip
.to appear at exactly that location
.then we activate tracking mode
:The result
The balloon tip appears, and the tip of the balloon points directly
.at the mouse cursor
.When the user presses the ESC key
we deactivate tracking mode, which removes the tooltip from the
.screen
TTM_ACTIVEPOSITION
Parameters
wParam
.Must be zero
lParam
The LOWORD specifies the x-coordinate of the point at which the tracking tooltip will be displayed, in screen coordinates. The HIWORD specifies the y-coordinate of the point at which the tracking tooltip will be displayed, in screen coordinates
To have tooltip windows displayed at specific coordinates, include the TTF_ABSOLUTE flag in the uFlagsmember of the TOOLINFO structure when
.adding the tool
TTF_ABSOLUTE
Positions the tooltip window at the same coordinates provided by TTM_TRACKPOSITION. This flag must be used with the TTF_TRACK flag.
TTF_CENTERTIP
Centers the tooltip window below the tool specified bythe uId member.
TTF_IDISHWND
Indicates that the uIdmember is the window handle to the tool. If this flag is not set, uId is the tool's identifier.
(Sub CreateToolTipForRect(HWND hwndParent
'Create a tooltip. HWND
hwndTT=CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndParent, NULL, g_hInst,NULL)
SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE)
'Set up "tool" information. In this case, the "tool" is the entire parent window.
TOOLINFO ti = { 0 }
ti.cbSize = sizeof(TOOLINFO)
ti.uFlags = TTF_SUBCLASS
ti.hwnd = hwndParent
ti.hinst = g_hInst
ti.lpszText = TEXT("This is your tooltip string.")
GetClientRect (hwndParent, &ti.rect)
' Associate the tooltip with the "tool" window.
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti)
End Sub
We need to show the tooltip form without activating it, so we can use the API method, 'ShowWindow' with the SW_SHOWNA parameter, which will show the form and bring it to the front without stealing focus from other windows.
ShowWindow function
Sets the specified window's show state
SW_SHOW=5
Activates the window and displays it in its current size and position.
SW_SHOWNA=8
Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is not activated.