**I apologize in advance if this has already been discussed on the board**
I want to be able to display a balloon tooltip solely based on the location of the mouse pointer within the Window. I have not been able to find a way of doing this, please help.
This is for a Windows XP application
Balloon Tip based on Mouse Location
Something like this...
Code: Select all
#TTF_TRACK = $20
#TTF_ABSOLUTE = $80
cursorWidth = GetSystemMetrics_(#SM_CXCURSOR)
cursorHeight = GetSystemMetrics_(#SM_CYCURSOR)
Macro MakeLong(low, high)
low | high <<16
EndMacro
Global ti.TOOLINFO
; --> Create tooltip for entire window
Procedure myWindowToolTip(hwnd, ttText$)
ti.TOOLINFO\cbSize = SizeOf(TOOLINFO)
If hToolTip = 0
hToolTip = CreateWindowEx_(#WS_EX_TOPMOST, "ToolTips_Class32","", #WS_POPUP | #TTS_NOPREFIX | #TTS_ALWAYSTIP | #TTS_BALLOON, 0, 0, 0, 0, WindowID(0), 0, GetModuleHandle_(0), 0)
EndIf
GetClientRect_(hwnd, @winRect.RECT)
ti\uFlags = #TTF_IDISHWND | #TTF_TRACK | #TTF_ABSOLUTE
ti\hwnd = hwnd
ti\hInst = GetModuleHandle_(0)
ti\uId = 0
ti\lpszText = @ttText$
ti\rect\left = winRect\left
ti\rect\top = winRect\top
ti\rect\right = winRect\right
ti\rect\bottom = winRect\bottom
SendMessage_(hToolTip, #TTM_ADDTOOL, 0, ti)
SendMessage_(hToolTip, #TTM_TRACKACTIVATE, #False, @ti)
ProcedureReturn hToolTip
EndProcedure
If OpenWindow(0, 0, 0, 270, 100, "Click the left mouse button below", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
hTT = myWindowToolTip(WindowID(0), "Smart ToolTip")
Repeat
Event = WaitWindowEvent()
Select Event
Case #WM_LBUTTONDOWN
SendMessage_(hTT, #TTM_TRACKACTIVATE, #True, @ti)
mx = DesktopMouseX()
my = DesktopMouseY(); - cursorHeight / 2
SendMessage_(hTT, #TTM_TRACKPOSITION, 0, MakeLong(mx, my))
Case #WM_NCLBUTTONUP, #WM_LBUTTONUP
SendMessage_(hTT, #TTM_TRACKACTIVATE, #False, @ti)
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
Here's another. Place the cursor either at the top-left or the bottom-right of the window :
Code: Select all
OpenWindow(0, 0, 0, 300, 300, "Tooltip Styles",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
TT = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_BALLOON, 0, 0, 0, 0, 0, 0, 0, 0)
SendMessage_(TT, #TTM_SETTITLE, 1, "Hiya")
SendMessage_(TT, #TTM_SETMAXTIPWIDTH, 0, 250)
;Add two 'tools' by area; one in the top left of the window and one in the bottom right.
ti.TOOLINFO\cbSize = SizeOf(TOOLINFO)
ti\uFlags = #TTF_CENTERTIP | #TTF_SUBCLASS
ti\hwnd = WindowID(0)
ti\lpszText = @"Tooltip 0"
;Top left.
ti\uId = 0
SetRect_(@ti\rect, 0,0,20,20)
;Register 'tool' with the control
SendMessage_(TT, #TTM_ADDTOOL, 0, ti)
;Bottom right.
ti\uId = 1
SetRect_(@ti\rect, 280,280,300,300)
ti\lpszText = @"Tooltip 1"
;Register 'tool' with the control
SendMessage_(TT, #TTM_ADDTOOL, 0, ti)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
I may look like a mule, but I'm not a complete ass.

