AutoHotkey Community

It is currently May 26th, 2012, 5:05 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: April 1st, 2008, 1:48 am 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2008, 3:42 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
Groovy.

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2008, 5:59 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 774
Location: Texas, USA
Neato Bandito. 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2008, 1:57 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Nice! Could you put in some comments about the names of the messages and the magic parameters? It would make changing the code easier.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2008, 2:35 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2008, 4:23 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2008, 6:09 am 
Of course it works for static controls. Just add a "null" g-label:
Code:
Gui,Add,TEXT,hwndTEXT1 gNULL,Testing for static.
...
...

NULL:
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2008, 11:07 am 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2008, 11:51 am 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2008, 1:24 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2008, 1:57 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
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!!
:D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2008, 2:21 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 6th, 2009, 11:20 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 774
Location: Texas, USA
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



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2009, 11:47 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 774
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2009, 9:12 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Check out new ToolTip() Options, many thanks Superfraggle ;)

ToolTip() - Advanced ToolTip Features

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], MSNbot Media and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group