WARNING: This is old thread. It is continued here.Here is a
ToolTipFM() function -
ToolTip which
Follows the
Mouse
Now it does not flicker when you move the mouse, but flickers once per text change.
Function:ToolTipFM(Text="", WhichToolTip=16, xOffset=16, yOffset=16) { ; ToolTip which Follows the Mouse
static LastText, hwnd, VirtualScreenWidth, VirtualScreenHeight ; http://www.autohotkey.com/forum/post-430240.html#430240
if (VirtualScreenWidth = "" or VirtualScreenHeight = "")
{
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
}
if (Text = "") ; destroy tooltip
{
ToolTip,,,, % WhichToolTip
LastText := "", hwnd := ""
return
}
else ; move or recreate tooltip
{
CoordMode, Mouse, Screen
MouseGetPos, x,y
x += xOffset, y += yOffset
WinGetPos,,,w,h, ahk_id %hwnd%
; if necessary, adjust Tooltip position
if ((x+w) > VirtualScreenWidth)
AdjustX := 1
if ((y+h) > VirtualScreenHeight)
AdjustY := 1
if (AdjustX and AdjustY)
x := x - xOffset*2 - w, y := y - yOffset*2 - h
else if AdjustX
x := VirtualScreenWidth - w
else if AdjustY
y := VirtualScreenHeight - h
if (Text = LastText) ; move tooltip
DllCall("MoveWindow", A_PtrSize ? "UPTR" : "UInt",hwnd,"Int",x,"Int",y,"Int",w,"Int",h,"Int",0)
else ; recreate tooltip
{
; Perfect solution would be to update tooltip text (TTM_UPDATETIPTEXT), but must be compatible with all versions of AHK_L and AHK Basic.
; My Ask For Help link: http://www.autohotkey.com/forum/post-421841.html#421841
CoordMode, ToolTip, Screen
ToolTip,,,, % WhichToolTip ; destroy old
ToolTip, % Text, x, y, % WhichToolTip ; show new
hwnd := WinExist("ahk_class tooltips_class32 ahk_pid " DllCall("GetCurrentProcessId")), LastText := Text
%A_ThisFunc%(Text, WhichToolTip, xOffset, yOffset) ; move new
}
Winset, AlwaysOnTop, on, ahk_id %hwnd%
}
}
Edit 07.05.2011.: fixed positioning on multi-monitors. Thanks to musketball and me lance for testing.Testing area:
; Press and hold F1-F4 hotkeys, and move mouse.
Text = ; Make too long ToolTip text for testing purpose
(
If blank or omitted, the existing tooltip (if any) will be hidden.
Otherwise, this parameter is the text to display in the tooltip.
If blank or omitted, the existing tooltip (if any) will be hidden.
Otherwise, this parameter is the text to display in the tooltip.
If blank or omitted, the existing tooltip (if any) will be hidden.
Otherwise, this parameter is the text to display in the tooltip.
If blank or omitted, the existing tooltip (if any) will be hidden.
Otherwise, this parameter is the text to display in the tooltip.
If blank or omitted, the existing tooltip (if any) will be hidden.
Otherwise, this parameter is the text to display in the tooltip.
If blank or omitted, the existing tooltip (if any) will be hidden.
Otherwise, this parameter is the text to display in the tooltip.
If blank or omitted, the existing tooltip (if any) will be hidden.
Otherwise, this parameter is the text to display in the tooltip.
)
;=== Test ToolTip mouse following ===
F1:: ; old system = flickers + high CPU load + slow moving
While, GetKeyState(A_ThisHotkey,"p")
{
Sleep, 20
ToolTip, % text
}
ToolTip
return
F2:: ; new system = does not flicker + low CPU load + fast moving
While, GetKeyState(A_ThisHotkey,"p")
{
Sleep, 20
ToolTipFM(Text)
}
ToolTipFM()
return
;=== Test ToolTip mouse following + text change ===
F3:: ; old system = flickers + high CPU load + slow moving
; Note: It's so slow that you'll need to hold hotkey for a long time to wait text to change.
c := 0
While, GetKeyState(A_ThisHotkey,"p")
{
Sleep, 20
c++
if (c < 100)
ToolTip, % Text
else if (c < 200)
ToolTip, % (SubStr(Text,1,50))
else
c = 0
}
ToolTip
return
F4:: ; new system = one flicker per text change + low CPU load + fast moving
c := 0
While, GetKeyState(A_ThisHotkey,"p")
{
Sleep, 20
c++
if (c < 100)
ToolTipFM(Text)
else if (c < 200)
ToolTipFM(SubStr(Text,1,50))
else
c = 0
}
ToolTipFM()
return
Everyone is welcome to
improve it - to use TTM_UPDATETIPTEXT instead of Tooltip recreation, but must be compatible with
all versions of AHK_L and
AHK Basic