 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Superfraggle
Joined: 02 Nov 2004 Posts: 1017 Location: London, UK
|
Posted: Tue Apr 01, 2008 1:48 am Post subject: Add ToolTips to controls. |
|
|
Just a simple add on to allow tooltips to be added to controls without having to monitor the wm_mousemove messages.
| Code: |
; ### Example Code #####
Gui,Add,Button,hwndbutton1 Gbut1,Test Button 1
Gui,Add,Button,hwndbutton2,Test Button 2
Gui,Add,Button,hwndbutton3,Test Button 3
AddTooltip(button1,"Press me to change my tooltip")
AddTooltip(button2," Another Test Tooltip")
AddTooltip(button3,"A Multiline`nTest Tooltip")
Gui,show,,Test Gui
Return
But1:
AddTooltip(button1,"Wasn't that easy `;)",1)
REturn
GuiClose:
Guiescape:
Exitapp
; ### End Example Code #####
AddToolTip(con,text,Modify = 0){
Static TThwnd,GuiHwnd
If (!TThwnd){
Gui,+LastFound
GuiHwnd:=WinExist()
TThwnd:=CreateTooltipControl(GuiHwnd)
}
Varsetcapacity(TInfo,44,0)
Numput(44,TInfo)
Numput(1|16,TInfo,4)
Numput(GuiHwnd,TInfo,8)
Numput(con,TInfo,12)
Numput(&text,TInfo,36)
Detecthiddenwindows,on
If (Modify){
SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
}
Else {
Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
SendMessage,1048,0,300,,ahk_id %TThwnd%
}
}
CreateTooltipControl(hwind){
Ret:=DllCall("CreateWindowEx"
,"Uint",0
,"Str","TOOLTIPS_CLASS32"
,"Uint",0
,"Uint",2147483648 | 3
,"Uint",-2147483648
,"Uint",-2147483648
,"Uint",-2147483648
,"Uint",-2147483648
,"Uint",hwind
,"Uint",0
,"Uint",0
,"Uint",0)
Return Ret
} |
You need to send the function the hwnd of the control, and the text you want it to say. If you are changing a tooltip, then specify a 1 for the last parameter.
As always, comments, bugs, questions, suggestions etc.... all welcome. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
Rhys
Joined: 17 Apr 2007 Posts: 758 Location: Florida
|
Posted: Tue Apr 01, 2008 3:42 am Post subject: |
|
|
Groovy. _________________ [Join IRC!]
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 446 Location: Texas, USA
|
Posted: Tue Apr 01, 2008 5:59 am Post subject: |
|
|
Neato Bandito.  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4425 Location: Pittsburgh
|
Posted: Tue Apr 01, 2008 1:57 pm Post subject: |
|
|
| Nice! Could you put in some comments about the names of the messages and the magic parameters? It would make changing the code easier. |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 156 Location: Osnabrück, Germany
|
Posted: Tue Apr 01, 2008 2:35 pm Post subject: |
|
|
Yes, its nice and could be pretty helpful.
But at the moment it seems to work only with buttons.
Can the script also work with other controls? |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 1017 Location: London, UK
|
Posted: Tue Apr 01, 2008 4:23 pm Post subject: |
|
|
So far i've tested on Tabs,Edits,buttons,checkboxes and text (static).
Only text failed so far, and im struggling to find anydocumentation in MSDN to say it doesnt work with any type. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
nouser Guest
|
Posted: Wed Apr 02, 2008 6:09 am Post subject: |
|
|
Of course it works for static controls. Just add a "null" g-label:
| Code: | Gui,Add,TEXT,hwndTEXT1 gNULL,Testing for static.
...
...
NULL:
Return
|
|
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 156 Location: Osnabrück, Germany
|
Posted: Wed Apr 02, 2008 11:07 am Post subject: |
|
|
Wonderful!
I tested it with gLabel, but there was a misspelling....sorry.
I've a question to the dllcall of CreateWindowEx. After seaching I found some VBA code for ToolTip. From that I made the following:
| Code: | CreateTooltipControl(hwind){
Ret:=DllCall("CreateWindowEx"
,"Uint",0
,"Str","TOOLTIPS_CLASS32"
,"Str",""
,"Uint",0|3
,"Uint",0
,"Uint",0
,"Uint",0
,"Uint",0
,"Uint",hwind
,"Uint",0
,"Uint",0
,"Uint",0)
Return Ret
} |
This also works. My Question: Is there a reason for the other function call?
And as a second: where does the Msg numbers come from? In google I found some code with this numbers, that have to do with slider range and toolbarbuttons. |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 156 Location: Osnabrück, Germany
|
Posted: Wed Apr 02, 2008 11:51 am Post subject: |
|
|
When a Tooltip is changed from another Window, the ToolTip is not updated.
Changing | Code: | If (Modify){
SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
}
Else {
Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
SendMessage,1048,0,300,,ahk_id %TThwnd%
} |
to | Code: | If (Modify)
SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
Else
SendMessage, 1028,0,&TInfo,,ahk_id %TThwnd%
SendMessage,1048,0,300,,ahk_id %TThwnd% |
helps. |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 1017 Location: London, UK
|
Posted: Wed Apr 02, 2008 1:24 pm Post subject: |
|
|
| Quote: | This also works. My Question: Is there a reason for the other function call?
And as a second: where does the Msg numbers come from? In google I found some code with this numbers, that have to do with slider range and toolbarbuttons. |
The first function call(createwindow) creates a tooltip control, this is required to store/create/show/hide the tool tips, this is only needed once. We then add the tool tips to the control, they can be attached to either controls or areas, at present only controls are supported.
The messages are
TTM_ADDTOOL = 1028 (used to add a tool, and assign it to a control)
TTM_UPDATETIPTEXT = 1036 (used to adjust the text of a tip)
TTM_SETMAXTIPWIDTH = 1048 (This one allows the use of multiline tooltips.)
| Quote: | | When a Tooltip is changed from another Window, the ToolTip is not updated. |
I am unable to replicate this, they change fine in all my tests. And unless I am missing something I can't see how the changes would fix it.
All you are doing is sending the maxwidth message everytime, instead of only during an add, I'll take a proper look later. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 156 Location: Osnabrück, Germany
|
Posted: Wed Apr 02, 2008 1:57 pm Post subject: |
|
|
In the first part of my question I wanted to know, if you can explain the found
differences like
| Quote: | ,"Str","TOOLTIPS_CLASS32"
,"Str",""
,"Uint",0|3
,"Uint",0 |
| Quote: | ,"Str","TOOLTIPS_CLASS32"
,"Uint",0
,"Uint",2147483648 | 3 |
especially I want to know if my found version is wrong, or if both are right.
I tried a short script to test my update-problem. You're right, it works well.
I have scripted a longer program where I can change the language on the fly over two windows. There it works only with the above changes. So it seems to be a problem with my program. [EDIT] I found the problem and fixed it. I had a try with onmessage before. I deleted this and now your code worked as it should.
Thanks for your answer and this wonderful function!!
 |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 1017 Location: London, UK
|
Posted: Wed Apr 02, 2008 2:21 pm Post subject: |
|
|
The number in mine stands for WS_POPUP which is one of the window styles that MSDN has in its example.
As to the str and Uint differences. Officially it should be an str, but as I am sending null I believe this does not matter. (Although I could be mistaken.) _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 446 Location: Texas, USA
|
Posted: Wed May 06, 2009 11:20 pm Post subject: |
|
|
I just started to play with this script again after letting sit on the shelf for a few weeks. I created an extended version of the sample script provided by Superfraggle. Hopefully, someone will find it of use. Instructions included in the script:
| Code: | ;-- Note. To get this script to work, you'll need to add (or include) the
; AddTooltip and CreateTooltipControl functions from the first post to the
; bottom of this script. For the picture example, copy any picture file (jpg,
; bmp, etc.) to the same directory as this script and name it "picture.bmp".
#NoEnv
gui -MinimizeBox
gui Add,Button,w150 hwndbutton1 gbut1,Test Button 1
AddTooltip(button1,"Button 1: Press me to change my tooltip")
gui Add,Button,y+0 w150 hwndbutton2 gbut2,Test Button 2
AddTooltip(button2,"Button 2: Press me to turn off the tooltip for this button")
gui Add,Button,y+0 w150 hwndbutton3,Test Button 3
AddTooltip(button3,"A Multiline Test Tooltip`n2nd line`n3rd line`n4th line")
gui Add,Checkbox,w150 hwndCheckbox_hWnd,Checkbox Control
AddTooltip(Checkbox_hWnd,"Tooltip for the Checkbox control")
gui Add,Radio,w150 hwndRadio_hWnd,Radio Control
AddTooltip(Radio_hWnd,"Tooltip for the Radio control")
gui Add,Edit,w150 hwndEdit_hWnd,Edit Control
AddTooltip(Edit_hWnd,"Tooltip for the Edit control")
gui Add,Text,w150 hwndText_hWnd gNull,Text Control
Tip=
(ltrim join`s
Tooltip for the Text control. Note that the Tooltip for a Text control does
not show unless a g-label for the control is defined.
)
AddTooltip(Text_hWnd,Tip)
gui Add,Picture,w150 h100 hwndPicture_hWnd gnull,Picture.bmp
Tip=
(ltrim join`s
Tooltip for the Picture control. Note that the Tooltip for a Picture
control does not show unless a g-label for the control is defined.
)
AddTooltip(Picture_hWnd,Tip)
gui Add,DropDownList,w150 r3 hwndDropDownList_hWnd,DropDownList Control||2|3
AddTooltip(DropDownList_hWnd,"Tooltip for the DropDownList control")
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. Note that
this tip is different than the Edit piece of the control.
)
AddTooltip(ComboBox_hWnd,Tip)
gui Add,ListBox,w150 r3 hwndListBox_hWnd,ListBox Control||2|3
AddTooltip(ListBox_hWnd,"Tooltip for the ListBox control")
gui Add,ListView,w150 h50 hwndListView_hWnd,ListView Control
Tip=
(ltrim join`s
Tooltip for the ListView control. Note that this tip is different than
the header piece of the control.
)
AddTooltip(ListView_hWnd,Tip)
gui Add,DateTime,w150 hwndDateTime_hWnd ;,DateTime Control
AddTooltip(DateTime_hWnd,"Tooltip for the DateTime control")
;-- Uncomment this if you want to see the MonthCal control. Works the same as DateTime
;;;;;gui Add,MonthCal,w150 hwndMonthCal_hWnd ;,MonthCal Control
;;;;;AddTooltip(MonthCal_hWnd,"Tooltip for the MonthCal control")
gui Add,Progress,w150 hwndProgress_hWnd,65 ;Progress Control
AddTooltip(Progress_hWnd,"Tooltip for the Progress control")
gui Add,Slider,w150 hwndSlider_hWnd,45 ;Slider Control
AddTooltip(Slider_hWnd,"Tooltip for the Slider control")
gui Add,Hotkey,w150 hwndHotkey_hWnd,45 ;Hotkey Control
AddTooltip(Hotkey_hWnd,"Tooltip for the Hotkey control")
gui Add,Edit,w150 h20 hwndEdit2_hWnd,Dummy Edit Control ;-- Used by UpDown control
Tip=
(ltrim join`s
This Edit control was created so that the attached UpDown control could be
demonstrated.
)
AddTooltip(Edit2_hWnd,Tip)
gui Add,UpDown,hwndUpDown_hWnd Range 1-10,5
AddTooltip(UpDown_hWnd,"Tooltip for the UpDown control")
gui Show,,Tooltip Test
;-- 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. Note that this tip is
different than the rest of the ListView control.
)
AddTooltip(ListViewHeader_hWnd,Tip)
;-- 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. Note that this tip is
different than the drop-down button piece of this control.
)
AddTooltip(EditComboBox_hWnd,Tip)
return
But1:
AddTooltip(button1,"Wasn't that easy `;)",true)
return
But2:
AddTooltip(button2,"",true)
return
Null:
return
GUIClose:
GUIescape:
ExitApp
;-- Copy the AddTooltip and CreateTooltipControl functions from the 1st post
; here. The original post can be found here:
; http://www.autohotkey.com/forum/viewtopic.php?t=30300
|
|
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 446 Location: Texas, USA
|
Posted: Thu May 07, 2009 11:47 pm Post subject: |
|
|
Found one tiny bug. The function indiscriminately sets DetectHiddenWindows to On. The function needs to set DetectHiddenWindows to what it was before returning. Something like:
| Code: | l_DetectHiddenWindows:=A_DetectHiddenWindows
Detecthiddenwindows,on
If (Modify){
SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
}
Else {
Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
SendMessage,1048,0,300,,ahk_id %TThwnd%
}
DetectHiddenWindows %l_DetectHiddenWindows% |
I hope this helps. |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 1088 Location: GERMANY
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|