├── Notify.ahk ├── Notify.text └── README.md /Notify.ahk: -------------------------------------------------------------------------------- 1 | #SingleInstance,Force 2 | Count:=0 3 | Notify:=Notify(20) 4 | /* 5 | Usage: 6 | Notify:=Notify() 7 | Window:=Notify.AddWindow("Your Text Here",{Icon:4,Background:"0xAA00AA"}) 8 | |---Window ID |--------Options 9 | Options: 10 | 11 | Window ID will be used when making calls to Notify.SetProgress(Window,ProgressValue) 12 | 13 | Animate: Ways that the window will animate in eg. {Animate:""} Can be Bottom, Top, Left, Right, Slide, Center, or Blend (Some work together, and some override others) 14 | Background: Color value in quotes eg. {Background:"0xAA00AA"} 15 | Buttons: Comma Delimited list of names for buttons eg. {Buttons:"One,Two,Three"} 16 | Color: Font color eg.{Color:"0xAAAAAA"} 17 | Destroy: Comma Delimited list of Bottom, Top, Left, Right, Slide, Center, or Blend 18 | Flash: Flashes the background of the notification every X ms eg. {Flash:1000} 19 | FlashColor: Sets the second color that your notification will change to when flashing eg. {FlashColor:"0xFF00FF"} 20 | Font: Face of the message font eg. {Font:"Consolas"} 21 | Icon: Can be either an Integer to pull an icon from Shell32.dll or a full path to an EXE or full path to a dll. You can add a comma and an integer to select an icon from within that file eg. {Icon:"C:\Windows\HelpPane.exe,2"} 22 | IconSize: Width and Height of the Icon eg. {IconSize:20} 23 | Hide: Comma Separated List of Directions to Hide the Notification eg. {Hide:"Left,Top"} 24 | Progress: Adds a progress bar eg. {Progress:10} ;Starts with the progress set to 10% 25 | Radius: Size of the border radius eg. {Radius:10} 26 | Size: Size of the message text eg {Size:20} 27 | ShowDelay: Time in MS of how long it takes to show the notification 28 | Sound: Plays either a beep if the item is an integer or the sound file if it exists eg. {Sound:500} 29 | Time: Sets the amount of time that the notification will be visible eg. {Time:2000} 30 | Title: Sets the title of the notification eg. {Title:"This is my title"} 31 | TitleColor: Title font color eg. {TitleColor:"0xAAAAAA"} 32 | TitleFont: Face of the title font eg. {TitleFont:"Consolas"} 33 | TitleSize: Size of the title text eg. {TitleSize:12} 34 | */ 35 | if(1){ 36 | Notify.AddWindow("Testing",{Background:"0xFF00FF",Color:"0xFF0000",ShowDelay:1000,Hide:"Top,Left",Buttons:"This,One,Here",Radius:40}) 37 | return 38 | } 39 | Text:=["Longer text for a longer thing","Taller Text`nfor`na`ntaller`nthing"] 40 | SetTimer,RandomProgress,500 41 | Loop,2 42 | { 43 | Random,Time,3000,8000 44 | /* 45 | Time:=A_Index=40?1000:Time 46 | Random,Sound,500,800 47 | */ 48 | Random,TT,1,2 49 | Random,Background,0x0,0xFFFFFF 50 | Random,Color,0x0,0xFFFFFF 51 | Random,Icon,20,200 52 | Notify.AddWindow(Text[TT],{Icon:300,Title:"This is my title",TitleFont:"Tahoma",TitleSize:10,Time:Time,Background:Background,Flash:1000,Color:Color}) 53 | Notify.AddWindow(Text[TT],{Icon:"D:\AHK\AHK-Studio\AHK-Studio.exe",IconSize:20,Title:"This is my title",TitleFont:"Tahoma",TitleSize:10,Time:Time,Background:Background,Flash:1000,FlashColor:"0xAA00AA",Color:Color,Time:Time,Sound:Sound}) 54 | Notify.AddWindow(Text[TT],{Icon:Icon,IconSize:80,Title:"This is my title",TitleFont:"Tahoma",TitleSize:10,Time:Time,Background:Background,Flash:1000,FlashColor:"0xAA00AA",Color:Color,Time:Time,Sound:Sound}) 55 | ID:=Notify.AddWindow(Text[TT],{Progress:0,Icon:Icon,IconSize:80,Title:"This is my title",TitleFont:"Tahoma",TitleSize:10,Time:Time,Background:Background,Flash:1000,FlashColor:"0xAA00AA",Color:Color,Time:Time,Sound:Sound}) 56 | Notify.AddWindow("This is my text",{Title:"My Title"}) 57 | Random,Ico,1,5 58 | Notify.AddWindow("Odd icon",{Icon:A_AhkPath "," Ico,IconSize:20,Title:"This is my title",TitleFont:"Tahoma",TitleSize:10,Time:Time,Background:Background,Flash:1000,Color:Color,Time:Time}) 59 | Random,Delay,100,400 60 | Delay:=1000 61 | Notify.AddWindow(Text[TT],{Radius:20,Hide:"Left,Bottom",Animate:"Right,Slide",ShowDelay:Delay,Icon:Icon,IconSize:20,Title:"This is my title",TitleFont:"Tahoma",TitleSize:10,Background:Background,Color:Color,Time:Time,Progress:0}) 62 | } 63 | return 64 | RandomProgress: 65 | for a,b in NotifyClass.Windows{ 66 | Random,Pro,10,100 67 | Notify.SetProgress(a,Pro) 68 | } 69 | return 70 | Click(Obj){ 71 | for a,b in Obj 72 | Msg.=a " = " b "`n" 73 | MsgBox,%Msg% 74 | } 75 | ;Actual code starts here 76 | Notify(Margin:=5){ 77 | static Notify:=New NotifyClass() 78 | Notify.Margin:=Margin 79 | return Notify 80 | } 81 | Class NotifyClass{ 82 | __New(Margin:=10){ 83 | this.ShowDelay:=40,this.ID:=0,this.Margin:=Margin,this.Animation:={Bottom:0x00000008,Top:0x00000004,Left:0x00000001,Right:0x00000002,Slide:0x00040000,Center:0x00000010,Blend:0x00080000} 84 | if(!this.Init) 85 | OnMessage(0x201,NotifyClass.Click.Bind(this)),this.Init:=1 86 | }AddWindow(Text,Info:=""){ 87 | (Info?Info:Info:=[]) 88 | for a,b in {Background:0,Color:"0xAAAAAA",TitleColor:"0xAAAAAA",Font:"Consolas",TitleSize:12,TitleFont:"Consolas",Size:20,Font:"Consolas",IconSize:20} 89 | if(Info[a]="") 90 | Info[a]:=b 91 | if(!IsObject(Win:=NotifyClass.Windows)) 92 | Win:=NotifyClass.Windows:=[] 93 | Hide:=0 94 | for a,b in StrSplit(Info.Hide,",") 95 | if(Val:=this.Animation[b]) 96 | Hide|=Val 97 | Info.Hide:=Hide 98 | DetectHiddenWindows,On 99 | this.Hidden:=Hidden:=A_DetectHiddenWindows,this.Current:=ID:=++this.ID,Owner:=WinActive("A") 100 | Gui,Win%ID%:Default 101 | if(Info.Radius) 102 | Gui,Margin,% Floor(Info.Radius/3),% Floor(Info.Radius/3) 103 | Gui,-Caption +HWNDMain +AlwaysOnTop +Owner%Owner% 104 | Gui,Color,% Info.Background,% Info.Background 105 | NotifyClass.Windows[ID]:={ID:"ahk_id" Main,HWND:Main,Win:"Win" ID,Text:Text,Background:Info.Background,FlashColor:Info.FlashColor,Title:Info.Title,ShowDelay:Info.ShowDelay,Destroy:Info.Destroy} 106 | for a,b in Info 107 | NotifyClass.Windows[ID,a]:=b 108 | if((Ico:=StrSplit(Info.Icon,",")).1) 109 | Gui,Add,Picture,% (Info.IconSize?"w" Info.IconSize " h" Info.IconSize:""),% "HBITMAP:" LoadPicture(Foo:=(Ico.1+0?"Shell32.dll":Ico.1),Foo1:="Icon" (Ico.2!=""?Ico.2:Info.Icon),2) 110 | if(Info.Title){ 111 | Gui,Font,% "s" Info.TitleSize " c" Info.TitleColor,% Info.TitleFont 112 | Gui,Add,Text,x+m,% Info.Title 113 | }Gui,Font,% "s" Info.Size " c" Info.Color,% Info.Font 114 | Gui,Add,Text,HWNDText,%Text% 115 | SysGet,Mon,MonitorWorkArea 116 | if(Info.Sound+0) 117 | SoundBeep,% Info.Sound 118 | if(FileExist(Info.Sound)) 119 | SoundPlay,% Info.Sound 120 | this.MonBottom:=MonBottom,this.MonTop:=MonTop,this.MonLeft:=MonLeft,this.MonRight:=MonRight 121 | if(Info.Time){ 122 | TT:=this.Dismiss.Bind({this:this,ID:ID}) 123 | SetTimer,%TT%,% "-" Info.Time 124 | }if(Info.Flash){ 125 | TT:=this.Flash.Bind({this:this,ID:ID}) 126 | SetTimer,%TT%,% Info.Flash 127 | NotifyClass.Windows[ID].Timer:=TT 128 | } 129 | for a,b in StrSplit(Info.Buttons,","){ 130 | Gui,Margin,% Info.Radius?Info.Radius/2:5,5 131 | Gui,Font,s10 132 | Gui,Add,Button,% (a=1?"xm":"x+m"),%b% 133 | } 134 | if(Info.Progress!=""){ 135 | Gui,Win%ID%:Font,s4 136 | ControlGetPos,x,y,w,h,,ahk_id%Text% 137 | Gui,Add,Progress,w%w% HWNDProgress,% Info.Progress 138 | NotifyClass.Windows[ID].Progress:=Progress 139 | }Gui,Win%ID%:Show,Hide 140 | WinGetPos,x,y,w,h,ahk_id%Main% 141 | if(Info.Radius) 142 | WinSet, Region, % "0-0 w" W " h" H " R" Info.Radius "-" Info.Radius,ahk_id%Main% 143 | Obj:=this.SetPos(),Flags:=0 144 | for a,b in StrSplit(Info.Animate,",") 145 | Flags|=Round(this.Animation[b]) 146 | DllCall("AnimateWindow","UInt",Main,"Int",(Info.ShowDelay?Info.ShowDelay:this.ShowDelay),"UInt",(Flags?Flags:0x00000008|0x00000004|0x00040000|0x00000002)) 147 | for a,b in StrSplit((Obj.Destroy?Obj.Destroy:"Top,Left,Slide"),",") 148 | Flags|=Round(this.Animation[b]) 149 | Flags|=0x00010000,NotifyClass.Windows[ID].Flags:=Flags 150 | DetectHiddenWindows,%Hidden% 151 | return ID 152 | }Click(){ 153 | Obj:=NotifyClass.Windows[RegExReplace(A_Gui,"\D")],Obj.Button:=A_GuiControl,(Fun:=Func("Click"))?Fun.Call(Obj):"",this.Delete(A_Gui) 154 | }Delete(Win){ 155 | Win:=RegExReplace(Win,"\D"),Obj:=NotifyClass.Windows[Win],NotifyClass.Windows.Delete(Win) 156 | if(WinExist("ahk_id" Obj.HWND)){ 157 | DllCall("AnimateWindow","UInt",Obj.HWND,"Int",Obj.ShowDelay,"UInt",Obj.Flags) 158 | Gui,% Obj.Win ":Destroy" 159 | }if(TT:=Obj.Timer) 160 | SetTimer,%TT%,Off 161 | this.SetPos() 162 | }Dismiss(){ 163 | this.this.Delete(this.ID) 164 | }Flash(){ 165 | Obj:=NotifyClass.Windows[this.ID] 166 | Obj.Bright:=!Obj.Bright 167 | Color:=Obj.Bright?(Obj.FlashColor!=""?Obj.FlashColor:Format("{:06x}",Obj.Background+800)):Obj.Background 168 | if(WinExist(Obj.ID)) 169 | Gui,% Obj.Win ":Color",%Color%,%Color% 170 | }SetPos(){ 171 | Width:=this.MonRight-this.MonLeft,MH:=this.MonBottom-this.MonTop,MinX:=[],MinY:=[],Obj:=[],Height:=0,Sub:=0,MY:=MH,MaxW:={0:1},Delay:=A_WinDelay,Hidden:=A_DetectHiddenWindows 172 | DetectHiddenWindows,On 173 | SetWinDelay,-1 174 | for a,b in NotifyClass.Windows{ 175 | WinGetPos,x,y,w,h,% b.ID 176 | Height+=h+this.Margin 177 | if(MH<=Height) 178 | Sub:=Width-MinX.MinIndex()+this.Margin,MY:=MH,MinY:=[],MinX:=[],Height:=h,MaxW:={0:1},Reset:=1 179 | MaxW[w]:=1,MinX[Width-w-Sub]:=1,MinY[MY:=MY-h-this.Margin]:=y,XPos:=MinX.MinIndex()+(Reset?0:MaxW.MaxIndex()-w) 180 | WinMove,% b.ID,,%XPos%,MinY.MinIndex() 181 | Obj[a]:={x:x,y:y,w:w,h:h},Reset:=0 182 | }DetectHiddenWindows,%Hidden% 183 | SetWinDelay,%Delay% 184 | }SetProgress(ID,Progress){ 185 | GuiControl,,% NotifyClass.Windows[ID].Progress,%Progress% 186 | } 187 | } 188 | 189 | ;Actual Code Ends Here 190 | return 191 | Escape:: 192 | ExitApp 193 | return -------------------------------------------------------------------------------- /Notify.text: -------------------------------------------------------------------------------- 1 | 0.000.1 2 | Fixed: Reported by PhyRBuRn #1 3 | -Click to Delete a Notification with a timer was causing an error -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notify 2 | Usage: 3 | 4 | ``` 5 | Notify:=Notify() 6 | 7 | WindowID:=Notify.AddWindow("Your Text Here",{Icon:4,Background:"0xAA00AA",Buttons:"OK,Exit"}) 8 | ``` 9 | Window ID will be used when making calls to 10 | ``` 11 | Notify.SetProgress(WindowID,ProgressValue) 12 | ``` 13 | ``` 14 | Click(Obj){ 15 | MsgBox,% Obj.Button ;Tells you which button clicked 16 | } 17 | ``` 18 | # Options: 19 | Option|Usage|Description 20 | ------|-----|----------- 21 | Animate|{Animate:"Bottom,Left"}|Ways that the window will animate in. Can be Bottom, Top, Left, Right, Slide, Center, or Blend (Some work together, and some override others) 22 | Background|{Background:"0xAA00AA"}|Color value in quotes 23 | Buttons|{Buttons:"One,Two,Three"}|Comma Delimited list of names for buttons 24 | Color|{Color:"0xAAAAAA"}|Font color 25 | Destroy|{Destroy:"Top,Left"}|Comma Delimited list of Bottom, Top, Left, Right, Slide, Center, or Blend 26 | Flash|{Flash:1000}|Flashes the background of the notification every X ms 27 | FlashColor|{FlashColor:"0xFF00FF"}|Sets the second color that your notification will change to when flashing 28 | Font|{Font:"Consolas"}|Face of the message font 29 | Icon|{Icon:"C:\Windows\HelpPane.exe,2"}|Can be either an Integer to pull an icon from Shell32.dll or a full path to an EXE or full path to a dll. You can add a comma and an integer to select an icon from within that file eg. 30 | IconSize|{IconSize:20}|Width and Height of the Icon 31 | Progress|{Progress:10}|Adds a progress bar ;Starts with the progress set to 10% 32 | Radius|{Radius:10}|Size of the border radius 33 | Size|{Size:20}|Size of the message text 34 | ShowDelay|{ShowDelay:1000}|Time in MS of how long it takes to show and hide the notification 35 | Sound|{Sound:500}|Plays either a beep if the item is an integer or the sound file if it exists 36 | Time|{Time:2000}|Sets the amount of time that the notification will be visible 37 | Title|{Title:"This is my title"}|Sets the title of the notification 38 | TitleColor|{TitleColor:"0xAAAAAA"}|Title font color 39 | TitleFont|{TitleFont:"Consolas"}|Face of the title font 40 | TitleSize|{TitleSize:12}|Size of the title text 41 | --------------------------------------------------------------------------------