- For those like me where Traytip always stops working after a certain time
(on any PC, even fresh Windows install, even with all the solutions proposed on this forum) - Or for anyone wanting a different (better?) TrayTip
Included
- Adds native traytip in action centre (can be removed by commenting one line)
- ProgressBar
- Can be included in other scripts
- Multiple stacked
- Works with correct timing and not with seperate calculated timer
- All traytips same width, text wraps (word- ánd letter-wrapping)
- Rounded corners (Tx Emmanuel)
- Different sound options (anything SoundPlay can)
- Icon options (default, index, file, same as trayicon) (Partly Tx Emmanuel)
- Different tests at end of script
- Uses monitor work area (instead of monitor edges)
- Features in other scripts below not taken over. Vote for them to include them in the main script.
- Calling function to remove all traytips.
- Clicking traytip to remove it
- Evade errors when traytip does not exist anymore (to be clarified by emmanuel)
- Failsafe against multiple scripts (unless you call all scripts via one script)
- myTrayTip Screenshot.png (201.58 KiB) Viewed 3113 times
Code: Select all
#SingleInstance force ; Allow only one instance of this script to be running.
#Requires AutoHotkey v2
;https://www.autohotkey.com/boards/viewtopic.php?f=83&t=121509
myTrayTip(tip, titl:="Autohotkey", secs:=3, ico:=-1, Sound:="*64") {
static WF:=258, trays:=[], trayTop,scrRight, scrBot:=0
if scrBot==0 ;static function
trayTop:=MonitorGetWorkArea(1,,, &scrRight, &scrBot)?scrBot:(scrRight:=A_ScreenWidth) AND (scrBot:=A_ScreenHeight)
TrayTip(tip, titl, IsInteger(ico)?ico:0) ;If you want it in in action centre
g := Gui("+AlwaysOnTop -Caption +ToolWindow +LastFound")
WinSetTransparent 240
g.BackColor := RegRead("HKCU\SOFTWARE\Microsoft\Windows\DWM", "ColorizationColor")
F:= g.marginX := g.marginY:= 0 ; prevent gui show from adding a margin for progressbar complete bottom
W0:=200
If ico==0
W0:=WF
Else If ico==-1
I:=A_IconNumber?A_IconNumber:1,
F:=A_IconFile?A_IconFile:A_AhkPath
Else If IsInteger(I:=ico)
F:="C:\Windows\system32\imageres.dll"
Else If FileExist(ico)
I:=1, F:=ico
If F {
g.AddPicture("x10 y10 w48 h-1 Section Icon" I,F)
}
g.SetFont("Bold ccccccc s13")
g.AddEdit((ico ? "xs+48 ys" : "") " w" W0 " Background" g.BackColor " -VScroll -E0x200 Center vt", titl) ; Using edits for word-cut-wrapping for fixed width
g.SetFont("norm s11")
g.AddEdit((ico ? " xs+48" : "") " w" W0 " Background" g.BackColor " -VScroll -E0x200 y+5 Center 0x80", tip)
g.AddProgress("x0 y+10 w" WF " h5 caa33aa Background0x663366 vprogress Range0-" WF)
g.Show("Hide") ;To get width & height we show-hide
WinGetPos(,, &W, &H, g.Hwnd) ; Works well with dpiscaling
g.Show("NA X" (scrRight - W) " Y" trayTop:=(trayTop-H) ) ; We cannot set lastTrayY here because it might be destroyed the time we arrive here
WinSetRegion("0-0 w" W " h" H " R12-12", g)
trays.Push({
g: g,
mSecs: secs * 1000,
start: A_TickCount
})
if trays.Length = 1 {
Try SoundPlay Sound
SetTimer(update, 100)
}
update() {
removes:=Array()
for i,tray in trays {
elapsedTime := A_TickCount - tray.start
if tray.mSecs <= elapsedTime {
removes.Push(i) ;doc:unsafe to remove inside loop, use second loop
continue
}
tray.g["progress"].Value := WF * elapsedTime / tray.mSecs
}
if i:=removes.Length {
trayTop:=scrBot
while i {
trays[removes[i]].g.Destroy()
trays.removeAt(removes[i--])
}
if trays.Length = 0
SetTimer , 0
else for i,tray in trays { ; move down, better to do after destroys in same update for a lot of reasons
WinGetPos(,&Y, &W, &H,tray.g.Hwnd) ; Works well with dpiscaling
tray.g.Move(, trayTop:=(trayTop-H) )
}
}
}
}
;Testing
^!t::
{
myTrayTip("3 second","Default icon",3)
myTrayTip("4 second","Default icon",4)
myTrayTip("6 second","No icon",6, 0)
myTrayTip("8 second","Path icon",8,"C:\Windows\WinSxS\amd64_microsoft-windows-dxp-deviceexperience_31bf3856ad364e35_10.0.19041.746_none_251e769058968366\pictures.ico")
myTrayTip("Testing 5","Very very loooooooooooooooooooong Title`n9 second",9)
myTrayTip("Very very loooooooooooooooooooong tip`nLine2","10 second",10)
myTrayTip("6 second","Info icon",6, 77)
myTrayTip("11 second","Warning icon",11, 80)
myTrayTip("12 second","Error icon",12, 94)
myTrayTip("13 second no title",13)
myTrayTip("14 second empty title","",14)
myTrayTip("15 second","Index icon",15, 1)
myTrayTip("16 second","Index icon",16, 2)
myTrayTip("16 second","Index icon - same seconds",16, 3)
myTrayTip("18 second","Index icon",18, 4)
myTrayTip("19 second","Index icon",19,5)
myTrayTip("19 second","Index icon - same seconds",19,90)
myTrayTip("20 second",,20)
myTrayTip("21 second",,21)
myTrayTip("22 second",,22)
myTrayTip("23 second",,23)
}