Function included in calling scripts:
Code: Select all
Notify(message, timeout := 2500) {
static NSW_WinName := "NotificationOperator - 0xF505 @ ZZ9PZA"
NSW_ID := WinExist(NSW_WinName)
if(!NSW_ID) {
for i, v in Array("\lib\CNS.ahk", "\CNS.ahk", "\..\CNS.ahk") {
if(FileExist(A_ScriptDir . v)) {
Run, % A_ScriptDir . v, A_ScriptDir, UseErrorLevel, CNS_PID
if(!ErrorLevel and CNS_PID) {
WinWait, %NSW_WinName%,,
NSW_ID := WinExist(NSW_WinName)
break
}
}
}
if(!NSW_ID) {
ToolTip, % message
return
}
}
;ToolTip, % SHOWNOTIFICATION . "`n" . message . "`n" . &message . "`n" . NSW_ID
SendMessage, %SHOWNOTIFICATION%, &message, %timeout%,, ahk_id %NSW_ID%
}
Code: Select all
;Centralized Notification System
;Version: 1.0
;Author: KuroiLight/klomb
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#NoEnv
#SingleInstance, force
#Persistent
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DetectHiddenWindows, On
global SCRIPT_TITLE := "NotificationOperator - 0xF505 @ ZZ9PZA"
WinSetTitle, ahk_id %A_ScriptHwnd%,, %SCRIPT_TITLE%
global SHOWNOTIFICATION := 0xF505
RemainingTick := 0
TickSize := 250
Notification_Visible := false
Notify_Window := 0x0
BgColor := "282828"
FrColor := "EEEEEE"
FontSize := "12"
OnMessage(SHOWNOTIFICATION, "Show_Notification")
SetTimer, Hide_Notification, %TickSize%
Initialize()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
return
Initialize() {
global base_x, base_y
if(WinExist("ahk_class Shell_TrayWnd")) {
WinGetPos, shell_x, shell_y, shell_w, shell_h, ahk_class Shell_TrayWnd
base_x := shell_x + shell_w
base_y := shell_y
} else {
SysGet, Primary_M, MonitorPrimary
SysGet, Monitor_, Monitor, %Primary_M%
base_x := Monitor_Right
base_y := Monitor_Left
}
base_x -= 10
base_y -= 10
}
Hide_Notification() {
global RemainingTick, Notification_Visible, Notify_Window, TickSize
if(!Notify_Window)
return
if(RemainingTick >= 1) {
RemainingTick -= TickSize
} else {
if(Notification_Visible) {
Gui, %Notify_Window%: Hide
Notification_Visible := false
}
}
}
Show_Notification(ptr_message, lParam, msg, hwnd) {
;ToolTip, % ptr_message . "`n" . lParam . "`n" . msg
Critical
if(!msg == SHOWNOTIFICATION or !ptr_message)
return 0
message := StrGet(ptr_message)
global RemainingTick, Notification_Visible, Notify_Window, MainLbl, base_x, base_y
global BgColor, FrColor, FontSize
RemainingTick := lParam
if(!Notify_Window) {
Gui, New, +AlwaysOnTop +Border -Caption -Resize +ToolWindow +HwndNotify_Window, %SCRIPT_TITLE%
Gui, %Notify_Window%: Color, %BgColor%
Gui, %Notify_Window%: Font, c%FrColor% s%FontSize%
Gui, %Notify_Window%: Margin, 5, 5
Gui, %Notify_Window%: Add, Text, +HwndMainLbl, %message%
if(!Notify_Window)
Throw, "Failure to create GUI."
} else {
DllCall("User32\DestroyWindow", "UInt", MainLbl)
Gui, %Notify_Window%: Add, Text, X5 Y5 +HwndMainLbl, %message%
}
Gui, %Notify_Window%: Show, Hide AutoSize NoActivate
WinGetPos,,, N_W, N_H, ahk_id %Notify_Window%
New_X := base_x - N_W
New_Y := base_y - N_H
Gui, %Notify_Window%: Show, AutoSize NoActivate X%New_X% Y%New_Y%
return (Notification_Visible := true)
}