Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ToolTip() - Advanced ToolTip features + Unicode


  • Please log in to reply
130 replies to this topic

Poll: Do you think AutoHotkey should have that features/function internally? (26 member(s) have cast votes)

Do you think AutoHotkey should have that features/function internally?

  1. Yes (10 votes [38.46%])

    Percentage of vote: 38.46%

  2. Yes, even more ToolTip features please (10 votes [38.46%])

    Percentage of vote: 38.46%

  3. No, I don (0 votes [0.00%])

    Percentage of vote: 0.00%

  4. No, to complex to use (4 votes [15.38%])

    Percentage of vote: 15.38%

  5. No (2 votes [7.69%])

    Percentage of vote: 7.69%

Vote Guests cannot vote
HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

For AHK_L or AHK_H I reccomend to use TT().

Added Font option K
| K | Font. Specify the font for the tooltip. Separate options with a period "."
| | Valid options are bold,underline,italic,strikeout,sFONTSIZE,fFONTFACE
| | Limitations: FONTFACE cannot include spaces
| | Examples: Ks12.fArial , Kbold.italic.fVerdana


ToolTip.png

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)

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


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 (cool.png, TTM_SETTIPTEXTCOLOR (F), TTM_TRACKPOSITION (N+X+Y),
TTM_SETMAXTIPWIDTH ®, 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.
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
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
;-- 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
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

Functions and info:
/*
ToolTip() by HotKeyIt http://www.autohotkey.com/forum/viewtopic.php?t=40165
 
Syntax: ToolTip(Number,Text,Title,Options)
 
Return Value: ToolTip returns hWnd of the ToolTip
 
|         Options can include any of following parameters separated by space
| Option   |      Meaning
| 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 + 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. See ToolTip actions how Links for ToolTip work.
| 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 + 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
|
|          To destroy a ToolTip use ToolTip(Number), to destroy all ToolTip()
|
|               ToolTip Actions (NOTE, OPTION P MUST BE PRESENT TO USE THAT FEATURE)
|      Assigning an action to a ToolTip to works using OnMessage(0x4e,"Function") - WM_NOTIFY
|      Parameter/option P must be present so ToolTip will forward messages to script
|      All you need to do inside this OnMessage function is to include:
|         - If wParam=0
|            ToolTip("",lParam[,Label])
|
|      Additionally you need to have one or more of following labels in your script
|      - ToolTip: when clicking a link
|      - ToolTipClose: when closing ToolTip
|         - You can also have a diferent label for one or all ToolTips
|         - Therefore enter the number of ToolTip in front of the label
|            - e.g. 99ToolTip: or 1ToolTipClose:
|
|      - Those labels names can be customized as well
|         - e.g. ToolTip("",lParam,"MyTip") will use MyTip: and MyTipClose:
|         - you can enter the number of ToolTip in front of that label as well.
|
|      - Links have following syntax:
|         - <a>Link</a> or <a link>LinkName</a>
|         - When a Link is clicked, ToolTip() will jump to the label
|            - Variable ErrorLevel will contain clicked link
|
|         - So when only LinkName is given, e.g. <a>AutoHotkey</a> Errorlevel will be AutoHotkey
|         - When using Link is given as well, e.g. <a http://www.autohotkey.com>AutoHotkey</a>
|            - Errorlevel will be set to http://www.autohotkey.com
|
|      Please note some options like Close Button and Links will require Win2000++ (+version 6.0 of comctl32.dll)
|        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.
|           - Other options, like Title, color and so on, will be valid globally
*/
 
ToolTip(ID="",TEXT="",TITLE="",OPTIONS=""){
static
local option,a,b,c,d,e,f,g,h,i,k,l,m,n,o,p,q,r,s,t,v,w,x,y,xc,yc,xw,yw,RECT,_DetectHiddenWindows,OnMessage
If !Init
Gosub, TTM_INIT
OnMessage:=OnMessage(0x4e,"") ,_DetectHiddenWindows:=A_DetectHiddenWindows
DetectHiddenWindows, On
If !ID
{
If text
If text is Xdigit
GoTo, TTN_LINKCLICK
Loop, Parse, hWndArray, % Chr(2) ;Destroy all ToolTip Windows
{
If WinExist("ahk_id " . A_LoopField)
DllCall("DestroyWindow","Uint",A_LoopField)
hWndArray%A_LoopField%=
}
hWndArray=
Loop, Parse, idArray, % Chr(2) ;Destroy all ToolTip Structures
{
TT_ID:=A_LoopField
If TT_ALL_%TT_ID%
Gosub, TT_DESTROY
}
idArray=
Goto, TT_EXITFUNC
}
 
TT_ID:=ID
TT_HWND:=TT_HWND_%TT_ID%
 
;___________________  Load Options Variables and Structures ___________________
 
If (options){
Loop,Parse,options,%A_Space%
If (option:= SubStr(A_LoopField,1,1))
%option%:= SubStr(A_LoopField,2)
}
If (G){
If (Title!=""){
                        Gosub, TTM_SETTITLE
Gosub, TTM_UPDATE
}
If (Text!=""){
If (A!="")
ID:=A
If (InStr(text,"<a") and L){
TOOLTEXT_%TT_ID%:=text
text:=RegExReplace(text,"<a\K[^<]*?>",">")
} else
TOOLTEXT_%TT_ID%:=
NumPut(&text,TOOLINFO_%ID%,36)
Gosub, TTM_UPDATETIPTEXT
}
Loop, Parse,G,.
If IsLabel(A_LoopField)
Gosub, %A_LoopField%
Sleep,10
    Goto, TT_EXITFUNC
}
;__________________________  Save TOOLINFO Structures _________________________
 
If P {
If (p<100 and !WinExist("ahk_id " p)){
Gui,%p%:+LastFound
P:=WinExist()
}
If !InStr(TT_ALL_%TT_ID%,Chr(2) . Abs(P) . Chr(2))
TT_ALL_%TT_ID%  .= Chr(2) . Abs(P) . Chr(2)
} 
If !InStr(TT_ALL_%TT_ID%,Chr(2) . ID . Chr(2))
TT_ALL_%TT_ID%  .= Chr(2) . ID . Chr(2)
If H
TT_HIDE_%TT_ID%:=1
;__________________________  Create ToolTip Window  __________________________
 
If (!TT_HWND and text)
{
TT_HWND := DllCall("CreateWindowEx", "Uint", 0x8, "str", "tooltips_class32", "str", "", "Uint", 0x02 + (v ? 0x1 : 0) + (l ? 0x100 : 0) + (C ? 0x80 : 0)+(O ? 0x40 : 0), "int", 0x80000000, "int", 0x80000000, "int", 0x80000000, "int", 0x80000000, "Uint", P ? P : 0, "Uint", 0, "Uint", 0, "Uint", 0)
TT_HWND_%TT_ID%:=TT_HWND
hWndArray .=(hWndArray ? Chr(2) : "") . TT_HWND
idArray .=(idArray ? Chr(2) : "") . TT_ID
Gosub, TTM_SETMAXTIPWIDTH
DllCall("SendMessage", "Uint", TT_HWND, "Uint", 0x403, "Uint", 2, "Uint", (D ? D*1000 : -1)) ;TTDT_AUTOPOP
DllCall("SendMessage", "Uint", TT_HWND, "Uint", 0x403, "Uint", 3, "Uint", (W ? W*1000 : -1)) ;TTDT_INITIAL
DllCall("SendMessage", "Uint", TT_HWND, "Uint", 0x403, "Uint", 1, "Uint", (W ? W*1000 : -1)) ;TTDT_RESHOW
} else if (!text and !options){
DllCall("DestroyWindow","Uint",TT_HWND)
Gosub, TT_DESTROY
GoTo, TT_EXITFUNC
}
 
;______________________  Create TOOLINFO Structure  ______________________
 
Gosub, TT_SETTOOLINFO
 
If (Q!="")
Gosub, TTM_SETWINDOWTHEME
If (E!="")
Gosub, TTM_SETMARGIN
If (F!="")
Gosub, TTM_SETTIPTEXTCOLOR
If (B!="")
Gosub, TTM_SETTIPBKCOLOR
If (title!="")
Gosub, TTM_SETTITLE
 
If (!A){
Gosub, TTM_UPDATETIPTEXT
Gosub, TTM_UPDATE
If D {
A_Timer := A_TickCount, D *= 1000
Gosub, TTM_TRACKPOSITION
Gosub, TTM_TRACKACTIVATE
Loop
{
Gosub, TTM_TRACKPOSITION
If (A_TickCount - A_Timer > D)
Break
}
Gosub, TT_DESTROY
DllCall("DestroyWindow","Uint",TT_HWND)
TT_HWND_%TT_ID%=
} else {
Gosub, TTM_TRACKPOSITION
Gosub, TTM_TRACKACTIVATE
If T
WinSet,Transparent,%T%,ahk_id %TT_HWND%
If M
WinSet,ExStyle,^0x20,ahk_id %TT_HWND%
}
}
 
;________  Return HWND of ToolTip  ________
 
Gosub, TT_EXITFUNC
Return TT_HWND
 
;________________________  Internal Labels  ________________________
 
TT_EXITFUNC:
If OnMessage
OnMessage(0x4e,OnMessage)
DetectHiddenWindows, %_DetectHiddenWindows%
Return
TTM_POP:  ;Hide ToolTip
TTM_POPUP:  ;Causes the ToolTip to display at the coordinates of the last mouse message.
TTM_UPDATE: ;Forces the current tool to be redrawn.
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", 0)
Return
TTM_TRACKACTIVATE: ;Activates or deactivates a tracking ToolTip.
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", (N ? 0 : 1), "Uint", &TOOLINFO_%ID%)
Return
TTM_UPDATETIPTEXT:
TTM_GETBUBBLESIZE:
TTM_ADDTOOL:
TTM_DELTOOL:
TTM_SETTOOLINFO:
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", &TOOLINFO_%ID%)
Return
TTM_SETTITLE:
title := (StrLen(title) < 96) ? title : (Chr(133) SubStr(title, -97))
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", I, "Uint", &Title)
Return
TTM_SETWINDOWTHEME:
If Q
DllCall("uxtheme\SetWindowTheme", "Uint", TT_HWND, "Uint", 0, "UintP", 0)
else
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", &K)
Return
TTM_SETMAXTIPWIDTH:
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", R ? R : A_ScreenWidth)
Return
TTM_TRACKPOSITION:
VarSetCapacity(xc, 20, 0), xc := Chr(20)
DllCall("GetCursorInfo", "Uint", &xc)
yc := NumGet(xc,16), xc := NumGet(xc,12)
SysGet,xl,76
SysGet,xr,78
SysGet,yl,77
SysGet,yr,79
xc+=15,yc+=15
If (x="caret" or y="caret"){
WinGetPos,xw,yw,,,A
If x=caret
{
xc:=xw+A_CaretX +1
xc:=(xl>xc ? xl : (xr<xc ? xr : xc))
}
If (y="caret"){
yc:=yw+A_CaretY+15
yc:=(yl>yc ? yl : (yr<yc ? yr : yc))
}
} else if (x="TrayIcon" or y="TrayIcon"){
Process, Exist
PID:=ErrorLevel
hWndTray:=WinExist("ahk_class Shell_TrayWnd")
ControlGet,hWndToolBar,Hwnd,,ToolbarWindow321,ahk_id %hWndTray%
RemoteBuf_Open(TrayH,hWndToolBar,20)
DataH:=NumGet(TrayH,0)
SendMessage, 0x418,0,0,,ahk_id %hWndToolBar%
Loop % ErrorLevel
{
SendMessage,0x417,A_Index-1,RemoteBuf_Get(TrayH),,ahk_id %hWndToolBar%
RemoteBuf_Read(TrayH,lpData,20)
VarSetCapacity(dwExtraData,8)
pwData:=NumGet(lpData,12)
DllCall( "ReadProcessMemory", "uint", DataH, "uint", pwData, "uint", &dwExtraData, "uint", 8, "uint", 0 )
BWID:=NumGet(dwExtraData,0)
WinGet,BWPID,PID, ahk_id %BWID%
If (BWPID!=PID and BWPID!=#__MAIN_PID_)
continue
SendMessage, 0x41d,A_Index-1,RemoteBuf_Get(TrayH),,ahk_id %hWndToolBar%
RemoteBuf_Read(TrayH,rcPosition,20)
If (NumGet(lpData,8)>7){
ControlGetPos,xc,yc,xw,yw,Button2,ahk_id %hWndTray%
xc+=xw/2, yc+=yw/4
} else {
ControlGetPos,xc,yc,,,ToolbarWindow321,ahk_id %hWndTray%
halfsize:=NumGet(rcPosition,12)/2
xc+=NumGet(rcPosition,0)+ halfsize
yc+=NumGet(rcPosition,4)+ (halfsize/2)
}
WinGetPos,xw,yw,,,ahk_id %hWndTray%
xc+=xw,yc+=yw
break
}
RemoteBuf_close(TrayH)
}
If xc not between %xl% and %xr%
xc=xc<xl ? xl : xr
If yc not between %yl% and %yr%
yc=yc<yl ? yl : yr
If (!x and !y)
Gosub, TTM_UPDATE
else if !WinActive("ahk_id " . TT_HWND)
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", (x<9999999 ? x : xc & 0xFFFF)|(y<9999999 ? y : yc & 0xFFFF)<<16)
Return
TTM_SETTIPBKCOLOR:
If B is alpha
If (%b%)
B:=%b%
B := (StrLen(B) < 8 ? "0x" : "") . B
B := ((B&255)<<16)+(((B>>8)&255)<<8)+(B>>16) ; rgb -> bgr
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", B, "Uint", 0)
Return
TTM_SETTIPTEXTCOLOR:
If F is alpha
If (%F%)
F:=%f%
F := (StrLen(F) < 8 ? "0x" : "") . F
F := ((F&255)<<16)+(((F>>8)&255)<<8)+(F>>16) ; rgb -> bgr
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint",F & 0xFFFFFF, "Uint", 0)
Return
TTM_SETMARGIN:
VarSetCapacity(RECT,16)
Loop,Parse,E,.
NumPut(A_LoopField,RECT,(A_Index-1)*4)
DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", &RECT)
Return
TT_SETTOOLINFO:
If A {
If A is not Xdigit
ControlGet,A,Hwnd,,%A%,ahk_id %P%
ID :=Abs(A)
If !InStr(TT_ALL_%TT_ID%,Chr(2) . ID . Chr(2))
TT_ALL_%TT_ID%  .= Chr(2) . ID . Chr(2) . ID+Abs(P) . Chr(2)
If !TOOLINFO_%ID%
VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40)
else
Gosub, TTM_DELTOOL
Numput((N ? 0 : 1)|(J ? 2 : 0)|(L ? 0x1000 : 0)|16,TOOLINFO_%ID%,4),Numput(P,TOOLINFO_%ID%,8),Numput(ID,TOOLINFO_%ID%,12)
If (text!="")
NumPut(&text,TOOLINFO_%ID%,36)
Gosub, TTM_ADDTOOL
      ID :=ID+Abs(P)
If !TOOLINFO_%ID%
{
VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40)
Numput(0|16,TOOLINFO_%ID%,4), Numput(P,TOOLINFO_%ID%,8), Numput(P,TOOLINFO_%ID%,12)
}
Gosub, TTM_ADDTOOL
ID :=Abs(A)
} else {
If !TOOLINFO_%ID%
VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40)
If (text!=""){
If InStr(text,"<a"){
TOOLTEXT_%ID%:=text
text:=RegExReplace(text,"<a\K[^<]*?>",">")
} else
TOOLTEXT_%ID%:=
NumPut(&text,TOOLINFO_%ID%,36)
}
      NumPut((J ? 2 : 0)|(!(x . y) ? 0 : 0x20)|(S ? 0x80 : 0)|(L ? 0x1000 : 0),TOOLINFO_%ID%,4), Numput(P,TOOLINFO_%ID%,8), Numput(P,TOOLINFO_%ID%,12)
Gosub, TTM_ADDTOOL
}
    TOOLLINK%ID%:=L
  Return
TTN_LINKCLICK:
Loop 4
m += *(text + 8 + A_Index-1) << 8*(A_Index-1)
If !(TTN_FIRST-2=m or TTN_FIRST-3=m or TTN_FIRST-1=m)
Return, OnMessage ? OnMessage(0x4e,OnMessage) : 0
Loop 4
p += *(text + 0 + A_Index-1) << 8*(A_Index-1)
If (TTN_FIRST-3=m)
Loop 4
option += *(text + 16 + A_Index-1) << 8*(A_Index-1)
Loop,Parse,hWndArray,% Chr(2)
If (p=A_LoopField and i:=A_Index)
break
Loop,Parse,idArray,% Chr(2)
{
If (i=A_Index){
If (TTN_FIRST-1=m){
Loop 4
ErrorLevel += *(text + 4 + A_Index-1) << 8*(A_Index-1)
Return A_LoopField, OnMessage ? OnMessage(0x4e,OnMessage) : 0
}
text:=TOOLTEXT_%A_LoopField%
If (TTN_FIRST-2=m){
If Title
{
If IsLabel(A_LoopField . title . "Close")
Gosub % A_LoopField . title . "Close"
else If IsLabel(title . "Close")
Gosub % title . "Close"
} else {
If IsLabel(A_LoopField . A_ThisFunc . "Close")
Gosub % A_LoopField . A_ThisFunc . "Close"
else If IsLabel(A_ThisFunc . "Close")
Gosub % A_ThisFunc . "Close"
}
} else If (InStr(TOOLTEXT_%A_LoopField%,"<a")){
Loop % option+1
StringTrimLeft,text,text,% InStr(text,"<a")+1
If TT_HIDE_%A_LoopField%
%A_ThisFunc%(A_LoopField,"","","gTTM_POP")
If ((a:=A_AutoTrim)="Off")
AutoTrim, On
ErrorLevel:=SubStr(text,1,InStr(text,">")-1)
StringTrimLeft,text,text,% InStr(text,">")
text:=SubStr(text,1,InStr(text,"</a>")-1)
If !ErrorLevel
ErrorLevel:=text
ErrorLevel=%ErrorLevel%
AutoTrim, %a%
If Title
{
If IsFunc(f:=(A_LoopField . title))
%f%(ErrorLevel)
else if IsLabel(A_LoopField . title)
Gosub % A_LoopField . title
else if IsFunc(title)
%title%(ErrorLevel)
else If IsLabel(title)
Gosub, %title%
} else {
if IsFunc(f:=(A_LoopField . A_ThisFunc))
%f%(ErrorLevel)
else If IsLabel(A_LoopField . A_ThisFunc)
Gosub % A_LoopField . A_ThisFunc
else If IsLabel(A_ThisFunc)
Gosub % A_ThisFunc
}
}
break
}
}
DetectHiddenWindows, %_DetectHiddenWindows%
Return OnMessage ? OnMessage(0x4e,OnMessage) : 0
TT_DESTROY:
Loop, Parse, TT_ALL_%TT_ID%,% Chr(2)
If A_LoopField
{
ID:=A_LoopField
Gosub, TTM_DELTOOL
TOOLINFO_%A_LoopField%:="", TT_HWND_%A_LoopField%:="", TOOLTEXT_%A_LoopField%:="", TT_HIDE_%A_LoopField%:="",TOOLLINK%A_LoopField%:=""
}
TT_ALL_%TT_ID%=
Return
 
TTM_INIT:
Init:=1
; Messages
TTM_ACTIVATE := 0x400 + 1, TTM_ADDTOOL := A_IsUnicode ? 0x432 : 0x404, TTM_DELTOOL := A_IsUnicode ? 0x433 : 0x405
,TTM_POP := 0x41c, TTM_POPUP := 0x422, TTM_UPDATETIPTEXT := 0x400 + (A_IsUnicode ? 57 : 12)
,TTM_UPDATE := 0x400 + 29, TTM_SETTOOLINFO := 0x409, TTM_SETTITLE := 0x400 + (A_IsUnicode ? 33 : 32)
,TTN_FIRST := 0xfffffdf8, TTM_TRACKACTIVATE := 0x400 + 17, TTM_TRACKPOSITION := 0x400 + 18
,TTM_SETMARGIN:=0x41a, TTM_SETWINDOWTHEME:=0x200b, TTM_SETMAXTIPWIDTH:=0x418,TTM_GETBUBBLESIZE:=0x41e
,TTM_SETTIPBKCOLOR:=0x413, TTM_SETTIPTEXTCOLOR:=0x414
;Colors
,Black:=0x000000, Green:=0x008000,Silver:=0xC0C0C0
,Lime:=0x00FF00, Gray:=0x808080, Olive:=0x808000
,White:=0xFFFFFF, Yellow:=0xFFFF00, Maroon:=0x800000
,Navy:=0x000080, Red:=0xFF0000, Blue:=0x0000FF
,Purple:=0x800080, Teal:=0x008080, Fuchsia:=0xFF00FF
   ,Aqua:=0x00FFFF
Return
}
 
MI_ExtractIcon(Filename, IconNumber, IconSize)
{
If A_OSVersion in WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
{
 DllCall("PrivateExtractIcons", "Str", Filename, "Int", IconNumber-1, "Int", IconSize, "Int", IconSize, "UInt*", hIcon, "UInt*", 0, "UInt", 1, "UInt", 0, "Int")
If !ErrorLevel
Return hIcon
}
If DllCall("shell32.dll\ExtractIconExA", "Str", Filename, "Int", IconNumber-1, "UInt*", hIcon, "UInt*", hIcon_Small, "UInt", 1)
{
SysGet, SmallIconSize, 49
 
If (IconSize <= SmallIconSize) {
DllCall("DeStroyIcon", "UInt", hIcon)
hIcon := hIcon_Small
}
 Else
DllCall("DeStroyIcon", "UInt", hIcon_Small)
 
If (hIcon && IconSize)
hIcon := DllCall("CopyImage", "UInt", hIcon, "UInt", 1, "Int", IconSize, "Int", IconSize, "UInt", 4|8)
}
Return, hIcon ? hIcon : 0
}
GetAssociatedIcon(File){
   static
   sfi_size:=352
   local Ext,Fileto,FileIcon,FileIcon#
   If !File
      Loop, Parse, #_hIcons, |
         If A_LoopField
            DllCall("DestroyIcon",UInt,A_LoopField)
   If not sfi
      VarSetCapacity(sfi, sfi_size)
   SplitPath, File,,, Ext
If !Ext
Return
   else if Ext in EXE,ICO,ANI,CUR,LNK
   {
      If ext=LNK
      {
         FileGetShortcut,%File%,Fileto,,,,FileIcon,FileIcon#
         File:=!FileIcon ? FileTo : FileIcon
      }
      SplitPath, File,,, Ext
      hIcon%Ext%:=MI_ExtractIcon(file,FileIcon# ? FileIcon# : 1,32)
   } else If (!hIcon%Ext% or !InStr(hIcons,"|" . hIcon%Ext% . "|")){
      If DllCall("Shell32\SHGetFileInfoA", "str", File, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101){
         Loop 4
            hIcon%Ext% += *(&sfi + A_Index-1) << 8*(A_Index-1)
      }
      hIcons .= "|" . hIcon%Ext% . "|"
   }
   return hIcon%Ext%
}


jmanx
  • Members
  • 110 posts
  • Last active: Mar 20 2011 07:55 PM
  • Joined: 14 May 2008

It would be really nice if we could make the tooltip a child window of a gui



HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
If I find some time I will try to transform :wink:

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
Very nice function, but the colors don't seem to work for me. Just trying your example, I get only plain white backgrounds with black text.

I am on Vista SP1, has this function been tested on Vista yet?

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Very nice function, but the colors don't seem to work for me. Just trying your example, I get only plain white backgrounds with black text.

I am on Vista SP1, has this function been tested on Vista yet?


I don't have vista so can't test, does DerRaphaels sToolTip work for you?

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
sTooltip is known not to work on vista

All scripts, unless otherwise noted, are hereby released under CC-BY

Yook
  • Members
  • 76 posts
  • Last active: Sep 23 2011 01:49 PM
  • Joined: 20 Nov 2008
Hi!

Nice feature.
I have a question : is it possible to have a tooltip displaying unicode? Or will I need (if this is possible) to create it from scratch using MSDN library? The tooltips don't seem to use standard controls, so I can't find out how to change the text with a SendMessageW. What's more, I don't know if its size would be updated if that worked. I can't find anything relevant on MSDN website : tooltips seem to be only usable for controls.

For now, I rely on a (unreliable diy) graphical method to resize a text control in which I inserted unicode text.
I have been looking for another method for a while...

Thanks in advance for your help.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
You could try to change following line in above fuction and try to display your unicode text in title, ToolTip(1,"some text","some unicode text",2,"","","","",3).
Cange it from:
SendMessage, 0x400+32, icon,&title,,% "ahk_id " . _tt_hwnd_list_%_tool_tip_id_%
to:
SendMessage, 0x400+3[color=Red]3[/color], icon,&title,,% "ahk_id " . _tt_hwnd_list_%_tool_tip_id_%

TTM_SETTITLE = 0x400 + (IsUnicode ? 33 : 32)


Does this help?

Yook
  • Members
  • 76 posts
  • Last active: Sep 23 2011 01:49 PM
  • Joined: 20 Nov 2008
Thanks for your reply !

It works, I inserted into the function some lines converting the title string to UTF16 and did as you said.
But the size of the title seems to be limited to 99 characters (it remains 99 with utf-16). Plus, the title is not multiline. This is interesting to know, though !

Isn't there a similar message that sets the body's text?

Here is the part I changed. The title parameter can receive a normal string or UTF-8 string as well (e.g. clipboard's unicode content retrieved with Transform) :
If title
{
      ;title := (StrLen(title) <= 99) ? title : (SubStr(title, -97) "…") 
      ;StrLen doesn't work for UTF-16 and UTF-8 uses variable size, so we cannot predict the length of the string.
      ;65001 is UTF-8. ASCII is also correctly converted, though.
      ;Size of the string
      nSize := DllCall("MultiByteToWideChar", "Uint", 65001, "Uint", 0, "Uint", &title, "int",  -1, "Uint", 0, "int",  0)
      VarSetCapacity(U16title, nSize * 2)
      DllCall("MultiByteToWideChar", "Uint", 65001, "Uint", 0, "Uint", &title, "int",  -1, "Uint", &U16title, "int",  nSize)
      ;We cut the string at the proper size by writing an end char in memory.
      If (nSize>100) ;100=string+end char
	        NumPut(0x2026, &U16title+196, "UInt") ;2026 is "…" .UInt is 32bits. The remaining bits will be filled with 0, creating the end char.
      SendMessage, 0x400+33, icon,&U16title,,% "ahk_id " . _tt_hwnd_list_%_tool_tip_id_%
}

A few remarks :

- Isn't this part redundant ?
If StrLen(title)>99
      {
         StringRight, title, title, 96
         title := "..." . title
      }
      title := (StrLen(title) < 96) ? title : ("..." . SubStr(title, -96))
You can change it to :
title := (StrLen(title) <= 99) ? title : (SubStr(title, -95) "...")
or even :
title := (StrLen(title) <= 99) ? title : (SubStr(title, -97) "…")

- You could use the extended style E0x20 to make the tooltip behave as if it wasn't there (clicks go through it), it could be useful especially with some transparency, and you don't need to disable the window (for the moment it makes "BUH!" when I click on it :D ).

- Transparency off and transparency at 255 are not the same. I am not sure, but I guess the system would perform better if transparency was off instead of at 255 (but if E0x20 is used, it is better not to put off transparency, or it might not repaint correctly).

Btw, 000000 as a background color displays white instead of black (000001 displays "almost black", though :) )

Regards

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Thanks Yook, I changed the exstyle and redundand part.
Alse several ToolTips should be handled now correct.
I will check why color is wrong.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Color is working now, 000000 was interpreted as false so it was not set.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Check out the new ToolTip function.
Many thanks to Sean for BalloonTip

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Update:
- Sometimes when using A_Caret and BallonTip ToolTip was shown very much outside of the screen and the script hanged for a few minutes.

However this should be fixed now.




Posted: Fri Jan 23, 2009 12:12 am Post subject:
It would be really nice if we could make the tooltip a child window of a gui

Here an example
CoordMode,Mouse,Screen
Gui,Add,Text
Gui,Show,w800 h600,GUI
Gui,+LastFound
hwnd:=WinExist()
tthwnd:=ToolTip(1,"Hallo","test","I1 X400 Y400")
DllCall("SetParent", "uint", tthwnd, "uint", hwnd)
OnMessage(0x200,"Show")
Return
2GuiClose:
GuiClose:
ExitApp

Show(wParam,lParam){
	ToolTip(1,"Parameter passed`nwParam: " wParam "`nlParam: " lParam,"Test","I1")
}


Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Oddity on my system: even with O1 set, it still displays regular rectangle tip unless a delay is also set in options :!:

When rectangle tip is set, the position follows mouse cursor correctly; when balloon is set, it appears somewhere to the middle-left of the cursor, but the balloon anchor is somewhere at the top-left of it.

Oh and the balloon flickers, while another small balloon-looking white ellipse quickly flashes at screen 0x0.

I wonder why balloon tip shows at all, considering Win98SE wasn't supposed to have it; must be one of my upgrades... 8)

The CoordMode,Mouse,Screen in the example shifts the tooltip down-right - should be removed.

I wonder if there's any way to hook all tooltip calls in the system and redirect them to this control... :?:

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Oddity on my system: even with O1 set, it still displays regular rectangle tip unless a delay is also set in options :!:

When rectangle tip is set, the position follows mouse cursor correctly; when balloon is set, it appears somewhere to the middle-left of the cursor, but the balloon anchor is somewhere at the top-left of it.

I will check on 98 SE and see what I get.

Oh and the balloon flickers, while another small balloon-looking white ellipse quickly flashes at screen 0x0.

This is when ToolTip is being created, have not found a way to get rid of that :?

I wonder why balloon tip shows at all, considering Win98SE wasn't supposed to have it; must be one of my upgrades... 8)

I'll check on my 98SE and see what it'll does there.

The CoordMode,Mouse,Screen in the example shifts the tooltip down-right - should be removed.

Why? It will not display correctly as it needs Screen coordinates?

I wonder if there's any way to hook all tooltip calls in the system and redirect them to this control... :?:


I do not think so, I could possibly include another parameter to SetParent automatically by specifying Wn (n would be ID or PID or CLASS), would this help?