Re: Tooltip disappearing and never returning.
Here is an example script that should demonstrate the problem. I've included the Tooltip function from today's post.
When you run the script, notice that tooltips are assigned to all GUI objects. If you click on any (read: most) of the non-button objects, the Tooltip for that object disappears and never returns again. I hope this helps to demonstrate the problem. Thanks for your help.
Code:
#NoEnv
#SingleInstance Force
;-- Collect hWnd for GUI
Gui,+LastFound
GuiHwnd:=WinExist()
;-- Build GUI
gui -MinimizeBox
gui Add,Button,w150 hwndButton1_hWnd gButton1,Test Button 1
Tip:="Button 1: Press me to change my tooltip"
ToolTip(1,Tip,"","A" . Button1_hWnd . " P" . GuiHwnd)
gui Add,Button,y+0 w150 hwndButton2_hWnd gButton2,Test Button 2
Tip:="Button 2: Press me to turn off the tooltip for this button"
ToolTip(2,Tip,"","A" . Button2_hWnd . " P" . GuiHwnd)
gui Add,Button,y+0 w150 hwndButton3_hWnd gButton3,Test Button 3
Tip=
(ltrim
A Multiline Test Tooltip
2nd line
3rd line
4th line.
Press me to turn off all tooltips
)
ToolTip(3,Tip,"","A" . Button3_hWnd . " P" . GuiHwnd)
gui Add,Checkbox,w150 hwndCheckbox_hWnd,Checkbox Control
Tip:="Tooltip for the Checkbox control"
ToolTip(4,Tip,"","A" . Checkbox_hWnd . " P" . GuiHwnd)
gui Add,Radio,w150 hwndRadio_hWnd,Radio Control
Tip:="Tooltip for the Radio control"
ToolTip(5,Tip,"","A" . Radio_hWnd . " P" . GuiHwnd)
gui Add,Edit,w150 hwndEdit_hWnd,Edit Control
Tip:="Tooltip for the Edit control"
ToolTip(6,Tip,"","A" . Edit_hWnd . " P" . GuiHwnd)
gui Add,Text,w150 hwndText_hWnd gNull,Text Control
Tip=
(ltrim join`s
Tooltip for the Text control.`nNote that the Tooltip for a Text control does
not show unless a g-label for the control is defined.
)
ToolTip(7,Tip,"","A" . Text_hWnd . " P" . GuiHwnd)
gui Add,Picture,w150 h100 hwndPicture_hWnd gnull,Picture.bmp
Tip=
(ltrim join`s
Tooltip for the Picture control.`nNote that the Tooltip for a Picture
control does not show unless a g-label for the control is defined.
)
ToolTip(9,Tip,"","A" . Picture_hWnd . " P" . GuiHwnd)
gui Add,DropDownList,w150 r3 hwndDropDownList_hWnd,DropDownList Control||2|3
Tip:="Tooltip for the DropDownList control"
ToolTip(10,Tip,"","A" . DropDownList_hWnd . " P" . GuiHwnd)
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.`nNote that
this tip is different than the Edit piece of the control.
)
ToolTip(11,Tip,"","A" . ComboBox_hWnd . " P" . GuiHwnd)
gui Add,ListBox,w150 r3 hwndListBox_hWnd,ListBox Control||2|3
Tip:="Tooltip for the ListBox control"
ToolTip(12,Tip,"","A" . ListBox_hWnd . " P" . GuiHwnd)
gui Add,ListView,w150 h50 hwndListView_hWnd,ListView Control
Tip=
(ltrim join`s
Tooltip for the ListView control.`nNote that this tip is different than
the header piece of the control.
)
ToolTip(13,Tip,"","A" . ListView_hWnd . " P" . GuiHwnd)
gui Add,DateTime,w150 hwndDateTime_hWnd ;,DateTime Control
Tip:="Tooltip for the DateTime control"
ToolTip(14,Tip,"","A" . DateTime_hWnd . " P" . GuiHwnd)
;-- Uncomment this if you want to see the MonthCal control. Works the same as DateTime
;;;;;gui Add,MonthCal,w150 hwndMonthCal_hWnd ;,MonthCal Control
;;;;;Tip:="Tooltip for the MonthCal control"
;;;;;ToolTip(15,Tip,"","A" . MonthCal_hWnd . " P" . GuiHwnd)
gui Add,Progress,w150 hwndProgress_hWnd,65 ;Progress Control
Tip:="Tooltip for the Progress control"
ToolTip(16,Tip,"","A" . Progress_hWnd . " P" . GuiHwnd)
gui Add,Slider,w150 hwndSlider_hWnd,45 ;Slider Control
Tip:="Tooltip for the Slider control"
ToolTip(17,Tip,"","A" . Slider_hWnd . " P" . GuiHwnd)
gui Add,Hotkey,w150 hwndHotkey_hWnd,45 ;Hotkey Control
Tip:="Tooltip for the Hotkey control"
ToolTip(18,Tip,"","A" . Hotkey_hWnd . " P" . GuiHwnd)
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.
)
ToolTip(19,Tip,"","A" . Edit2_hWnd . " P" . GuiHwnd)
gui Add,UpDown,hwndUpDown_hWnd Range 1-10,5
Tip:="Tooltip for the UpDown control"
ToolTip(20,Tip,"","A" . UpDown_hWnd . " P" . GuiHwnd)
gui Show,,Tooltip Test
;-- Note: The following information cannot be collected until after the window
; has been rendered
;-- 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.`nNote that this tip is
different than the drop-down button piece of this control.
)
ToolTip(11,Tip,"","A" . EditComboBox_hWnd . " P" . GuiHwnd)
;-- 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.`nNote that this tip is
different than the rest of the ListView control.
)
ToolTip(13,Tip,"","A" . ListViewHeader_hWnd . " P" . GuiHwnd)
return
Button1:
ToolTip(1,"Button 1: New Text","","AButton1 P" . GuiHwnd)
return
Button2:
ToolTip(2,"","","AButton2 P" . GuiHwnd)
return
Button3:
ToolTip()
MsgBox 64,ToolTips Cleared,All Tooltips destroyed. %A_Space%
return
Null:
return
GUIClose:
GUIescape:
ExitApp
;;;;;#include ToolTip.ahk
ToolTip(ID="", text=" ", title="",options=""){ ;i x y b f d t o c m p a
static
local option, a, b, c, d, f, i, m, o, p, C_ID, hWnd, #_DetectHiddenWindows
C_ID:=ID
If ((#_DetectHiddenWindows:=A_DetectHiddenWindows)="Off")
DetectHiddenWindows, On
If !ID
{
Loop, Parse, hWndArray, % Chr(2)
If (hwnd:=WinExist("ahk_id " hWndArray%A_LoopField%))
DllCall("DestroyWindow","Uint",hwnd)
hWndArray=
DetectHiddenWindows,%#_DetectHiddenWindows%
Return
}
If options
Loop,Parse,options,%A_Space%
If (option:= SubStr(A_LoopField,1,1))
%option%:= SubStr(A_LoopField,2)
hwnd:=hWndArray%ID%
If (!hwnd and text)
{
hWndArray.=(hWndArray ? Chr(2) : "") . 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", P, "Uint", 0, "Uint", 0, "Uint", 0) ;param4 0xc3 0x80
hWndArray%ID%:=hwnd
DllCall("SendMessage", "Uint", hWnd, "Uint", 1048, "Uint", 0, "Uint", A_ScreenWidth) ;TTM_SETMAXTIPWIDTH
} else if !(text){
If (title){
Gosub, TTM_SETTITLE
DllCall("SendMessage", "Uint", hWnd, "Uint", 0x41D, "Uint", 0, "Uint", 0) ; TTM_UPDATE
Gosub, TTM_TRACKPOSITION
} else
DllCall("DestroyWindow","Uint",hwnd), hWndArray%ID%:=""
DetectHiddenWindows,%#_DetectHiddenWindows%
Return
}
If P
{
ID := Abs(P)
If A {
If A is not Xdigit
ControlGet,A,Hwnd,,%A%,ahk_id %P%
ID :=Abs(A)
hWndArray.=(hWndArray ? Chr(2) : "") . ID
}
If !TOOLINFO_%ID%
VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40)
else
DllCall("SendMessage", "Uint", hWnd, "Uint", 0x405, "Uint", 0, "Uint", &TOOLINFO_%ID%) ; TTM_DELTOOL
Numput(ID,TOOLINFO_%ID%,12)
Numput(1|16,TOOLINFO_%ID%,4)
Numput(P,TOOLINFO_%ID%,8)
DllCall("SendMessage", "Uint", hWnd, "Uint", 0x403, "Uint", 2, "Uint", (D ? D*1000 : -1)) ; TTDT_INITIAL
DllCall("SendMessage", "Uint", hWnd, "Uint", 0x404, "Uint", 0, "Uint", &TOOLINFO_%ID%) ; TTM_ADDTOOL
} else {
If !TOOLINFO_%ID%
VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40)
If O
NumPut(0x20,TOOLINFO_%ID%,4)
else
NumPut(0x20|0x80,TOOLINFO_%ID%,4)
DllCall("SendMessage", "Uint", hWnd, "Uint", 0x403, "Uint", 2, "Uint", (D ? D*1000 : -1)) ; TTDT_INITIAL
DllCall("SendMessage", "Uint", hWnd, "Uint", 1028, "Uint", 0, "Uint", &TOOLINFO_%ID%) ; TTM_ADDTOOL
}
If B
Gosub, TTM_SETTIPBKCOLOR
If F
Gosub, TTM_SETTIPTEXTCOLOR
NumPut(&text,TOOLINFO_%ID%,36)
If title
Gosub, TTM_SETTITLE
Gosub, TTM_UPDATETIPTEXT
If (D and !P)
{
A_Timer := A_TickCount, D *= 1000
Gosub, TTM_TRACKPOSITION
Loop
{
Gosub, TTM_TRACKPOSITION
If (A_TickCount - A_Timer > D)
Break
}
DllCall("DestroyWindow","Uint",hwnd), hWndArray%C_ID%:=""
}
If !P
{
Gosub, TTM_TRACKPOSITION
If !C
WinSet, Disable,,ahk_id %hwnd%
If M
WinSet,ExStyle,^0x20,ahk_id %hwnd%
If T
WinSet,Transparent,%T%,ahk_id %hwnd%
}
Return hwnd
TTM_SETTITLE:
title := (StrLen(title) < 96) ? title : ("…" . SubStr(title, -97))
DllCall("SendMessage", "Uint", hWnd, "Uint", 1056, "Uint", I, "Uint", &Title)
Return
TTM_TRACKPOSITION:
If x is integer
If y is integer
{
DllCall("SendMessage", "Uint", hWnd, "Uint", 1042, "Uint", 0, "Uint", (x & 0xFFFF)|(y & 0xFFFF)<<16)
DllCall("SendMessage", "Uint", hWnd, "Uint", 1041, "Uint", 1, "Uint", &TOOLINFO_%ID%) ; TTM_TRACKACTIVATE
Return
}
MouseGetPos, xc,yc
xc+=15,yc+=15
If (x="caret" or y="caret"){
WinGetPos,xw,yw,,,A
If x=caret
{
SysGet,xl,76
SysGet,xr,78
xc:=xw+A_CaretX +1
xc:=(xl>xc ? xl : (xr<xc ? xr : xc))
}
If (y="caret"){
SysGet,yl,77
SysGet,yr,79
yc:=yw+A_CaretY+15
yc:=(yl>yc ? yl : (yr<yc ? yr : yc))
}
}
DllCall("SendMessage", "Uint", hWnd, "Uint", 1042, "Uint", 0, "Uint", (xc & 0xFFFF)|(yc & 0xFFFF)<<16)
DllCall("SendMessage", "Uint", hWnd, "Uint", 1041, "Uint", 1, "Uint", &TOOLINFO_%ID%) ; TTM_TRACKACTIVATE
Return
TTM_SETTIPBKCOLOR:
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)
Return
TTM_SETTIPTEXTCOLOR:
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)
Return
TTM_UPDATETIPTEXT:
DllCall("SendMessage", "Uint", hWnd, "Uint", 0x40c, "Uint", 0, "Uint", &TOOLINFO_%ID%)
Return
}
MI_ExtractIcon(Filename, IconNumber, IconSize)
{
If A_OSVersion in WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
{
DllCall("PrivateExtractIcons", "Str", Filename, "Int", IconNumber-1, "Int", IconSize, "Int", IconSize, "UInt*", hIcon, "UInt*", 0, "UInt", 1, "UInt", 0, "Int")
If !ErrorLevel
Return hIcon
}
If DllCall("shell32.dll\ExtractIconExA", "Str", Filename, "Int", IconNumber-1, "UInt*", hIcon, "UInt*", hIcon_Small, "UInt", 1)
{
SysGet, SmallIconSize, 49
If (IconSize <= SmallIconSize) {
DllCall("DeStroyIcon", "UInt", hIcon)
hIcon := hIcon_Small
}
Else
DllCall("DeStroyIcon", "UInt", hIcon_Small)
If (hIcon && IconSize)
hIcon := DllCall("CopyImage", "UInt", hIcon, "UInt", 1, "Int", IconSize, "Int", IconSize, "UInt", 4|8)
}
Return, hIcon ? hIcon : 0
}
GetAssociatedIcon(File){
static
sfi_size:=352
local Ext,Fileto,FileIcon,FileIcon#
If not sfi
VarSetCapacity(sfi, sfi_size)
SplitPath, File,,, Ext
if Ext in EXE,ICO,ANI,CUR,LNK
{
If ext=LNK
{
FileGetShortcut,%File%,Fileto,,,,FileIcon,FileIcon#
File:=!FileIcon ? FileTo : FileIcon
}
SplitPath, File,,, Ext
If !(hIcon%Ext%:=MI_ExtractIcon(InStr(File,"`n") ? SubStr(file,1,InStr(file,"`n")-1) : file,FileIcon# ? FileIcon# : 1,32))
hIcon%Ext%:=#_hIcon_3
}
else If !(InStr(hIcons,"|" . Ext . "|")){
If DllCall("Shell32\SHGetFileInfoA", "str", File, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101){
Loop 4
hIcon%Ext% += *(&sfi + A_Index-1) << 8*(A_Index-1)
}
hIcons.= "|" . Ext . "|"
}
return hIcon%Ext%
}