Many thanks to: - DerRaphael for sTooltip - colored standard tooltip with timeout. - Sean for BalloonTip - Superfraggle for Add ToolTips to controls. - Lexikos for Menu Icons v2 (stdlib) - majkinetor for RemoteBuffer 2.0 (requiered to show ToolTip at TrayIcon coordinates)
Important Information wrote:
Please note some options like Close Button and Link will require Win2000++ (+version 6.0 of comctl32.dll) Background and Text color do not work in Vista ToolTips, but you can disable it using Q option. AutoHotKey Version 1.0.48++ is required due to "assume static mode" If you use 1 ToolTip for several controls, the only difference between those can be the text. - Rest, like Title, color and so on, will be valid globally In Vista you can use Option Q (Q1) to disable Vista or XP Theme for the ToolTip - this option will enable usual ToolTip and you can use colors
Options wrote:
A - Aim ConrolId or ClassNN (Button1, Edit2, ListBox1, SysListView321...) - using this, ToolTip will be shown when you point mouse on a control - D (delay) can be used to change how long ToolTip is shown - W (wait) can wait for specified seconds before ToolTip will be shown - Some controls like Static require a subroutine to have a ToolTip!!! B and F - Specify here the color for ToolTip in 6-digit hexadecimal RGB code - B = Background color, F = Foreground color (text color) - this can be 0x00FF00 or 00FF00 or Blue, Lime, Black, White... C - Close button for ToolTip/BalloonTip. See ToolTip actions how to use it D - Delay. This option will determine how long ToolTip should be shown.30 sec. is maximum - this option is also available when assigning the ToolTip to a control. E - Edges for ToolTip, Use this to set margin of ToolTip window (space between text and border) - Supply Etop.left.bottom.right in pixels, for example: E10.0.10.5 G - Execute one or more internal Labels of ToolTip function only. For example: - Track the position only, use ToolTip(1,"","","Xcaret Ycaret gTTM_TRACKPOSITION") - When X+Y are empty (= display near mouse position) you can use TTM_UPDATE - Update text only, use ToolTip(1,"text","","G1"). Note specify L1 if links are used. - Update title only, use ToolTip(1,"","Title","G1") - Hide ToolTip, use ToolTip(1,"","","gTTM_POP") - To show ToolTip again use ToolTip(1,"","","gTTM_TRACKPOSITION.TTM_TRACKACTIVATE") - Update background color + text color, specify . between gLabels to execute several: - ToolTip(1,"","","BBlue FWhite gTTM_SETTIPBKCOLOR.TTM_SETTIPTEXTCOLOR") - Following labels can be used: TTM_SETTITLEA + TTM_SETTITLEW (title+I), TTM_POPUP, TTM_POP TTM_SETTIPBKCOLOR (B), TTM_SETTIPTEXTCOLOR (F), TTM_TRACKPOSITION (N+X+Y), TTM_SETMAXTIPWIDTH (R), TTM_SETMARGIN (E), TT_SETTOOLINFO (text+A+P+N+X+Y+S+L) TTM_SETWINDOWTHEME (Q) H - Hide ToolTip after a link is clicked.See L option I - Icon 1-3, e.g. I1. If this option is missing no Icon will be used (same as I0) - 1 = Info, 2 = Warning, 3 = Error, > 3 is meant to be a hIcon (handle to an Icon) Use Included MI_ExtractIcon and GetAssociatedIcon functions to get hIcon J - Justify ToolTip to center of control L - Links for ToolTips. Here an example for Links feature and another one for dynamic Text.
Code (Expand):
OnMessage(0x4e,"WM_NOTIFY") ;Will make LinkClick and ToolTipClose possible WM_NOTIFY(wParam, lParam, msg, hWnd) { ToolTip("",lParam) } Sleep, 10 ToolTip(1,"<a>Click</a>`n<a>Onother one</a>`n" . "<a This link is different`nit uses different text>Different</a>`n" . "<a>ExitApp</a>","ClickMe","L1 P99 C1") Return ToolTip: link:=ErrorLevel SetTimer, MsgBox, -10 Return ToolTipClose: ExitApp MsgBox: If Link=ExitApp ExitApp MsgBox % Link Return
Code (Expand):
OnMessage(0x4e,"WM_NOTIFY") Gui,Add,Button,,Time Gui,Add,Button,,Username Gui,Add,Button,,User is Admin? Gui,Add,Button,,IP addresses Loop 4 ToolTip("Button1"," ","","p1 aButton" . A_Index) gui,show Sleep, 3000 ToolTip("Button1","hallo","","G1") Return WM_NOTIFY(wParam,lParam){ If (control:=ToolTip("",lparam)){ Tool:=ErrorLevel MouseGetPos,,,,ClassNN If (ClassNN="Button1"){ FormatTime,text,%A_Now%,HH:mm:ss Title:="Time" } else if (ClassNN="Button2"){ text:=A_UserName,title:="UserName" } else if (ClassNN="Button3"){ text:=(A_ISAdmin ? "Yes" : "No"),title:="User is Admin?" } else if (ClassNN="Button4"){ text:= "1: " A_IPAddress1 "`n2: " A_IPAddress2 "`n3: " A_IPAddress3 "`n4: " A_IPAddress4 title:="IP Addresses" } ToolTip(control,text,title,"G1 A" . ErrorLevel) } } GuiClose: ExitApp
M - Mouse click-trough. So a click will be forwarded to the window underneath ToolTip N - Do NOT activate ToolTip (N1), To activate (show) call ToolTip(1,"","","gTTM_TRACKACTIVATE") O - Oval ToolTip (BalloonTip). Specify O1 to use a BalloonTip instead of ToolTip. P - Parent window hWnd or GUI number. This will assign a ToolTip to a window. - Reqiered to assign ToolTip to controls and actions. Q - Quench Style/Theme. Use this to disable Theme of ToolTip. Using this option you can have for example colored ToolTips in Vista. R - Restrict width. This will restrict the width of the ToolTip. So if Text is to long it will be shown in several lines S - Show at coordinates regardless of position. Specify S1 to use that feature - normally it is fed automaticaly to show on screen T - Transparency. This option will apply Transparency to a ToolTip. - this option is not available to ToolTips assigned to a control. V - Visible: even when the parent window is not active, a control-ToolTip will be shown W - Wait time in seconds (max 30) before ToolTip pops up when pointing on one of controls. X and Y - Coordinates where ToolTip should be displayed, e.g. X100 Y200 - leave empty to display ToolTip near mouse - you can specify Xcaret Ycaret to display at caret coordinates
A few examples: InfoToolTip
Code (Expand):
;-- Build GUI gui -MinimizeBox Gui +LastFound GuiHwnd:=WinExist() gui Add,Button,w150 hwndButton1_hWnd gButton1,Test Button 1 Tip:="Button 1: Press me to change my tooltip" ToolTip(1,Tip,"","A" . Button1_hWnd . " P" . GuiHwnd) gui Add,Button,y+0 w150 hwndButton2_hWnd gButton2,Test Button 2 Tip:="Button 2: Press me to turn off the tooltip for this button" ToolTip(2,Tip,"","A" . Button2_hWnd . " P" . GuiHwnd) gui Add,Button,y+0 w150 hwndButton3_hWnd gButton3,Test Button 3 Tip= (ltrim A Multiline Test Tooltip 2nd line 3rd line 4th line. Press me to turn off all tooltips ) ToolTip(3,Tip,"","A" . Button3_hWnd . " P" . GuiHwnd) gui Add,Checkbox,w150 hwndCheckbox_hWnd,Checkbox Control Tip:="Tooltip for the Checkbox control" ToolTip(4,Tip,"","A" . Checkbox_hWnd . " P" . GuiHwnd) gui Add,Radio,w150 hwndRadio_hWnd,Radio Control Tip:="Tooltip for the Radio control" ToolTip(5,Tip,"","A" . Radio_hWnd . " P" . GuiHwnd) gui Add,Edit,w150 hwndEdit_hWnd,Edit Control Tip:="Tooltip for the Edit control" ToolTip(6,Tip,"","A" . Edit_hWnd . " P" . GuiHwnd) gui Add,Text,w150 hwndText_hWnd gNull,Text Control Tip= (ltrim join`s Tooltip for the Text control.`nNote that the Tooltip for a Text control does not show unless a g-label for the control is defined. ) ToolTip(7,Tip,"","A" . Text_hWnd . " P" . GuiHwnd) gui Add,Picture,w150 h100 hwndPicture_hWnd gNull,Picture.bmp Tip= (ltrim join`s Tooltip for the Picture control.`nNote that the Tooltip for a Picture control does not show unless a g-label for the control is defined. ) ToolTip(9,Tip,"","A" . Picture_hWnd . " P" . GuiHwnd) gui Add,DropDownList,w150 r3 hwndDropDownList_hWnd,DropDownList Control||2|3 Tip:="Tooltip for the DropDownList control" ToolTip(10,Tip,"","A" . DropDownList_hWnd . " P" . GuiHwnd) gui Add,ComboBox,w150 r3 hwndComboBox_hWnd,ComboBox Control||2|3 ;-- A ComboBox is actually two controls: An Edit control and a Drop-down ; button. Note that handle returned for this control is for the ; drop-down button, not for the Edit control. Tip= (ltrim join`s Tooltip for the drop-down button piece of the ComboBox control.`nNote that this tip is different than the Edit piece of the control. ) ToolTip(11,Tip,"","A" . ComboBox_hWnd . " P" . GuiHwnd) gui Add,ListBox,w150 r3 hwndListBox_hWnd,ListBox Control||2|3 Tip:="Tooltip for the ListBox control" ToolTip(12,Tip,"","A" . ListBox_hWnd . " P" . GuiHwnd) gui Add,ListView,w150 h50 hwndListView_hWnd,ListView Control Tip= (ltrim join`s Tooltip for the ListView control.`nNote that this tip is different than the header piece of the control. ) ToolTip(13,Tip,"","A" . ListView_hWnd . " P" . GuiHwnd) gui Add,DateTime,w150 hwndDateTime_hWnd ;,DateTime Control Tip:="Tooltip for the DateTime control" ToolTip(14,Tip,"","A" . DateTime_hWnd . " P" . GuiHwnd) gui Add,UpDown,hwndUpDown_hWnd Range 1-100,5 Tip:="Tooltip for the UpDown control" ToolTip(20,Tip,"","A" . UpDown_hWnd . " P" . GuiHwnd) gui Show,,Tooltip Test ;-- Note: The following information cannot be collected until after the window ; has been rendered ;-- Get hWnd to the Edit control piece of the ComboBox ControlGet EditComboBox_hWnd,hWnd,,Edit2,Tooltip Test Tip= (ltrim join`s Tooltip for the Edit piece of the ComboBox control.`nNote that this tip is different than the drop-down button piece of this control. ) ToolTip(11,Tip,"","A" . EditComboBox_hWnd . " P" . GuiHwnd) ;-- Get hWnd to the Edit control piece of the ComboBox ControlGet ListViewHeader_hWnd,hWnd,,SysHeader321,Tooltip Test Tip= (ltrim join`s Tooltip for the header of the ListView control.`nNote that this tip is different than the rest of the ListView control. ) ToolTip(13,Tip,"","A" . ListViewHeader_hWnd . " P" . GuiHwnd) return Button1: ToolTip(1,"Button 1: New Text","","AButton1 P" . GuiHwnd) return Button2: ToolTip(2) return Button3: ToolTip() MsgBox 64,ToolTips Cleared,All Tooltips destroyed. %A_Space% return Null: return GUIClose: GUIescape: Gui,Destroy ExitApp Return
Code (Expand):
OnMessage(0x4e,"WM_NOTIFY") ;Will make LinkClick and ToolTipClose possible OnMessage(0x404,"AHK_NotifyTrayIcon") ;Will pop up the ToolTip when you click on Tray Icon OnExit, ExitApp #NoEnv #SingleInstance Force Restart: ToolTip(99,"Please click a link:`n`n" . "<a>My Favorite Websites</a>`n`n" . "<a>ToolTip Examples</a>`n`n" . "<a notepad.exe >Notepad</a>`n" . "<a explorer.exe >Explorer</a>`n" . "<a calc.exe >Calculator</a>`n" . "`n<a>Hide ToolTip</a>`n - To show this ToolTip again click onto Tray Icon" . "`n<a>ExitApp</a>`n" , "Welcome to ToolTip Control" , "L1 H1 O1 C1 T220 BLime FBlue I" . GetAssociatedIcon(A_ProgramFiles . "\Internet Explorer\iexplore.exe") . " P99 X" A_ScreenWidth . " Y" . A_ScreenHeight) Return My_Favorite_Websites: ToolTip(98,"<a http://www.autohotkey.com >AutoHotkey</a> - <a http://de.autohotkey.com>DE</a>" . " - <a http://autohotkey.free.fr/docs/>FR</a> - <a http://www.autohotkey.it/>IT</a>" . " - <a http://www.script-coding.info/AutoHotkeyTranslation.html>RU</a>" . " - <a http://lukewarm.s101.xrea.com/>JP</a>" . " - <a http://lukewarm.s101.xrea.com/>GR</a>" . " - <a http://www.autohotkey.com/docs/Tutorial-Portuguese.html>PT</a>" . " - <a http://cafe.naver.com/AutoHotKey>KR</a>" . " - <a http://forum.ahkbbs.cn/bbs.php>CN</a>" . "`n<a http://www.google.com>Google</a> - <a http://www.maps.google.com>Maps</a>`n" . "<a http://social.msdn.microsoft.com/Search/en-US/?Refinement=86&Query=>MSDN</a>`n" , "My Websites" , "L1 O1 C1 BSilver FBlue I" . GetAssociatedIcon(A_ProgramFiles . "\Internet Explorer\iexplore.exe") . " P99") Return ToolTip_Examples: ToolTip(97, "<a>Message Box ToolTip</a>`n" . "<a>Change ToolTip</a>`n" . "<a>ToolTip Loop #1</a>`n" . "<a>ToolTip Loop #2</a>`n" . "<a>ToolTip Loop #3</a>`n`nClose to return to previous ToolTip" , "ToolTip Examples" , "L1 O1 C1 BYellow FBlue I" . GetAssociatedIcon(A_ProgramFiles . "\Internet Explorer\iexplore.exe") . " P99") Return 99ToolTip: If InStr(link:=ErrorLevel,"http://") Run iexplore.exe %link% else if IsLabel(link:=RegExReplace(link,"[^\w\.]","_")) SetTimer % link,-150 else if link { Run % link SetTimer, Restart, -100 } Return 98ToolTip: Run iexplore.exe %ErrorLevel% Return 97ToolTip: IsLabel(ErrorLevel:=RegExReplace(ErrorLevel,"[^\w]","_")) SetTimer % ErrorLevel,-100 Return 99ToolTipClose: MsgBox,262148,Closing ToolTip..., ToolTip is about to close`nClick no to disable ToolTip`n -You can show it again by clicking onto the Tray Icon`nDo you want to exit script? IfMsgBox Yes ExitApp Return 97ToolTipClose: 98ToolTipClose: SetTimer, Restart, -100 Return WM_NOTIFY(wParam, lParam, msg, hWnd){ ToolTip("",lParam,"") } AHK_NotifyTrayIcon(wParam, lParam) { If (lparam = 0x201 or lparam = 0x202) SetTimer, Restart, -250 } Hide_ToolTip: ToolTip(99) Return Execute: Run %ErrorLevel%.exe SetTimer, Restart, -100 Return ExitApp: Loop, Parse, #_hIcons, | If A_LoopField DllCall("DestroyIcon",UInt,%A_LoopField%) ExitApp Return ToolTip_Loop__1: ToolTip(100,"`nJust an example ToolTip following mouse movements" ,"This ToolTip will be destroyed in " . 4 . " Seconds","o1 I" . GetAssociatedIcon(A_AhkPath) . " B0000FF FFFFFFF") Start:=A_TickCount end= While, end < 10 { ToolTip(100,"In this example text and Title are updated continuously.`nTickCount:" . A_TickCount,"This ToolTip will be destroyed in " . 11 - Round(end:=(A_TickCount-Start)/1000) . " Seconds","I" . GetAssociatedIcon(A_AhkPath)) } ToolTip(100) Return ToolTip_Loop__2: end= ToolTip(100,"In this example only position is tracked.","This ToolTip will be destroyed in 10 Seconds","D10 I" . GetAssociatedIcon(A_AhkPath) . " B0000FF FFFFFFF") ToolTip(100) Return ToolTip_Loop__3: end= ToolTip(100,"`nHere only title is being changed" ,"This ToolTip will be destroyed in 10 Seconds","I" . GetAssociatedIcon(A_AhkPath) . " B0000FF FFFFFFF") Start:=A_TickCount While, end < 10 { ToolTip(100,"","This ToolTip will be destroyed in " . 11 - Round(end:=(A_TickCount-Start)/1000) . " Seconds","I" . GetAssociatedIcon(A_AhkPath)) } ToolTip(100) Return Message_Box_Tooltip: SetTimer,proceed, -200 MsgBox,4,Test,Hallo,`nPoint onto yes or no proceed: hwnd:=WinExist("Test ahk_class #32770") ToolTip(101,"Click here to accept and proceed.","Here you see an example how to assign a ToolTip to MsgBox controls","I1 B00FF00 AButton1 P" . hwnd) ToolTip(101,"Click here to refuse and proceed","","AButton2 P" . hwnd) IfWinExist Test ahk_class #32770 { WinWaitClose, Test ahk_class #32770 Return } ToolTip(101) Return Change_ToolTip: Gui, Add,Button,,Point your mouse cursor here Gui,+LastFound ToolTip(1,"Test deleting and creating same Tooltip","TEST","Abutton1 P" . WinExist()) Gui,Show Sleep, 5000 ToolTip(1) Gui,Destroy Sleep, 1000 Gui, Add,Button,,Move your mouse cursor a little Gui,+LastFound ToolTip(1,"Test deleting and creating same Tooltip`nTooltips were destroyed and recreated.","New Tooltip with different text and title.","Abutton1 P" . WinExist()) Gui,Show Sleep, 5000 Gui,Destroy ToolTip(1) Return