AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add ToolTips to controls.

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Superfraggle



Joined: 02 Nov 2004
Posts: 846
Location: London, UK

PostPosted: Tue Apr 01, 2008 1:48 am    Post subject: Add ToolTips to controls. Reply with quote

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
View user's profile Send private message MSN Messenger
Rhys



Joined: 17 Apr 2007
Posts: 722
Location: Florida

PostPosted: Tue Apr 01, 2008 3:42 am    Post subject: Reply with quote

Groovy.
_________________
[Join IRC!]
Back to top
View user's profile Send private message
jballi



Joined: 01 Oct 2005
Posts: 346
Location: Texas, USA

PostPosted: Tue Apr 01, 2008 5:59 am    Post subject: Reply with quote

Neato Bandito. Cool
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4015
Location: Pittsburgh

PostPosted: Tue Apr 01, 2008 1:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
haichen



Joined: 05 Feb 2007
Posts: 110
Location: Osnabrück, Germany

PostPosted: Tue Apr 01, 2008 2:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 846
Location: London, UK

PostPosted: Tue Apr 01, 2008 4:23 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
nouser
Guest





PostPosted: Wed Apr 02, 2008 6:09 am    Post subject: Reply with quote

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

PostPosted: Wed Apr 02, 2008 11:07 am    Post subject: Reply with quote

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
View user's profile Send private message
haichen



Joined: 05 Feb 2007
Posts: 110
Location: Osnabrück, Germany

PostPosted: Wed Apr 02, 2008 11:51 am    Post subject: Reply with quote

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
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 846
Location: London, UK

PostPosted: Wed Apr 02, 2008 1:24 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
haichen



Joined: 05 Feb 2007
Posts: 110
Location: Osnabrück, Germany

PostPosted: Wed Apr 02, 2008 1:57 pm    Post subject: Reply with quote

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!!
Very Happy
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 846
Location: London, UK

PostPosted: Wed Apr 02, 2008 2:21 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group