 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Micahs
Joined: 01 Dec 2006 Posts: 413
|
Posted: Sat Apr 11, 2009 12:15 pm Post subject: tooltip.ahk version 2 |
|
|
I threatened to do this a long time ago, but forgot till now. This is an updated version of the tooltip script from this thread.
I've improved it so that setting a tooltip is even easier.
| Code: | ;Just supply text, variable, classnn, or hwnd and the text for the tip:
setTip("Button1", "This button does absolutely nothing.") ;using the classnn
setTip("Ok", "Begin the Process") ;using the caption
setTip("Cancel", "Cancel Whatever is Happening!")
setTip(DDL, "Dropdownlist") ;using the variable
setTip(MYEdit, "The infamous edit control") ;using the hwnd |
To clear a tip for a certain control, just call it again without text:
| Code: | | setTip("Ok", "") ;this clears the tip |
To change the tip for a control, call it again with different text:
| Code: | | setTip("Ok", "New text for the tip") ;this updates the tip text |
Tooltips are enabled by default. To disable tooltips at any time, call:
| Code: | TipsState(0) ;disable tooltips
TipsState(1) ;enable tooltips again |
The standard version tooltips uses standard windows tooltips.
tooltipV2.ahk >>Standard Version Download<<
Standard Version Demo:
| Code: | ;*************gui1*********************
Gui, Add, Button,,Click to do nothing
Gui, Add, DropDownList,vDDL,red|blue|green||
Gui, Add, Checkbox,, Click to enable
Gui, Add, Edit, HwndMYEdit,This is an edit box
Gui, Add, Button,, Ok
Gui, Add, Button, x+ yp, Cancel
Gui, Add, Button, x+ yp, Retry
Gui, Show,x200
;set tooltips for each button - supply text, variable, classnn, or hwnd
setTip("Button1", "This button does absolutely nothing.") ;using the classnn
setTip("Ok", "Begin the Process") ;using the caption
setTip("Cancel", "Cancel Whatever is Happening!")
setTip("Retry", "Do Over")
setTip("Click to enable", "Checkbox")
setTip(DDL, "Dropdownlist") ;using the variable
setTip(MYEdit, "The infamous edit control") ;using the hwnd
;*************gui2*********************
Gui, 2:Add, Button,,Click to do nothing
Gui, 2:Add, DropDownList,vDDL2,red|blue|green||
Gui, 2:Add, Checkbox,, Click to enable
Gui, 2:Add, Edit, HwndMYEdit2,This is edit box two
Gui, 2:Add, Button,, Ok
Gui, 2:Add, Button, x+ yp, Cancel
Gui, 2:Add, Button, x+ yp, Retry
Gui, 2:Show,x400
;set tooltips for each button - supply text, variable, classnn, or hwnd
setTip("Button1", "This button does absolutely nothing. gui2", 2) ;using the classnn
setTip("Ok", "Begin the Process gui2", 2) ;using the caption
setTip("Cancel", "Cancel Whatever is Happening! gui2", 2)
setTip("Retry", "Do Over gui2", 2)
setTip("Click to enable", "Checkbox gui2", 2)
setTip(DDL2, "Dropdownlist part two: This time it's personal", 2) ;using the variable
setTip(MYEdit2, "The infamous edit control redeux", 2) ;using the hwnd
;TipsState(0) ;disable tooltips
Return
#Include tooltipV2.ahk
2guiClose:
guiClose:
ExitApp
Return
|
Alternate version allows use of an image and custom text and background colors. (Can also mimic standard windows tooltips.)
tooltipV2a.ahk >>Alternate Version Download<<
See the comments in tooltipV2a.ahk for version specific usage instructions.
Alternate Version Demo:
| Code: | ;*************gui1*********************
Gui, Add, Button,,Click to do nothing
Gui, Add, DropDownList,vDDL,red|blue|green||
Gui, Add, Checkbox,, Click to enable
Gui, Add, Edit, HwndMYEdit,This is an edit box
Gui, Add, Button,, Ok
Gui, Add, Button, x+ yp, Cancel
Gui, Add, Button, x+ yp, Retry
Gui, Show,x200
setTip_Defaults("", "FontArial s15 C0xAA0000 BGC0xFF9B9B", "shell32.dll", "Icon24")
;set tooltips for each button - supply text, variable, classnn, or hwnd
setTip("Ok", "Why would you ever need a tooltip that looks like this?", "", "", "", "Icon24") ;imgoptions are "x, y, icon, altsubmit, ..." ;using the classnn
setTip("Retry", "Maybe do something again.", "", "", "", "Icon147") ;use imgOptions to set a different icon
setTip("Cancel", " ", "", "", "", "Icon132") ;use imgOptions to set a different icon
setTip("Click to enable", "Click to do something.", "", "", " ") ;use blank imgPath to show no icon if default already set
setTip(MYEdit, "The infamous edit control", "", "", " ") ;use blank imgPath to show no icon if default already set
setTip(DDL, "Dropdownlist: for to drop down lists") ;icon not given, using default
setTip("Button1", "This button does absolutely nothing.", "", "", "", "Icon222") ;Change to diff icon again
;*************gui2*********************
Gui, 2:Add, Button,,Click to do nothing
Gui, 2:Add, DropDownList,vDDL2,red|blue|green||
Gui, 2:Add, Checkbox,, Click to enable
Gui, 2:Add, Edit, HwndMYEdit2,This is edit box two
Gui, 2:Add, Button,, Ok
Gui, 2:Add, Button, x+ yp, Cancel
Gui, 2:Add, Button, x+ yp, Retry
Gui, 2:Show,x400
;set tooltips for each button - supply text, variable, classnn, or hwnd
setTip("Ok", "Why would you ever need a tooltip that looks like this?", "2") ;on guis other than 1, have to give the gui number - Gui 2 uses all default settings
setTip("Retry", "Maybe do something again.", "2")
setTip("Cancel", "Cancel whatever is happening.", "2")
;~ TipsState(0) ;disable tooltips
Return
#Include tooltipV2a.ahk
2guiClose:
guiClose:
ExitApp
Return
|
_________________

Last edited by Micahs on Sat Apr 18, 2009 10:36 pm; edited 5 times in total |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Mon Apr 13, 2009 5:37 pm Post subject: |
|
|
| Works for me in Win98SE, thanks. One small issue that caught my eye: the tooltip stays in position for a while when the cursor is moved onto another control and then jumps directly to show the new tooltip. Is this intended behavior or should it behave the classic way (dissapear as soon as the cursor leaves the hovered control and appear with a certain delay over the newly hovered one)? |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 413
|
Posted: Mon Apr 13, 2009 8:06 pm Post subject: |
|
|
Not intended, just a silly oversight. I updated the first post with the fix. Is this better? _________________
 |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Tue Apr 14, 2009 4:03 am Post subject: |
|
|
Yes, works perfectly now. Thank you for the fix.  |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 413
|
Posted: Tue Apr 14, 2009 2:16 pm Post subject: |
|
|
Glad you like it.
New version is posted. I fixed another bug, streamlined the setTip function, and made tooltips enabled by default. _________________
 |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Tue Apr 14, 2009 4:57 pm Post subject: |
|
|
Well, now I'm gonna drop the bomb: without COM, HTML or any other such trick, could you put a picture in the tooltip instead of text?
I've seen this done in C++ and working on my machine but dunno the details. Maybe it did use COM, after all...  |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 413
|
Posted: Wed Apr 15, 2009 9:44 am Post subject: |
|
|
Here's what is coming.
 _________________
 |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Wed Apr 15, 2009 10:56 am Post subject: |
|
|
Woohoo, that sure is good news!!!
(Hopefully it'll work in Win9x...)
Keep up the good work, can't wait for the new version!  |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 413
|
Posted: Fri Apr 17, 2009 10:40 am Post subject: |
|
|
New version is up. See first post.
The standard version is the same. The alternate version is new. It allows images and custom text fonts and colors. _________________
 |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Fri Apr 17, 2009 4:58 pm Post subject: |
|
|
Basically, alternate version works. A few quirks though (after brief testing):
- icon 132 and 222 do not exist in Win98's shell library; can be replaced with 133 and 173 (maximum resource number)
- When icon number exceeds 99, icon is not shown and the text is shifted up a few pixels, appearing cut at the top
Great job, however, thank you very much!
EDIT
Actually it's not your fault - there's probably a bug somewhere, in AHK or in Windows' shell, that won't let extract any icon resource with a resource number greater than 99. Most likely a shell issue, since I tried moricons.dll and it did show icon 103. |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 413
|
Posted: Sat Apr 18, 2009 10:38 am Post subject: |
|
|
I've made a fix where if the icon does not load for some reason (icon number greater than resources) it will ignore it and display the text correctly. This won't fix your problem, but will mask the effects. The faulty icon will not show, just the text. _________________
 |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Sat Apr 18, 2009 12:52 pm Post subject: |
|
|
| This is fine, thanks. I've just asked someone to test icon extraction and to my surprise I've been told that most likely AHK extracts icons by ordinal number, not by resource number (he got them mixed up a bit). If that's correct, then it should be fixed in AHK since we shouldn't be supposed to translate resource to ordinal manually, IMHO. |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 2166 Location: GERMANY
|
Posted: Sat Apr 18, 2009 1:40 pm Post subject: |
|
|
Here a version using ToolTip() - Advanced ToolTip features
All functions are included here (using Standard version)
| Code: | CoordMode,Mouse,Screen
ToolTipOptions:="B0000FF F00FF00 t200 I1 M1"
;*************gui1*********************
Gui, Add, Button,,Click to do nothing
Gui, Add, DropDownList,vDDL,red|blue|green||
Gui, Add, Checkbox,, Click to enable
Gui, Add, Edit, HwndMYEdit,This is an edit box
Gui, Add, Button,, Ok
Gui, Add, Button, x+ yp, Cancel
Gui, Add, Button, x+ yp, Retry
Gui, Show,x200
;set tooltips for each button - supply text, variable, classnn, or hwnd
setTip("Button1", "This button does absolutely nothing.") ;using the classnn
setTip("Ok", "Begin the Process") ;using the caption
setTip("Cancel", "Cancel Whatever is Happening!")
setTip("Retry", "Do Over")
setTip("Click to enable", "Checkbox")
setTip(DDL, "Dropdownlist") ;using the variable
setTip(MYEdit, "The infamous edit control") ;using the hwnd
;*************gui2*********************
Gui, 2:Add, Button,,Click to do nothing
Gui, 2:Add, DropDownList,vDDL2,red|blue|green||
Gui, 2:Add, Checkbox,, Click to enable
Gui, 2:Add, Edit, HwndMYEdit2,This is edit box two
Gui, 2:Add, Button,, Ok
Gui, 2:Add, Button, x+ yp, Cancel
Gui, 2:Add, Button, x+ yp, Retry
Gui, 2:Show,x400
;set tooltips for each button - supply text, variable, classnn, or hwnd
setTip("Button1", "This button does absolutely nothing. gui2", 2) ;using the classnn
setTip("Ok", "Begin the Process gui2", 2) ;using the caption
setTip("Cancel", "Cancel Whatever is Happening! gui2", 2)
setTip("Retry", "Do Over gui2", 2)
setTip("Click to enable", "Checkbox gui2", 2)
setTip(DDL2, "Dropdownlist part two: This time it's personal", 2) ;using the variable
setTip(MYEdit2, "The infamous edit control redeux", 2) ;using the hwnd
;TipsState(0) ;disable tooltips
Return
2guiClose:
guiClose:
ExitApp
Return
/*
tooltipV2.ahk
Version: 1.2
By: Micahs
CallWith: (You can use Hwnd, var, text, classnn)
setTip("Button1", "This button does absolutely nothing.") ;using the classnn
setTip("Ok", "Begin the Process") ;using the caption
setTip("Cancel", "Cancel Whatever is Happening!")
setTip(DDL, "Dropdownlist") ;using the variable
setTip(MYEdit, "The infamous edit control") ;using the hwnd
*/
setTip(tipControl, tipText, guiNum=1) ;tipControl - text,variable,hwnd,classnn ; tipText - text to display ; gui number, default is 1
{
global
local List_ClassNN
Gui,%guiNum%:Submit,NoHide
Gui,%guiNum%:+LastFound
WinGet, tipGui_guiID, ID
WinGet, List_ClassNN, ControlList
StringReplace, List_ClassNN, List_ClassNN, `n, `,, All
IfInString, tipControl, %List_ClassNN% ;it is a classnn
{ tipGui_ClassNN := tipControl ;use it as is
}
Else ;must be text/var or ID
{ tipGui_ClassNN := tipGui_getClassNN(tipControl, guiNum) ;get the classnn
}
tipGui_%guiNum%_%tipGui_ClassNN% := tipText ;set the tip
If(!tipGui_Init) ;enable tooltips when the first one is set, but only if TipsState has not been called (either to enable or disable)
{ TipsState(1)
}
}
TipsState(ShowToolTips)
{
global tipGui_Init
tipGui_Init = 1 ;iniialize this latch
If(ShowToolTips)
{ OnMessage(0x200, "WM_MOUSEMOVE") ;enable tips
}
Else
{ OnMessage(0x200, "") ;disable tips
}
}
WM_MOUSEMOVE()
{
global
Critical
IfEqual, A_Gui,, Return
MouseGetPos,,,tipGui_outW,tipGui_outC
If(tipGui_outC != tipGui_OLDoutC)
{ tipGui_OLDoutC := tipGui_outC
Gui, %A_Gui%:+LastFound
ToolTip(1,"")
tipGui_ID := WinExist()
SetTimer, tipGui_killTip, 1000
counter := A_TickCount + 500
Loop
{ MouseGetPos,,,, tipGui_newC
IfNotEqual, tipGui_outC, %tipGui_newC%, Return
looper := A_TickCount
IfGreater, looper, %counter%, Break
sleep,50
}
MouseGetPos,x,y
ToolTip(1,tipGui_%A_Gui%_%tipGui_outC%,tipGui_outC,ToolTipOptions)
}
SetTimer, tipGui_killTip, 1000
Return
tipGui_killTip:
MouseGetPos,,, tipGui_outWm
If(tipGui_outWm != tipGui_ID) or (A_TimeIdle >= 4000)
{ SetTimer, tipGui_killTip, Off
ToolTip(1,"")
}
Return
}
tipGui_getClassNN(tipControl, g=1) ;tipControl = text/var,Hwnd ;g = gui number, default=1
{
Gui,%g%:+LastFound
guiID := WinExist() ;get the id for the gui
WinGet, List_controls, ControlList
StringReplace, List_controls, List_controls, `n, `,, All
;if id supplied do nothing special
IfNotInString, tipControl, %List_controls% ;must be the text/var - get the ID
{ mm := A_TitleMatchMode
SetTitleMatchMode, 3 ;exact match only
ControlGet, o, hWnd,, %tipControl% ;get the id
SetTitleMatchMode, %mm% ;restore previous setting
If(o) ;found match
{ tipControl := o ;set sought-after id
}
}
Loop, Parse, List_controls, CSV
{ ControlGet, o, hWnd,, %A_LoopField% ;get the id of current classnn
If(o = tipControl) ;if it is the one we want
{ Return A_Loopfield ;return the classnn
}
}
}
/*
ToolTip() by HotKeyIt http://www.autohotkey.com/forum/viewtopic.php?t=40165
Options can include any of following parameters separated by space
In - Icon 1-3, e.g. I1
Xn Yn - screen coordinates, can be empty to display near the mouse or caret to display near caret
e.g. X200 Y300 or Xcaret Ycaret
bn - background color, e.g. BFFFFFF or B0xFFFFFF
fn - text color, e.g. F000000 or F0x000000
dn - delay in seconds, e.g. d5
tn - Transparency, e.g. t200
o1 - activate ballontip, e.g. O1
c1 - display close button, e.g. C1
m1 - activate click trough effect, e.g. M1
*/
ToolTip(_tool_tip_id_="", text=" ", title="", options=""){ ;i x y b f d t o c m
static _tt_hwnd_list_
global #_ti_
If !#_ti_
VarSetCapacity(#_ti_, 40, 0),#_ti_:=Chr(40),NumPut(0x20,#_ti_,4)
If !_tool_tip_id_
{
Loop,Parse,_tt_hwnd_list_,|
If WinExist("ahk_id " RegExReplace(A_LoopField,"\d+\."))
DllCall("DestroyWindow","Uint",hwnd1)
_tt_hwnd_list_=
Return
}
If options
Loop,Parse,options,%A_Space%
{
option:= SubStr(A_LoopField,1,1)
If option
%option%:= SubStr(A_LoopField,2)
}
If RegExMatch(_tt_hwnd_list_,"\|" . _tool_tip_id_ . "\.([^\|]+)",hwnd)
hwnd := hwnd1
If (!WinExist("ahk_id " hwnd1) and text!="")
{
_tt_hwnd_list_:=RegExReplace(_tt_hwnd_list_,"\|" . _tool_tip_id_ . "\.[^\|]+\|")
hWnd := DllCall("CreateWindowEx", "Uint", 0x8, "str", "tooltips_class32", "str", "", "Uint", (C ? 80 : 0)+(O ? 115 : 50), "int", 0, "int", 0, "int", 0, "int", 0, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0) ;param4 0xc3 0x80
_tt_hwnd_list_.= "|" . _tool_tip_id_ . "." . hWnd . "|"
NumPut(&_tool_tip_id_,#_ti_,36)
DllCall("SendMessage", "Uint", hWnd, "Uint", 1028, "Uint", 0, "Uint", &#_ti_) ; TTM_ADDTOOL
DllCall("SendMessage", "Uint", hWnd, "Uint", 1041, "Uint", 1, "Uint", &#_ti_) ; TTM_TRACKACTIVATE
WinHide,ahk_id %hWnd%
If !C
WinSet, Disable,,ahk_id %hwnd%
If M
WinSet,ExStyle,^0x20,ahk_id %hwnd%
}
If ((B!="" ? SetToolTipColor(hwnd,B) :) or (F !="" ? SetToolTipTextColor(hwnd,F) :) and text="")
DllCall("DestroyWindow","Uint",hwnd), _tt_hwnd_list_:=RegExReplace(_tt_hwnd_list_,"\|" . _tool_tip_id_ . "\.[^\|]+\|")
else if !D
ShowToolTip(hwnd,x,y,text,title,I,T)
else
{
A_Timer := A_TickCount, D *= 1000
Loop
If (A_TickCount - A_Timer > D or ShowToolTip(hwnd,x,y,text,title,I,T))
Break
DllCall("DestroyWindow","Uint",hwnd), _tt_hwnd_list_:=RegExReplace(_tt_hwnd_list_,"\|" . _tool_tip_id_ . "\.[^\|]+\|")
}
Return hwnd
}
SetToolTipTitle(hwnd,title,I="0"){
title := (StrLen(title) < 96) ? title : ("…" . SubStr(title, -97))
; TTM_SETTITLE ; 0: None, 1:Info, 2: Warning, 3: Error. n > 3: assumed to be an hIcon.
DllCall("SendMessage", "Uint", hWnd, "Uint", 1056, "Uint", I, "Uint", &Title)
}
SetToolTipColor(hwnd,B){
B := (StrLen(B) < 8 ? "0x" : "") . B
B := ((B&255)<<16)+(((B>>8)&255)<<8)+(B>>16) ; rgb -> bgr
DllCall("SendMessage", "Uint", hWnd, "Uint", 1043, "Uint", B, "Uint", 0) ; TTM_SETTIPBKCOLOR
}
SetToolTipTextColor(hwnd,F){
F := (StrLen(F) < 8 ? "0x" : "") . F
F := ((F&255)<<16)+(((F>>8)&255)<<8)+(F>>16) ; rgb -> bgr
DllCall("SendMessage", "Uint", hWnd, "Uint", 1044, "Uint",F & 0xFFFFFF, "Uint", 0) ; TTM_SETTIPTEXTCOLOR
}
ShowToolTip(hwnd,x,y,text,title="",I="0",T=""){
local xc,yc,xw,ywd
MouseGetPos, xc,yc
WinGetPos,xw,yw,,,A
xc+=15,yc+=15
If (x="caret")
xc:=xw+A_CaretX
If (y="caret")
yc:=yw+A_CaretY
DllCall("SendMessage", "Uint", hWnd, "Uint", 1042, "Uint", 0, "Uint", ((x="" ? xc : (x="caret" ? xc : x)) & 0xFFFF)|((y="" ? yc : (y="caret" ? yc : y)) & 0xFFFF)<<16) ; TTM_TRACKPOSITION
If (title!="")
SetToolTipTitle(hwnd,title,I)
NumPut(&text,#_ti_,36)
DllCall("SendMessage", "Uint", hWnd, "Uint", 1048, "Uint", 0, "Uint", A_ScreenWidth) ;TTM_SETMAXTIPWIDTH
DllCall("SendMessage", "Uint", hWnd, "Uint", 0x40c, "Uint", 0, "Uint", &#_ti_) ; TTM_UPDATETIPTEXT
If T
WinSet,Transparent,%t%,ahk_id %hwnd%
} |
_________________ AutoHotFile - ToolTip(n,text,title,options) |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 413
|
Posted: Sat Apr 18, 2009 9:12 pm Post subject: |
|
|
The best of both worlds! It's good to have choices.
(Mine works in Vista. Nanner nanner! ) _________________
 |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Sat Apr 18, 2009 10:30 pm Post subject: |
|
|
All the charm's in the alternate version, with image support.  |
|
| 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
|