/*
Function: ShowTooltip
Show the tooltip and automatically dismiss it.
Parameters:
Text - Text to show. If omitted or empty, any existing tooltip will be hidden.
X,Y - Coordinates on which to show tooltip. Affected by CoordMode. Optional.
In, Out - Time in milliseconds for tooltip to show and to disappear.
- If TimeOut is 0, tooltip will never be dismissed. Optional.
bControl - Set to TRUE to associate the tooltip with control currently under the mouse.
- That means that Tooltip will not be shown if control has changed. By default, false
Nr - Tooltip number, by default 19. Multiple tooltips can exist with different settings.
About:
o v2.0 by HotKeyIt
*/
ShowToolTip(Text="", X="",Y="", In=500, Out=1500, bControl=0, Nr=19){
static
If (Text=""){
MouseGetPos,,,_win,_ctrl
ControlGet,hCtrl,HWND,,%_ctrl%,ahk_id %_win%
If ((T_Text%Nr% && !T_%Nr% && T_In%Nr%<A_TickCount && (!T_Ctrl%Nr% or (T_Ctrl%Nr% && hCtrl=T_Ctrl%Nr%))) || (T_%Nr% && T_Out%Nr%<A_TickCount && !((T_Text%Nr%:="") . (T_X%Nr%:="") . (T_Y%Nr%:="") . (T_In%Nr%:="") . (T_Out%Nr%:="") . (T_%Nr%:="") . (T_Ctrl%Nr%:=""))))
ToolTip % T_Text%Nr%,% T_X%Nr%,% T_Y%Nr%,% Nr+(T_Text%Nr% ? ((T_%Nr%:=1)-1) : 0)
Return (!T_%Nr% ? T_In%Nr% : (T_Out%Nr%>A_TickCount ? T_Out%Nr% : ""))
} else if (bControl=1){
MouseGetPos,,,_win,_ctrl
ControlGet,T_Ctrl%Nr%,HWND,,%_ctrl%,ahk_id %_win%
} else T_Ctrl%Nr%:=0
T_Text%Nr%:=text,T_X%Nr%:= X,T_Y%Nr%:= Y,T_In%Nr%:=Round(A_TickCount+In),T_Out%Nr%:=(Out ? Round(A_TickCount+In+Out) : 9223372036854775807)
ShowToolTip:
NextTimer=
Loop 20
If (ErrorLevel:=ShowToolTip("","","","","","",A_Index))
If (!NextTimer || NextTimer+A_TickCount>ErrorLevel)
NextTimer:=(ErrorLevel-A_TickCount<0) ? "" : (ErrorLevel-A_TickCount+10)
SetTimer, ShowToolTip,% NextTimer ? (-1*(NextTimer+10)) : "Off"
Return
}
[function] ShowTooltip 2.0
#1
Posted 10 September 2009 - 08:04 AM
#2
Posted 11 September 2009 - 04:47 PM
-gwarble
#3
Posted 11 September 2009 - 05:04 PM
I think Tooltip number as parameter will be better (not tested):
; From majkinetor
; http://www.autohotkey.com/forum/viewtopic.php?p=295501#295501
; Loaded 11/09/2009
;
; From MaxMax14 : Add ToolTipNr=1 parameter
;
/*
Function: ShowTooltip
Show the tooltip and automatically dismiss it.
Parameters:
Msg - Text to show. If omitted or empty, any existing tooltip will be hidden.
X,Y - Coordinates on which to show tooltip. Affected by CoordMode. Optional.
TimeIn, TimeOut - Time in milliseconds for tooltip to show and to disappear.
If TimeOut is 0, tooltip will never be dismissed. Optional.
ToolTipNr=1 - ToolTip Nr
About:
o v1.0 by majkinetor
*/
ShowTooltip( Msg, X="" ,Y="", TimeIn=500, TimeOut=1500, ToolTipNr=1){
static
_Msg := Msg, _X:=X, _Y:=Y,, _TimeOut := TimeOut
MouseGetPos,,,_win,_ctrl
SetTimer, ShowTooltipOn, % -TimeIn
return
ShowTooltipOff:
Tooltip,,,,%ToolTipNr%
return
ShowTooltipOn:
if (_TimeOut)
SetTimer, ShowTooltipOff, % -_TimeOut
MouseGetPos,,,win,ctrl
if (win != _win) || (ctrl != _ctrl)
return
Tooltip,%_Msg% , _X, _Y, %ToolTipNr%
return
}MaxMax14
#4
Posted 11 September 2009 - 05:18 PM
I just don't remember that I ever used Tooltip 19, so ...
#5
Posted 11 September 2009 - 06:16 PM
Find herewith a similar function I use :
ToolTipNxy(Text, TimeOut=5000,ToolTipNr=1,X2=100,Y2=100,Mode=0){ ;ToolTip function WITH mouse position
/*
Function: ToolTipNxy
Show the tooltip and automatically dismiss it.
Parameters:
Text - Text to show.
TimeOut - Time in milliseconds for tooltip to show and to disappear.
ToolTipNr=1 - ToolTip Nr from 1 to 20
X2,Y2 - Coordinates on which to show tooltip. Affected by CoordMode and mode parameter.
Mode=0 -> Take account parameters : X,Y position of the tooltip relative to the active window
Mode=1 -> X,Y not taking account -> mouse Position
Mode=2 -> X,Y middle of the screen
Mode=3 -> x,y = Offset relative to mouse position
About:
o v1.0 by MaxMax14
*/
If Mode = 0
ToolTip, %Text%,X2,Y2,%ToolTipNr%
If Mode = 1
{
ToolTip, %Text%,,,%ToolTipNr%
}
If Mode = 2
{
X2:=A_ScreenWidth/2
Y2:=A_ScreenHeight/2
;msgbox,0,Stop,X2=%X2%`nY2=%Y2%
ToolTip, %Text%,X2,Y2,%ToolTipNr%
}
If Mode = 3
{
MouseGetPos, Mouse_X, Mouse_Y
X3:=Mouse_X + X2
Y3:=Mouse_Y + Y2
ToolTip, %Text%,X3,Y3,%ToolTipNr%
}
SetTimer, RemoveToolTip%ToolTipNr%, %TimeOut%
Return
}
;_______________________________________________________________________________
RemoveToolTip1:
ToolTip,,,,1
Return
RemoveToolTip2:
ToolTip,,,,2
Return
RemoveToolTip3:
ToolTip,,,,3
Return
RemoveToolTip4:
ToolTip,,,,4
Return
RemoveToolTip5:
ToolTip,,,,5
Return
RemoveToolTip6:
ToolTip,,,,6
Return
RemoveToolTip7:
ToolTip,,,,7
Return
RemoveToolTip8:
ToolTip,,,,8
Return
RemoveToolTip9:
ToolTip,,,,9
Return
RemoveToolTip10:
ToolTip,,,,10
Return
RemoveToolTip11:
ToolTip,,,,11
Return
RemoveToolTip12:
ToolTip,,,,12
Return
RemoveToolTip13:
ToolTip,,,,13
Return
RemoveToolTip14:
ToolTip,,,,14
Return
RemoveToolTip15:
ToolTip,,,,15
Return
RemoveToolTip16:
ToolTip,,,,16
Return
RemoveToolTip17:
ToolTip,,,,17
Return
RemoveToolTip18:
ToolTip,,,,18
Return
RemoveToolTip19:
ToolTip,,,,19
Return
RemoveToolTip20:
ToolTip,,,,20
ReturnMaxMax14
#6
Posted 11 September 2009 - 06:43 PM
#7
Posted 12 September 2009 - 02:11 AM
RemoveToolTip1: ToolTip,,,,1 Return RemoveToolTip2: ToolTip,,,,2 Return
Looks funny D.R.Y.
why not use a function
RemoveToolTip( nr ) {
ToolTip,,,,%nr%
}
3 line instead of 60.
#8
Posted 12 September 2009 - 10:10 AM
I think it won't work
1) You need to call a label :
2) If you call a label that call a function like yours I think i won't work if you call more than one tooltip at the same time because timer will call always the same label and will use the last value of variable "ToolTipNr"SetTimer, Label [, Period|On|Off, Priority]
MaxMax14
#9
Posted 12 September 2009 - 12:21 PM
#10
Posted 12 September 2009 - 12:29 PM
RemoveToolTip1: RemoveToolTip2: RemoveToolTip3: ... RemoveToolTip20: ToolTip,,,, % SubStr(A_ThisLabel,14) Return
#11
Posted 12 September 2009 - 03:35 PM
-|------|--------|-------|-----------------------------> time t1 m1 t2 m2
In this scenario there are 2 tooltips, t & m, timeIn is marked as 1 and timeout as 2.
So timer first fires at t1, then m1-t1, then t2-m1 then m2-t2 (in this case). To support all possible outcomes requries work but I it can maybe be done in less then 22 lines of code, most importantly, it will not make cloud of sublabel names which will AFAIK slowdown internal label name search as it is linear. Several functions that use this kind of thing can easily create more then hundred unnecessary labels.
However, all that for multiple tooltips (rarely something you rly want) on the screen doesn't seem like idea too me. Thats why I keep original code with tooltip 19. Afterall, if you need two toolips, its easy to use Maxmax14s version and copy the func 2 times with different name and use different number.
#12
Posted 12 September 2009 - 07:07 PM
#Persistent
CoordMode,ToolTip,Screen
Loop % (20){
Random,posx,0,% A_ScreenWidth
Random,posy,0,% A_ScreenHeight
Random,TimeIn,500,5000
Random,TimeOut,2000,10000
ShowToolTip("ToolTip " A_Index,A_Index,TimeOut/1000,TimeIn/1000,posx,posy)
}
MsgBox Watch the ToolTips
ExitApp
ShowToolTip(Text, Nr=1,Out=5,In=0,X="",Y=""){
static
If (text=""){
If ((T_Text%Nr% && !T_%Nr% && T_In%Nr%<A_TickCount) || (T_%Nr% && T_Out%Nr%<A_TickCount && !((T_Text%Nr%:="") . (T_X%Nr%:="") . (T_Y%Nr%:="") . (T_In%Nr%:="") . (T_Out%Nr%:="") . (T_%Nr%:=""))))
ToolTip % T_Text%Nr%,% T_X%Nr%,% T_Y%Nr%,% Nr+(T_%Nr%:=1)-1
Return (!T_%Nr% ? T_In%Nr% : (T_Out%Nr%>A_TickCount ? T_Out%Nr% : ""))
}
T_Text%Nr%:=text,T_X%Nr%:= X,T_Y%Nr%:= Y,timer ? "" : (timer:=1),T_In%Nr%:=Round(A_TickCount + In*1000),T_Out%Nr%:=Round(A_TickCount + (In+Out)*1000), NextTimer ? "" : (NextTimer:=10)
ShowToolTip:
NextTimer=
Loop 20
If (ErrorLevel:=ShowToolTip("",A_Index))
If (!NextTimer || NextTimer+A_TickCount>ErrorLevel)
NextTimer:=ErrorLevel-A_TickCount+10
SetTimer, ShowToolTip,% NextTimer ? (-1*(NextTimer+10)) : "Off"
Return
}EDIT:
Bug with SetTimer fixed
#13
Posted 12 September 2009 - 09:13 PM
You need to check current window and control tho. Tooltip shouldn't show up if cursor has moved out of triggering area before tooltip is fired. Thinking about it now, it should be an option (bControl). Its important to have both features. One is there for notifications, other for control tooltips.
Thanks.
#14
Posted 12 September 2009 - 09:37 PM
This is seriiously cool
You need to check current window and control tho. Tooltip shouldn't show up if cursor has moved out of triggering area before tooltip is fired. Thinking about it now, it should be an option (bControl). Its important to have both features. One is there for notifications, other for control tooltips.
Thanks.
Thanks
Can you show an example (using your code) what win hWnd and control Id is useful for :?:
#15
Posted 13 September 2009 - 08:11 AM
When you hover over A you call ShowTooltip function. It requires TimIn to show the tooltip. Before that time you move the cursor to B. Then tooltip of A (wrongly) bumps in over B. You could cancel it yourself on entering B, but then the whole point of function is lost.
I had the similar problem with tray icons in custom taskbar. I was fireing showtooltip on Toolbar control (which holds the tray icons) HOT event. Then if I moved mouse to the center of the desktop before tooltip fired, tooltip would fire there. This is not something regular tray area does - as soon as you move cursor out of it, tooltip is canceled.




