Another update, to add font color.
toast.exe "title" "message" duration-in-milliseconds "startcolor" "endcolor" "fontcolor"
; Needs to be compiled as a standalone exe, as it captures event handling - core application will not work whilst the window is active
#NoTrayIcon ; Don't show a tray icon
; Place at the top of your script
$g_szVersion = "Toast v1.0"
If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)
#include <GUIConstants.au3>
#include <Array.au3>
#include <Color.au3>
Opt("GuiOnEventMode",1)
Dim $Label
Dim $move, $Xpos, $Ypos, $TrayWnd, $Xexit, $Yexit
Dim $iStartColor = 0x0000ff, $iEndColor = 0xffffff, $iFontColor
Dim $iSize = -1, $iWeight = -1, $iAttribute = 4, $iFontName = -1
Dim $Clicked = 0
Dim $iWinWidth = 100, $iWinHeight = 100
Dim $activeWindow
; Get any command line input
if ubound($CMDLINE) < 4 Then
msgbox(48, "Toast.exe", "Invalid input")
Exit
EndIf
If $CMDLINE[0] > 0 Then
$title = $CMDLINE[1]
$message = $CMDLINE[2]
$duration = $CMDLINE[3]
if ubound($CMDLINE) >= 5 then $iStartColor = "0x" & $CMDLINE[4]
if ubound($CMDLINE) >= 6 then $iEndColor = "0x" & $CMDLINE[5]
if ubound($CMDLINE) >= 7 then $iFontColor = "0x" & $CMDLINE[6]
; Get the title of the current active window
$activeWindow = WinGetTitle('')
_SetPopupBackground($iStartColor, $iEndColor)
$Ret = _Popup($title, $message, $duration)
EndIf
Exit
;========= End Test
#ce
;===============================================================================
;
; Function Name: _SetPopupSize()
; Description: Set the size of the Popup Window
;
; Parameter(s): $WinWidth - Popup window width
; $WinHeight - Popup window height
;
; Requirement(s): None
; Return Value(s): None
;
; Author(s): GioVit <gvitale@cantv.net>
;
;===============================================================================
Func _SetPopupSize($WinWidth, $WinHeight)
$iWinWidth = $winWidth
$iWinHeight = $WinHeight
EndFunc
;===============================================================================
;
; Function Name: _SetPopupBackround()
; Description: Set the Attributes of the font the Hyperlink Label
;
; Parameter(s): $Size - Font size
; $Weight - Font weight
; $Attibutes - Font Attributes
; $FontName - Self explanatory
;
; Requirement(s): None
; Return Value(s): None
;
; Author(s): GioVit <gvitale@cantv.net>
;
;===============================================================================
Func _SetPopupFont($Size, $Weight= - 1, $Attribute = 4, $FontName = -1)
$iSize = $Size
$iWeight = $Weight
$Attribute = Bitor($Attribute, 4)
$iAttribute = $Attribute
$iFontName = $FontName
EndFunc
;===============================================================================
;
; Function Name: _SetPopupBackround()
; Description: Set the Popup Window gradient colors
;
; Parameter(s): $StartColor - Popup window width
; $EndColor - Popup window height
;
; Requirement(s): None
; Return Value(s): None
;
; Author(s): GioVit <gvitale@cantv.net>
;
;===============================================================================
Func _SetPopupBackground($StartColor, $EndColor)
$iStartColor = $StartColor
$iEndColor = $EndColor
EndFunc
;===============================================================================
;
; Function Name: _Popup()
; Description: Display a sliding popup window from the taskbar displaying a Clickable Control Label
;
; Parameter(s): $Title - A window Title (Not Shown)
; $Message - The Clickable text displayed in the window
; $Timeout - [optional] Timeout in miliseconds. After the timeout has elapsed the popup window will be automatically closed.
;
; Requirement(s): None
; Return Value(s): -1 = Exit Button was Clicked
; 0 = Timeout elapsed
; 1 = Message was Clicked
;
; Author(s): GioVit <gvitale@cantv.net>
;
;===============================================================================
Func _Popup($Title, $Message, $Timeout = 3000)
$OldEventMode = AutoItSetOption("GuiOnEventMode",1)
$PreviousMode = AutoItSetOption("WinTitleMatchMode", 4)
$TrayWnd = WinGetPos("classname=Shell_TrayWnd")
AutoItSetOption("WinTitleMatchMode", $PreviousMode)
$pos = ControlGetPos("Program Manager", "", "SysListView321")
$x = $pos[0]
$y = $pos[1]
$w = $pos[2]
$h = $pos[3]
If $TrayWnd[1] > 0 Then
$move = "Up"
$Xpos = @DesktopWidth - $iWinWidth - 10
$Ypos = $TrayWnd[1]
$Xexit = 4
$Yexit = 4
Elseif $TrayWnd[0] > 0 Then
$move = "Left"
$Xpos = $TrayWnd[0]
$Ypos = @DesktopHeight - $iWinHeight - 10
$Xexit = 4
$Yexit = 4
ElseIf $TrayWnd[2] = @DesktopWidth Then
$move = "Down"
$Xpos = @DesktopWidth - $iWinWidth - 10
$Ypos = $TrayWnd[1] + $TrayWnd[3] - $iWinHeight
$Xexit = 4
$Yexit = $iWinHeight - 19
ElseIf $TrayWnd[3] = @DesktopHeight Then
$move = "Right"
$Xpos = $TrayWnd[0] + $TrayWnd[2] - $iWinWidth
$Ypos = @DesktopHeight - $iWinHeight - 10
$Xexit = $iWinWidth - 19
$Yexit = 4
EndIf
$handle = GUICreate($Title, $iWinWidth, $iWinHeight, $Xpos, $Ypos, $WS_POPUPWINDOW,$WS_EX_TOOLWINDOW);$WS_SIZEBOX + $WS_POPUPWINDOW)
_GUICtrlCreateGradient($iStartColor, $iEndColor, 1, 1, $iWinWidth, $iWinHeight,"H")
$Label = _GuiCtrlCreateHyperlink($Message, 5, 24, $iWinWidth - 10, $iWinHeight - 48, $iFontColor, 'Click Here', BitOR($GUI_SS_DEFAULT_LABEL, $SS_CENTER))
GuiCtrlSetOnEvent($Label,"_Label")
$EXIT = GUICtrlCreatePic ("exit.jpg",$Xexit, $Yexit,15,15,0x0100 )
GUICtrlSetTip(-1, "Exit")
GuiCtrlSetOnEvent($Exit,"_Exit")
GUISetState(@SW_SHOW)
; Put focus back on the main window
WinActivate ( $activeWindow )
ShowPopup($Title, $move)
$i = 1
while $i*10 < $Timeout
Sleep(10)
$i += 1
if $Clicked Then ExitLoop
WEnd
HidePopup($Title, $move)
AutoItSetOption("GuiOnEventMode", $OldEventMode)
Return $Clicked
EndFunc
Func ShowPopup($Title, $move)
Select
Case $move = "Down"
GUIMove($Title, 0, $iWinHeight)
Case $move = "Up"
GUIMove($Title, 0, -$iWinHeight)
Case $move = "Left"
GUIMove($Title, -$iWinWidth, 0)
Case $move = "Right"
GUIMove($Title, $iWinWidth, 0)
EndSelect
EndFunc
Func HidePopup($Title, $move)
$Pxy = WinGetPos($Title)
Select
Case $move = "Down"
GUIMove($Title, 0, -$Pxy[1]-$Pxy[3], 400, False)
Case $move = "Up"
GUIMove($Title, 0, @DesktopHeight-$Pxy[1], 400, False)
Case $move = "Left"
GUIMove($Title, @DesktopWidth - $Pxy[0], 0, 400, False)
Case $move = "Right"
GUIMove($Title, -$Pxy[0] - $Pxy[2], 0, 400, False)
EndSelect
EndFunc
Func GUIMove($Title, $Dx=0, $Dy=0, $Time=700, $Showing = True)
Dim $Incx, $Incy, $IncTime, $Offsetx, $Offsety
$Incx = $Dx/($Time/15)
$Incy = $Dy/($Time/15)
$IncTrans = 255/($Time/15)
$Pxy = WinGetPos($Title)
$i = 1
While 1
if $Showing Then
WinSetTrans($Title, "", $IncTrans*$i)
Else
WinSetTrans($Title, "", 255 - $IncTrans*$i)
EndIf
WinMove($Title,"", $Pxy[0]+$Incx*$i, $Pxy[1]+$Incy*$i)
Sleep(15)
if abs($Incx*$i) >= Abs($Dx) and Abs($Incy*$i) >= Abs($Dy) then ExitLoop
$i += 1
WEnd
EndFunc
Func _Exit()
$Clicked = -1
EndFunc
Func _Label()
;MsgBox(0,"Info", "Click")
$Clicked = 1
Return 1
EndFunc
;===============================================================================
; Others Authors Code
;===============================================================================
;===============================================================================
;
; Function Name: _GuiCtrlCreateHyperlink()
; Description: Creates a label that acts as a hyperlink
;
; Parameter(s): $s_Text - Label text
; $i_Left - Label left coord
; [$i_Top] - Label top coord
; [$i_Width] - Label width
; [$i_Height] - Label height
; [$i_Color] - Text Color
; [$s_ToolTip] - Hyperlink ToolTip
; [$i_Style] - Label style
; [$i_ExStyle] - Label extended style
;
; Requirement(s): None
; Return Value(s): Control ID
;
; Author(s): Saunders <krawlie@hotmail.com>
;
;===============================================================================
Func _GuiCtrlCreateHyperlink($s_Text, $i_Left, $i_Top, $i_Width = -1, $i_Height = -1, $i_Color = 0x0000ff, $s_ToolTip = '', $i_Style = -1, $i_ExStyle = -1)
Local $i_CtrlID
$i_CtrlID = GUICtrlCreateLabel($s_Text, $i_Left, $i_Top, $i_Width, $i_Height, $i_Style, $i_ExStyle)
If $i_CtrlID <> 0 Then
GUICtrlSetFont (-1, $iSize, $iWeight, $iAttribute, $iFontName)
GUICtrlSetImage (-1, "shell32.dll",22)
GuiCtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, $i_Color)
GUICtrlSetCursor(-1, 0)
If $s_ToolTip <> '' Then
GUICtrlSetTip(-1, $s_ToolTip)
EndIf
EndIf
Return $i_CtrlID
EndFunc;==>_GuiCtrlCreateHyperlink
Func _GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY, $nWidth = 255, $nHeight = 20,$s_type="V")
Local $colorR = _ColorGetRed($nStartColor)
Local $colorG = _ColorGetGreen($nStartColor)
Local $colorB = _ColorGetBlue($nStartColor)
Local $nStepR,$nStepG,$nStepB
GuiCtrlCreateGraphic($nX, $nY, $nWidth, $nHeight)
If(StringUpper($s_type) == "V") Then
$nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nWidth
$nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nWidth
$nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nWidth
For $i = 0 To $nWidth
$sColor = "0x" & StringFormat("%02X%02X%02X", $colorR+$nStepR*$i, $colorG+$nStepG*$i, $colorB+$nStepB*$i)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $i, 0)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $i, $nHeight)
Next
ElseIf(StringUpper($s_type) == "H") Then
$nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nHeight
$nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nHeight
$nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nHeight
For $i = 0 To $nHeight
$sColor = "0x" & StringFormat("%02X%02X%02X", $colorR+$nStepR*$i, $colorG+$nStepG*$i, $colorB+$nStepB*$i)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $nWidth, $i)
Next
EndIf
GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc