 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Superfraggle
Joined: 02 Nov 2004 Posts: 846 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: 722 Location: Florida
|
Posted: Tue Apr 01, 2008 3:42 am Post subject: |
|
|
Groovy. _________________ [Join IRC!]
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 346 Location: Texas, USA
|
Posted: Tue Apr 01, 2008 5:59 am Post subject: |
|
|
Neato Bandito.  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 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: 110 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: 846 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: 110 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: 110 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: 846 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: 110 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: 846 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|