Jump to content

How to make Toast - New version 2 Aug 18


Melba23
 Share

Recommended Posts

Awesome script. I like this one over another I found in these forums a while back for its "cleanness". I will definitely look at using this on future projects. I looked and did not see any options that set the transparency of the toast message itself. Assuming I didnt miss that somewhere in the UDF, would that be hard to do having both a title bar and a message body for the toast?

Thanks again for the great work!

Link to comment
Share on other sites

  • Moderators

Reaper HGN,

Thanks for the compliments. :D

If you want to change the transparency, you need to add a line like this:

; Create Message label
GUICtrlCreateLabel($sMessage, 10 + $iIcon_Reduction, 10 + $iTitle_Height, $iLabelwidth, $iLabelheight)
GUICtrlSetStyle(-1, $iLabel_Style)
If $iToast_Message_Col <> Default Then GUICtrlSetColor(-1, $iToast_Message_Col)

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WinSetTrans($hToast_Handle, "", 100) ; New line (see WinSetTrans in the Help file for details)
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; Slide Toast Slice into view from behind systray and activate
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 1000, "long", $aToast_Data[2])

I leave it to you to add another option to _Toast_Set if you so desire - the current version gives you lots of clues on how to do it! :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I think this is the initial post http://www.autoitscript.com/forum/index.php?showtopic=86298

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Congratulations on your searching skills! But if you look at the date you will see that post relates to a much earlier version of the UDF from over a year ago.

Please use the version in this thread if you decide to make some Toast yourself on this fine Sunday morning! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@M23

Do I have to start training you all over again?

This thread should have been titled

"How to make Melba Toast"

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

Thank you for that - but I prefer it thick and toasted on both sides! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

A recent forum query about the small pop-ups that some apps produce from the systray made me realise that I had not posted my version of how this can be done.

In the function _Toast_Show() I changed $iDelay < 0 to $iDelay <= 0 in the sections that add the [X] but for some reason it will display but doesn't register that I have clicked on it. Surely this should work?

; Set title bar height - with minimum for [X]
    Local $iTitle_Height = 0
    If $sTitle = "" Then
        If $iDelay <= 0 Then $iTitle_Height = 6
    Else
        $iTitle_Height = $iLine_Height + 2
        If $iDelay <= 0 Then
            If $iTitle_Height < 17 Then $iTitle_Height = 17
        EndIf
    EndIf

; Create closure [X] if needed
        If $iDelay <= 0 Then
            ; Create [X]
            Local $iX_YCoord = Int(($iTitle_Height - 17) / 2)
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, $iX_YCoord, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Header_Col)
            ; Reduce title bar width to allow [X] to activate
            $iTitle_Width -= 18
        EndIf

If $iDelay <= 0 Then
            ; Only need [X]
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, 0, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Message_Col)
        EndIf

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

guinness,

In the UDF I posted the logic for $iDelay works like this:

$iDelay = 0 (default) - the script continues immediately, the Toast remains visible uniil a _Toast_Hide or another _Toast_Show.

$iDelay > 0 - the script waits $iDelay seconds before continuing, the Toast behaves as above

$iDelay < 0 - the script continues immediately, the Toast will retract automatically after $iDelay seconds or if the [X] is clicked.

As you are mixing up 2 of the states, I am not very surprised that it is not working as you want. But.......................

If you alter the code, you can debug it! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hi,

After having received literally hundreds of requests (well, one actually - from dmob) I have added a new parameter to the _Toast_Show function. This allows the user to override the normal maximum width setting of the Toast (500 pixels) to display wider messages if their formatting requires it. However, the Toast will not display if the result is wider than the display.

The new version (and a new example script as well before anyone asks! :D ) is in the first post.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

James,

Here is a version which can display gradients in the title bar. If you enter a single value for the $vHdr_BkCol parameter in _Toast_Set you get a solid bar - if you enter a 2-element array you get a gradient:

#include-once

; #INDEX# ============================================================================================================
; Title .........: Toast
; AutoIt Version : 3.3.2.0 - uses AdlibRegister/Unregister
; Language ......: English
; Description ...: Show and hides slice messages from the systray in user defined colours and fonts
; Author(s) .....: Melba23.  Credit to GioVit (tray location)
; ====================================================================================================================

;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

; #INCLUDES# =========================================================================================================
#include <StringSize.au3>

#include <WinAPIEx.au3>

; #GLOBAL VARIABLES# =================================================================================================
Global $iDef_Toast_Font_Size   = _Toast_GetDefFont(0)
Global $sDef_Toast_Font_Name   = _Toast_GetDefFont(1)

Global $hToast_Handle        = 0
Global $hToast_Close_X       = 9999
Global $iToast_Move          = 0
Global $iToast_Style         = 1 ; $SS_CENTER
Global $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
Global $vToast_Header_BkCol[2]  = [$aRet[0], ""]
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
Global $iToast_Header_Col    = $aRet[0]
Global $iToast_Header_Bold   = 0
Global $iToast_Message_BkCol = $iToast_Header_Col
Global $iToast_Message_Col   = $vToast_Header_BkCol[01]
Global $iToast_Font_Size     = $iDef_Toast_Font_Size
Global $sToast_Font_Name     = $sDef_Toast_Font_Name
Global $iToast_Timer         = 0
Global $iToast_Start         = 0
Global $fToast_Close         = False

; #CURRENT# ==========================================================================================================
; _Toast_Set:  Sets text justification and optionally colours and font, for _Toast_Show function calls
; _Toast_Show: Shows a slice message from the systray
; _Toast_Hide: Hides a slice message from the systray
; ====================================================================================================================

; #INTERNAL_USE_ONLY#=================================================================================================
; _Toast_Locate:        Find Systray and determine Toast start position and movement direction
; _Toast_Timer_Check:   Checks whether Toast has timed out or closure [X] clicked
; _Toast_WM_EVENTS:     Message handler to check if closure [X] clicked
; _Toast_GetDefFont:    Determine system default MsgBox font and size
; _Toast_Title_Gradient Fills the Title bar with a user-defined 2 colour gradient
; ====================================================================================================================

; #FUNCTION# =========================================================================================================
; Name...........: _Toast_Set
; Description ...: Sets text justification and optionally colours and font, for _Toast_Show function calls
; Syntax.........: _Toast_Set($vJust, [$vHdr_BkCol, [$iHdr_Col, [$iMsg_BkCol, [$iMsg_Col, [$sFont_Size, [$iFont_Name]]]]]])
; Parameters ....: $vJust     - 0 = Left justified, 1 = Centred (Default), 2 = Right justified
;                                Can use $SS_LEFT, $SS_CENTER, $SS_RIGHT
;                                + 4 = Header text in bold
;                       >>>>>    Setting this parameter to' Default' will reset ALL parameters to default values     <<<<<
;                       >>>>>    All optional parameters default to system MsgBox default values                     <<<<<
;                  $vHdr_BkCol - [Optional] The colour for the title bar background
;                                - If a single colour then the title bar is set to that colour
;                                - If a 2-element array, the title bar is set to a L-R gradient between the 2 colours
;                  $iHdr_Col   - [Optional] The colour for the title bar text
;                  $iMsg_BkCol - [Optional] The colour for the message background
;                  $iMsg_Col   - [Optional] The colour for the message text
;                                Omitting a colour parameter or setting it to -1 leaves it unchanged
;                                Setting a colour parameter to Default resets the system colour
;                  $iFont_Size - [Optional] The font size in points to use for the Toast
;                  $sFont_Name - [Optional] The font to use for the Toast
;                       >>>>>    Omitting a font parameter, setting size to -1 or name to "" leaves it unchanged     <<<<<
;                       >>>>>    Setting a font parameter to Default resets the system message box font or size      <<<<<
; Requirement(s).: v3.3.2.0 or higher - AdlibRegister/Unregister used in _Toast_Show
; Return values .: Success - Returns 1
;                  Failure - Returns 0 and sets @error to 1 with @extended set to parameter index number
; Author ........: Melba23
; Example........; Yes
;=====================================================================================================================

Func _Toast_Set($vJust, $vHdr_BkCol = -1, $iHdr_Col = -1, $iMsg_BkCol = -1, $iMsg_Col = -1, $iFont_Size = -1, $sFont_Name = "")

    ; Set parameters
    Switch $vJust
        Case Default
            $iToast_Style         = 1; $SS_CENTER
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $vToast_Header_BkCol[0]  = $aRet[0]
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iToast_Header_Col    = $aRet[0]
            $iToast_Message_BkCol = $iToast_Header_Col
            $iToast_Message_Col   = $vToast_Header_BkCol[0]
            $sToast_Font_Name     = $sDef_Toast_Font_Name
            $iToast_Font_Size     = $iDef_Toast_Font_Size
            Return
        Case 0, 1, 2, 4, 5, 6
            $iToast_Style = $vJust
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 1, 0)
    EndSwitch

    If IsArray($vHdr_BkCol) Then
        If UBound($vHdr_BkCol) <> 2 Then Return SetError(1, 2, 0)
        For $i = 0 To 1
            Switch $vHdr_BkCol[$i]
                Case 0 To 0xFFFFFF
                    ; Valid
                Case Else
                    Return SetError(1, 2, 0)
            EndSwitch
        Next
        ; Must be valid array
        $vToast_Header_BkCol = $vHdr_BkCol
    Else
        Switch $vHdr_BkCol
            Case Default
                $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
                $vToast_Header_BkCol[0]  = $aRet[0]
            Case 0 To 0xFFFFFF
                $vToast_Header_BkCol[0] = Int($vHdr_BkCol)
            Case -1
                ; Do nothing
            Case Else
                Return SetError(1, 2, 0)
        EndSwitch
        ; Set the second element to "" as a flag
        $vToast_Header_BkCol[1]  = ""
    EndIf

    Switch $iHdr_Col
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iToast_Header_Col  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Header_Col = Int($iHdr_Col)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 3, 0)
    EndSwitch

    Switch $iMsg_BkCol
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iToast_Message_BkCol  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Message_BkCol = Int($iMsg_BkCol)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 4, 0)
    EndSwitch

    Switch $iMsg_Col
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iToast_Message_Col  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Message_Col = Int($iMsg_Col)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 5, 0)
    EndSwitch

    Switch $iFont_Size
        Case Default
            $iToast_Font_Size = $iDef_Toast_Font_Size
        Case 8 To 72
            $iToast_Font_Size = Int($iFont_Size)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 6, 0)
    EndSwitch

    Switch $sFont_Name
        Case Default
            $sToast_Font_Name = $sDef_Toast_Font_Name
        Case ""
            ; Do nothing
        Case Else
            If IsString($sFont_Name) Then
                $sToast_Font_Name = $sFont_Name
            Else
                Return SetError(1, 7, 0)
            EndIf
    EndSwitch

    Return 1

EndFunc ; => _Toast_Set

; #FUNCTION# =========================================================================================================
; Name...........: _Toast_Show
; Description ...: Shows a slice message from the systray
; Syntax.........: _Toast_Show($vIcon, $sTitle, $sMessage, [$iDelay [, $fWait [, $fRaw]]])
; Parameters ....: $vIcon    - 0 - No icon, 8 - UAC, 16 - Stop, 32 - Query, 48 - Exclamation, 64 - Information
;                              The $MB_ICON constant can also be used for the last 4 above
;                              If set to the name of an exe, the main icon of that exe will be displayed
;                              Any other value returns -1, error 1
;                  $sTitle   - Text to display on Title bar
;                  $sMessage - Text to display in Toast body
;                  $iDelay   - The delay in seconds before the Toast retracts or script continues (Default = 0)
;                              If negative, an [X] is added to the title bar. Clicking [X] retracts/continues immediately
;                  $fWait    - True  - Script waits for delay time before continuing and Toast remains visible (default)
;                              False - Script continues and Toast retracts automatically after delay time
;                  $fRaw     - True  - Message is not wrapped and Toast expands to show full width
;                            - False - Message is wrapped if over max preset Toast width
; Requirement(s).: v3.3.1.5 or higher - AdlibRegister/Unregister used in _Toast_Show
; Return values .: Success: Returns 2-element array: [Toast width, Toast height]
;                  Failure: Returns -1 and sets @error as follows:
;                           1 = Toast GUI creation failed
;                           2 = Taskbar not found
;                           3 = StringSize error
;                           4 = When using Raw, the Toast is too wide for the display
; Author ........: Melba23, based on some original code by GioVit for the Toast
; Notes .........; Any visible Toast is retracted by a subsequent _Toast_Hide or _Toast_Show, or clicking a visible [X]
; Example........; Yes
;=====================================================================================================================

Func _Toast_Show($vIcon, $sTitle, $sMessage, $iDelay = 0, $fWait = True, $fRaw = False)

    ; Store current GUI mode and set Message mode
    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    ; Retract any Toast already in place
    If $hToast_Handle <> 0 Then _Toast_Hide()

    ; Reset non-reacting Close [X] ControlID
    $hToast_Close_X = 9999

    ; Set minimum Toast widths
    Local $iToast_Width_max = 500
    Local $iToast_Width_min = 150

    ; Check for icon
    Local $iIcon_Style = 0
    Local $iIcon_Reduction = 50
    Local $sDLL = "user32.dll"
    If StringIsDigit($vIcon) Then
        Switch $vIcon
            Case 0
                $iIcon_Reduction = 0
            Case 8
                $sDLL = "imageres.dll"
                $iIcon_Style = 78
            Case 16 ; Stop
                $iIcon_Style = -4
            Case 32 ; Query
                $iIcon_Style = -3
            Case 48 ; Exclam
                $iIcon_Style = -2
            Case 64 ; Info
                $iIcon_Style = -5
            Case Else
                $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(1, 0, -1)
        EndSwitch
    Else
        $sDLL = $vIcon
        $iIcon_Style = 0
    EndIf

    ; Determine max message width
    Local $iMax_Label_Width = $iToast_Width_max - 20 - $iIcon_Reduction
    If $fRaw = True Then $iMax_Label_Width = 0

    ; Get message label size
    Local $aLabel_Pos = _StringSize($sMessage, $iToast_Font_Size, Default, Default, $sToast_Font_Name, $iMax_Label_Width)
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(3, 0, -1)
    EndIf

    ; Set text to match rectangle
    $sMessage = $aLabel_Pos[0]

    ;Set line height for this font
    Local $iLine_Height = $aLabel_Pos[1]

    ; Set label size
    Local $iLabelwidth  = $aLabel_Pos[2]
    Local $iLabelheight = $aLabel_Pos[3]

    ; Set Toast size
    Local $iToast_Width = $iLabelwidth + 20 + $iIcon_Reduction
    ; Check if Toast will fit on screen
    If $iToast_Width > @DesktopWidth - 20 Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(4, 0, -1)
    EndIf

    If $iToast_Width < $iToast_Width_min + $iIcon_Reduction Then
        ; Increase if below min size
        $iToast_Width = $iToast_Width_min + $iIcon_Reduction
        $iLabelwidth  = $iToast_Width_min - 20
    EndIf

    ; Set title bar height - with minimum for [X]
    Local $iTitle_Height = 0
    If $sTitle = "" Then
        If $iDelay < 0 Then $iTitle_Height = 6
    Else
        $iTitle_Height = $iLine_Height + 2
        If $iDelay < 0 Then
            If $iTitle_Height < 17 Then $iTitle_Height = 17
        EndIf
    EndIf

    ; Set Toast height as label height + title bar + bottom margin
    Local $iToast_Height = $iLabelheight + $iTitle_Height + 20
    ; Ensure enough room for icon if displayed
    If $iIcon_Reduction Then
        If $iToast_Height < $iTitle_Height + 42 Then $iToast_Height = $iTitle_Height + 47
    EndIf

    ; Get Toast starting position and direction
    Local $aToast_Data = _Toast_Locate($iToast_Width, $iToast_Height)

    ; Create Toast slice with $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW style and $WS_EX_TOPMOST extended style
    $hToast_Handle = GUICreate("", $iToast_Width, $iToast_Height, $aToast_Data[0], $aToast_Data[1], 0x80880000, BitOr(0x00000080, 0x00000008))
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(1, 0, -1)
    EndIf
        GUISetFont($iToast_Font_Size, Default, Default, $sToast_Font_Name)
        GUISetBkColor($iToast_Message_BkCol)

    ; Set centring parameter
    Local $iLabel_Style = 0 ; $SS_LEFT
    If BitAND($iToast_Style, 1) = 1 Then
        $iLabel_Style = 1 ; $SS_CENTER
    ElseIf BitAND($iToast_Style, 2) = 2 Then
        $iLabel_Style = 2 ; $SS_RIGHT
    EndIf

    ; Check installed fonts
    Local $sX_Font = "WingDings"
    Local $sX_Char = "x"
    Local $i = 1
    While 1
        Local $sInstalled_Font = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $i)
        If @error Then ExitLoop
        If StringInStr($sInstalled_Font, "WingDings 2") Then
            $sX_Font = "WingDings 2"
            $sX_Char = "T"
        EndIf
        $i += 1
    WEnd

    ; Create title bar if required
    If $sTitle <> "" Then

        ; Create disabled background strip
        If $vToast_Header_BkCol[1] = "" Then
            ; Want solid
            GUICtrlCreateLabel("", 0, 0, $iToast_Width, $iTitle_Height)
                GUICtrlSetBkColor(-1, $vToast_Header_BkCol[0])
                    GUICtrlSetState(-1, 128) ; $GUI_DISABLE
        Else
            ; Want gradient
            Local $hPic = GUICtrlCreatePic("", 0, 0, $iToast_Width, $iTitle_Height)
                GUICtrlSetState(-1, 128) ; $GUI_DISABLE
                _Toast_Title_Gradient(GUICtrlGetHandle($hPic), $iToast_Width, $iTitle_Height)
        EndIf

        ; Set title bar width to offset text
        Local $iTitle_Width = $iToast_Width - 10

        ; Create closure [X] if needed
        If $iDelay < 0 Then
            ; Create [X]
            Local $iX_YCoord = Int(($iTitle_Height - 17) / 2)
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, $iX_YCoord, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Header_Col)
            ; Reduce title bar width to allow [X] to activate
            $iTitle_Width -= 18
        EndIf

        ; Create Title label with bold text, centred vertically in case bar is higher than line
        GUICtrlCreateLabel($sTitle, 10, 0, $iTitle_Width, $iTitle_Height, 0x0200) ; $SS_CENTERIMAGE
            GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
            GUICtrlSetColor(-1, $iToast_Header_Col)
            If BitAND($iToast_Style, 4) = 4 Then GUICtrlSetFont(-1, $iToast_Font_Size, 600)

    Else

        If $iDelay < 0 Then
            ; Only need [X]
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, 0, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Message_Col)
        EndIf

    EndIf

    ; Create icon
    If $iIcon_Reduction Then GUICtrlCreateIcon($sDLL, $iIcon_Style, 10, 10 + $iTitle_Height)

    ; Create Message label
    GUICtrlCreateLabel($sMessage, 10 + $iIcon_Reduction, 10 + $iTitle_Height, $iLabelwidth, $iLabelheight)
        GUICtrlSetStyle(-1, $iLabel_Style)
        If $iToast_Message_Col <> Default Then GUICtrlSetColor(-1, $iToast_Message_Col)

    ; Slide Toast Slice into view from behind systray and activate
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 1000, "long", $aToast_Data[2])

    ; Activate Toast without stealing focus
    GUISetState(@SW_SHOWNOACTIVATE, $hToast_Handle)

    ; If script is to pause
    If $fWait = True Then

        ; Begin timeout counter
        Local $iTimeout_Begin = TimerInit()

        ; Wait for timeout or closure
        While 1
            If GUIGetMsg() = $hToast_Close_X Or TimerDiff($iTimeout_Begin) / 1000 >= Abs($iDelay) Then ExitLoop
        WEnd

    ; If script is to continue and delay has been set
    ElseIf Abs($iDelay) > 0 Then

        ; Store timer info
        $iToast_Timer = Abs($iDelay * 1000)
        $iToast_Start = TimerInit()

        ; Register Adlib function to run timer
        AdlibRegister("_Toast_Timer_Check", 100)
        ; Register message handler to check for [X] click
        GUIRegisterMsg(0x0021, "_Toast_WM_EVENTS") ; $WM_MOUSEACTIVATE

    EndIf

    ; Reset original mode
    $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)

    ; Create array to return Toast dimensions
    Local $aToast_Data[3] = [$iToast_Width, $iToast_Height, $iLine_Height]

    Return $aToast_Data

EndFunc ; => _Toast_Show

; #FUNCTION# ========================================================================================================
; Name...........: _Toast_Hide
; Description ...: Hides a slice message from the systray
; Syntax.........: _Toast_Hide()
; Requirement(s).: v3.3.1.5 or higher - AdlibRegister used in _Toast_Show
; Return values .: Success: Returns 0
;                  Failure: If Toast does not exist returns -1 and sets @error to 1
; Author ........: Melba23
; Example........; Yes
;=====================================================================================================================

Func _Toast_Hide()

    ; If no Toast to hide, return
    If $hToast_Handle = 0 Then Return SetError(1, 0, -1)

    ; Slide Toast back behind systray
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 500, "long", $iToast_Move)

    ; Delete Toast slice
    GUIDelete($hToast_Handle)

    ; Set flag for "no Toast"
    $hToast_Handle = 0

EndFunc ; => _Toast_Hide

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Locate
; Description ...: Find Systray and determine Toast start position and movement direction
; Syntax ........: _Toast_Locate($iToast_Width, $iToast_Height)
; Parameters ....: $iToast_Width  - required width of slice
;                  $iToast_Height - required height of slice
; Author ........: Melba23, based on some original code by GioVit
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show
; ===============================================================================================================================
Func _Toast_Locate($iToast_Width, $iToast_Height)

    ; Define return array
    Local $aToast_Data[3]

    ; Find systray
    Local $iPrevMode = Opt("WinTitleMatchMode", 4)
    Local $aTray_Pos = WinGetPos("[CLASS:Shell_TrayWnd]")
    Opt("WinTitleMatchMode", $iPrevMode)

    ; If error in finding systray
    If Not IsArray($aTray_Pos) Then Return SetError(2, 0, -1)

    ; Determine direction of Toast motion and starting position
    If $aTray_Pos[1] > 0 Then
        $iToast_Move = 0x00050004 ; $AW_SLIDE_OUT_BOTTOM
        $aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
        $aToast_Data[1] = $aTray_Pos[1] - $iToast_Height
        $aToast_Data[2] = 0x00040008 ; $AW_SLIDE_IN_BOTTOM
    Elseif $aTray_Pos[0] > 0 Then
        $iToast_Move = 0x00050001 ; $AW_SLIDE_OUT_RIGHT
        $aToast_Data[0] = $aTray_Pos[0] - $iToast_Width
        $aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
        $aToast_Data[2] = 0x00040002 ; $AW_SLIDE_IN_RIGHT
    ElseIf $aTray_Pos[2] = @DesktopWidth Then
        $iToast_Move = 0x00050008 ; $AW_SLIDE_OUT_TOP
        $aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
        $aToast_Data[1] = $aTray_Pos[1] + $aTray_Pos[3]
        $aToast_Data[2] = 0x00040004 ; $AW_SLIDE_IN_TOP
    ElseIf $aTray_Pos[3] = @DesktopHeight Then
        $iToast_Move = 0x00050002 ; $AW_SLIDE_OUT_LEFT
        $aToast_Data[0] = $aTray_Pos[0] + $aTray_Pos[2]
        $aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
        $aToast_Data[2] = 0x00040001 ; $AW_SLIDE_IN_LEFT
    EndIf

    Return $aToast_Data

EndFunc ; => _Toast_Locate

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Timer_Check
; Description ...: Checks whether Toast has timed out or closure [X] clicked
; Syntax ........: _Toast_Locate($iToast_Width, $iToast_Height)
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show if the Wait parameter is set to False
; ===============================================================================================================================
Func _Toast_Timer_Check()

    ; Return if timeout not elapsed and [X] not clicked
    If TimerDiff($iToast_Start) < $iToast_Timer And $fToast_Close = False Then Return

    ; Unregister message handler
    GUIRegisterMsg(0x0021, "") ; $WM_MOUSEACTIVATE
    ; Unregister this function
    AdlibUnRegister("_Toast_Timer_Check")
    ; Reset flag
    $fToast_Close = False
    ; Retract slice
    _Toast_Hide()

EndFunc; => _Toast_Timer_Check

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_WM_EVENTS
; Description ...: Message handler to check if closure [X] clicked
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show if the Wait parameter is set to False
; ===============================================================================================================================
Func _Toast_WM_EVENTS($hWnd, $Msg, $wParam, $lParam)

    #forceref $wParam, $lParam
    If $hWnd = $hToast_Handle Then
        If $Msg = 0x0021 Then ; $WM_MOUSEACTIVATE
            ; Check mouse position
            Local $aPos = GUIGetCursorInfo($hToast_Handle)
            If $aPos[4] = $hToast_Close_X Then $fToast_Close = True
        EndIf
    EndIf
    Return 'GUI_RUNDEFMSG'

EndFunc; => _Toast_WM_EVENTS

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_GetDefFont
; Description ...: Determine system default MsgBox font and size
; Syntax ........: _Toast_GetDefFont($iData)
; Parameters ....: $iData - 0 = Font point size, 1 = Font name
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast functions
; ===============================================================================================================================
Func _Toast_GetDefFont($iData)

    ; Get default system font data
    Local $tNONCLIENTMETRICS = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
    DLLStructSetData($tNONCLIENTMETRICS, 1, DllStructGetSize($tNONCLIENTMETRICS))
    DLLCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($tNONCLIENTMETRICS), "ptr", DllStructGetPtr($tNONCLIENTMETRICS), "int", 0)
    ; Read font data for MsgBox font
    Local $tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DLLStructGetPtr($tNONCLIENTMETRICS, 15))
    Switch $iData
        Case 0
            ; Font size as integer
            Return Int((Abs(DllStructGetData($tLOGFONT, 1)) + 1) * .75)
        Case 1
            ; Font name
            Return DllStructGetData($tLOGFONT, 14)
    EndSwitch

EndFunc ;=>_Toast_GetDefFont

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Title_Gradient
; Description ...: Fills the Title bar with a user-defined 2 colour gradient
; Syntax ........: _Toast_Title_Gradient($hWnd, $iX, $iY)
; Parameters ....: $hWnd - The Pic control to colour
;                  $iX   - The width of the Title bar
;                  $iY   - The height of the Title bar
; Author ........: Melba23, based on Yashied's WinAPIEx functions
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show when a gradient is required
; ===============================================================================================================================
Func _Toast_Title_Gradient($hWnd, $iX, $iY)

    Local $aVertex [2][3] = [[0, 0, $vToast_Header_BkCol[0]], [$iX, $iY, $vToast_Header_BkCol[1]]]

    ; Create gradient
    $hDC = _WinAPI_GetDC($hWnd)
    $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iX, $iY)
    $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
    _WinAPI_GradientFill($hDestDC, $aVertex, 0, 1, True)

    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hDestDC, $hDestSv)
    _WinAPI_DeleteDC($hDestDC)

    ; Set gradient to control
    _SendMessage($hWnd, 0x0172, 0, $hBitmap) ; $STM_SETIMAGE
    $hObj = _SendMessage($hWnd, 0x0173) ; $STM_GETIMAGE
    If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf

EndFunc

And a short example script:

#include "Toast.au3"

Local $sMsg, $aRet[2]

$sMsg  = "This Toast has a solid title bar." & @CRLF & @CRLF
$sMsg &= "It is easy to choose the colours for the bar and the text to "
$sMsg &= "ensure you can see both the text and the closure [X]"

_Toast_Set(0, 0xFF0000, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show(0, "Gradient Title Bar", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & @CRLF)

$sMsg  = "This Toast has a gradient filled title bar." & @CRLF & @CRLF
$sMsg &= "But you must choose the colours for the bar and the text carefully "
$sMsg &= "or you may have difficulty seeing both the text and the closure [X] "
$sMsg &= "as in this example"

Global $aColours[2] = [0xFF0000, 0x00FFFF]

_Toast_Set(5, $aColours, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show(0, "Gradient Title Bar", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & @CRLF)
_Toast_Hide()

$sMsg  = "And back to solid again"

_Toast_Set(0, 0xFF0000, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show(0, "Solid Title Bar", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & @CRLF)

I am not going to put this as a formal release because it relies on Yashied's WinAPIEx functions for the gradient and so that file needs to be included, which goes against my wish to reduce the includes to a minimum. I realise that it would be relatively trivial to extract the relevant functions from WinAPIEx and have them as #INTERNAL_USE_ONLY# functions within this UDF, but I am not overly keen on doing that. It seems a bit disrespectful to to the original authors. Besides, it gives you something to do if you find yourself at a loose end! :D

M23

Edit: Altered _WinAPI_FreeObject to _WinAPI_DeleteObject following Yashied's change to the WinAPIEx library. Thanks to 4ggr35510n for pointing it out. :huggles:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba,

I hope you don't mind me doing this, but I added an optional parameter on the _Toast_Set() function to control which way the gradient flows.

#include-once

; #INDEX# ============================================================================================================
; Title .........: Toast
; AutoIt Version : 3.3.2.0 - uses AdlibRegister/Unregister
; Language ......: English
; Description ...: Show and hides slice messages from the systray in user defined colours and fonts
; Author(s) .....: Melba23.  Credit to GioVit (tray location)
; ====================================================================================================================

;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

; #INCLUDES# =========================================================================================================
#include "StringSize.au3"
#include <WinAPIEx.au3>

; #GLOBAL VARIABLES# =================================================================================================
Global $iDef_Toast_Font_Size   = _Toast_GetDefFont(0)
Global $sDef_Toast_Font_Name   = _Toast_GetDefFont(1)

Global $hToast_Handle        = 0
Global $hToast_Close_X       = 9999
Global $iToast_Move          = 0
Global $iToast_Style         = 1 ; $SS_CENTER
Global $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
Global $vToast_Header_BkCol[2]  = [$aRet[0], ""]
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
Global $iToast_Header_Col    = $aRet[0]
Global $iToast_Header_Bold   = 0
Global $iToast_Message_BkCol = $iToast_Header_Col
Global $iToast_Message_Col   = $vToast_Header_BkCol[01]
Global $iToast_Grad_Style    = 0 ; Added by JamesBrooks
Global $iToast_Font_Size     = $iDef_Toast_Font_Size
Global $sToast_Font_Name     = $sDef_Toast_Font_Name
Global $iToast_Timer         = 0
Global $iToast_Start         = 0
Global $fToast_Close         = False

; #CURRENT# ==========================================================================================================
; _Toast_Set:  Sets text justification and optionally colours and font, for _Toast_Show function calls
; _Toast_Show: Shows a slice message from the systray
; _Toast_Hide: Hides a slice message from the systray
; ====================================================================================================================

; #INTERNAL_USE_ONLY#=================================================================================================
; _Toast_Locate:        Find Systray and determine Toast start position and movement direction
; _Toast_Timer_Check:   Checks whether Toast has timed out or closure [X] clicked
; _Toast_WM_EVENTS:     Message handler to check if closure [X] clicked
; _Toast_GetDefFont:    Determine system default MsgBox font and size
; _Toast_Title_Gradient Fills the Title bar with a user-defined 2 colour gradient
; ====================================================================================================================

; #FUNCTION# =========================================================================================================
; Name...........: _Toast_Set
; Description ...: Sets text justification and optionally colours and font, for _Toast_Show function calls
; Syntax.........: _Toast_Set($vJust, [$vHdr_BkCol, [$iHdr_Col, [$iMsg_BkCol, [$iMsg_Col, [$sFont_Size, [$iFont_Name [, $fGrad]]]]]]])
; Parameters ....: $vJust     - 0 = Left justified, 1 = Centred (Default), 2 = Right justified
;                                Can use $SS_LEFT, $SS_CENTER, $SS_RIGHT
;                                + 4 = Header text in bold
;                       >>>>>    Setting this parameter to' Default' will reset ALL parameters to default values     <<<<<
;                       >>>>>    All optional parameters default to system MsgBox default values                     <<<<<
;                  $vHdr_BkCol - [Optional] The colour for the title bar background
;                                - If a single colour then the title bar is set to that colour
;                                - If a 2-element array, the title bar is set to a L-R gradient between the 2 colours
;                  $iHdr_Col   - [Optional] The colour for the title bar text
;                  $iMsg_BkCol - [Optional] The colour for the message background
;                  $iMsg_Col   - [Optional] The colour for the message text
;                                Omitting a colour parameter or setting it to -1 leaves it unchanged
;                                Setting a colour parameter to Default resets the system colour
;                  $iFont_Size - [Optional] The font size in points to use for the Toast
;                  $sFont_Name - [Optional] The font to use for the Toast
;                       >>>>>    Omitting a font parameter, setting size to -1 or name to "" leaves it unchanged     <<<<<
;                       >>>>>    Setting a font parameter to Default resets the system message box font or size      <<<<<
;                  $sFont_Name - [Optional] The direction to set the background gradient
;                              - True, set the direction to left and right
;                              - False, set the direction to top to bottom
; Requirement(s).: v3.3.2.0 or higher - AdlibRegister/Unregister used in _Toast_Show
; Return values .: Success - Returns 1
;                  Failure - Returns 0 and sets @error to 1 with @extended set to parameter index number
; Author ........: Melba23
; Modified ......; JamesBrooks, added $fGrad to control gradient direction
; Example........; Yes
;=====================================================================================================================

Func _Toast_Set($vJust, $vHdr_BkCol = -1, $iHdr_Col = -1, $iMsg_BkCol = -1, $iMsg_Col = -1, $iFont_Size = -1, $sFont_Name = "", $fGrad = False)

    ; Set parameters
    Switch $vJust
        Case Default
            $iToast_Style         = 1; $SS_CENTER
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $vToast_Header_BkCol[0]  = $aRet[0]
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iToast_Header_Col    = $aRet[0]
            $iToast_Message_BkCol = $iToast_Header_Col
            $iToast_Message_Col   = $vToast_Header_BkCol[0]
            $sToast_Font_Name     = $sDef_Toast_Font_Name
            $iToast_Font_Size     = $iDef_Toast_Font_Size
            Return
        Case 0, 1, 2, 4, 5, 6
            $iToast_Style = $vJust
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 1, 0)
    EndSwitch

    If IsArray($vHdr_BkCol) Then
        If UBound($vHdr_BkCol) <> 2 Then Return SetError(1, 2, 0)
        For $i = 0 To 1
            Switch $vHdr_BkCol[$i]
                Case 0 To 0xFFFFFF
                    ; Valid
                Case Else
                    Return SetError(1, 2, 0)
            EndSwitch
        Next
        ; Must be valid array
        $vToast_Header_BkCol = $vHdr_BkCol
    Else
        Switch $vHdr_BkCol
            Case Default
                $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
                $vToast_Header_BkCol[0]  = $aRet[0]
            Case 0 To 0xFFFFFF
                $vToast_Header_BkCol[0] = Int($vHdr_BkCol)
            Case -1
                ; Do nothing
            Case Else
                Return SetError(1, 2, 0)
        EndSwitch
        ; Set the second element to "" as a flag
        $vToast_Header_BkCol[1]  = ""
    EndIf

    Switch $iHdr_Col
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iToast_Header_Col  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Header_Col = Int($iHdr_Col)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 3, 0)
    EndSwitch

    Switch $iMsg_BkCol
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iToast_Message_BkCol  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Message_BkCol = Int($iMsg_BkCol)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 4, 0)
    EndSwitch

    Switch $iMsg_Col
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iToast_Message_Col  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Message_Col = Int($iMsg_Col)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 5, 0)
    EndSwitch

    Switch $iFont_Size
        Case Default
            $iToast_Font_Size = $iDef_Toast_Font_Size
        Case 8 To 72
            $iToast_Font_Size = Int($iFont_Size)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 6, 0)
    EndSwitch

    Switch $sFont_Name
        Case Default
            $sToast_Font_Name = $sDef_Toast_Font_Name
        Case ""
            ; Do nothing
        Case Else
            If IsString($sFont_Name) Then
                $sToast_Font_Name = $sFont_Name
            Else
                Return SetError(1, 7, 0)
            EndIf
    EndSwitch

    Switch $fGrad
        Case Default
            $iToast_Grad_Style = False
        Case True
            $iGrad_Type = True ; Left to right
        Case False
            $iGrad_Type = False ; Top to bottom
        Case Else
            Return SetError(1, 8, 0)
    EndSwitch

    Return 1
EndFunc ; => _Toast_Set

; #FUNCTION# =========================================================================================================
; Name...........: _Toast_Show
; Description ...: Shows a slice message from the systray
; Syntax.........: _Toast_Show($vIcon, $sTitle, $sMessage, [$iDelay [, $fWait [, $fRaw]]])
; Parameters ....: $vIcon    - 0 - No icon, 8 - UAC, 16 - Stop, 32 - Query, 48 - Exclamation, 64 - Information
;                              The $MB_ICON constant can also be used for the last 4 above
;                              If set to the name of an exe, the main icon of that exe will be displayed
;                              Any other value returns -1, error 1
;                  $sTitle   - Text to display on Title bar
;                  $sMessage - Text to display in Toast body
;                  $iDelay   - The delay in seconds before the Toast retracts or script continues (Default = 0)
;                              If negative, an [X] is added to the title bar. Clicking [X] retracts/continues immediately
;                  $fWait    - True  - Script waits for delay time before continuing and Toast remains visible (default)
;                            - False - Script continues and Toast retracts automatically after delay time
;                  $fRaw     - True  - Message is not wrapped and Toast expands to show full width
;                            - False - Message is wrapped if over max preset Toast width
; Requirement(s).: v3.3.1.5 or higher - AdlibRegister/Unregister used in _Toast_Show
; Return values .: Success: Returns 2-element array: [Toast width, Toast height]
;                  Failure: Returns -1 and sets @error as follows:
;                           1 = Toast GUI creation failed
;                           2 = Taskbar not found
;                           3 = StringSize error
;                           4 = When using Raw, the Toast is too wide for the display
; Author ........: Melba23, based on some original code by GioVit for the Toast
; Notes .........; Any visible Toast is retracted by a subsequent _Toast_Hide or _Toast_Show, or clicking a visible [X]
; Example........; Yes
;=====================================================================================================================

Func _Toast_Show($vIcon, $sTitle, $sMessage, $iDelay = 0, $fWait = True, $fRaw = False)

    ; Store current GUI mode and set Message mode
    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    ; Retract any Toast already in place
    If $hToast_Handle <> 0 Then _Toast_Hide()

    ; Reset non-reacting Close [X] ControlID
    $hToast_Close_X = 9999

    ; Set minimum Toast widths
    Local $iToast_Width_max = 500
    Local $iToast_Width_min = 150

    ; Check for icon
    Local $iIcon_Style = 0
    Local $iIcon_Reduction = 50
    Local $sDLL = "user32.dll"
    If StringIsDigit($vIcon) Then
        Switch $vIcon
            Case 0
                $iIcon_Reduction = 0
            Case 8
                $sDLL = "imageres.dll"
                $iIcon_Style = 78
            Case 16 ; Stop
                $iIcon_Style = -4
            Case 32 ; Query
                $iIcon_Style = -3
            Case 48 ; Exclam
                $iIcon_Style = -2
            Case 64 ; Info
                $iIcon_Style = -5
            Case Else
                $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(1, 0, -1)
        EndSwitch
    Else
        $sDLL = $vIcon
        $iIcon_Style = 0
    EndIf

    ; Determine max message width
    Local $iMax_Label_Width = $iToast_Width_max - 20 - $iIcon_Reduction
    If $fRaw = True Then $iMax_Label_Width = 0

    ; Get message label size
    Local $aLabel_Pos = _StringSize($sMessage, $iToast_Font_Size, Default, Default, $sToast_Font_Name, $iMax_Label_Width)
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(3, 0, -1)
    EndIf

    ; Set text to match rectangle
    $sMessage = $aLabel_Pos[0]

    ;Set line height for this font
    Local $iLine_Height = $aLabel_Pos[1]

    ; Set label size
    Local $iLabelwidth  = $aLabel_Pos[2]
    Local $iLabelheight = $aLabel_Pos[3]

    ; Set Toast size
    Local $iToast_Width = $iLabelwidth + 20 + $iIcon_Reduction
    ; Check if Toast will fit on screen
    If $iToast_Width > @DesktopWidth - 20 Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(4, 0, -1)
    EndIf

    If $iToast_Width < $iToast_Width_min + $iIcon_Reduction Then
        ; Increase if below min size
        $iToast_Width = $iToast_Width_min + $iIcon_Reduction
        $iLabelwidth  = $iToast_Width_min - 20
    EndIf

    ; Set title bar height - with minimum for [X]
    Local $iTitle_Height = 0
    If $sTitle = "" Then
        If $iDelay < 0 Then $iTitle_Height = 6
    Else
        $iTitle_Height = $iLine_Height + 2
        If $iDelay < 0 Then
            If $iTitle_Height < 17 Then $iTitle_Height = 17
        EndIf
    EndIf

    ; Set Toast height as label height + title bar + bottom margin
    Local $iToast_Height = $iLabelheight + $iTitle_Height + 20
    ; Ensure enough room for icon if displayed
    If $iIcon_Reduction Then
        If $iToast_Height < $iTitle_Height + 42 Then $iToast_Height = $iTitle_Height + 47
    EndIf

    ; Get Toast starting position and direction
    Local $aToast_Data = _Toast_Locate($iToast_Width, $iToast_Height)

    ; Create Toast slice with $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW style and $WS_EX_TOPMOST extended style
    $hToast_Handle = GUICreate("", $iToast_Width, $iToast_Height, $aToast_Data[0], $aToast_Data[1], 0x80880000, BitOr(0x00000080, 0x00000008))
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(1, 0, -1)
    EndIf
        GUISetFont($iToast_Font_Size, Default, Default, $sToast_Font_Name)
        GUISetBkColor($iToast_Message_BkCol)

    ; Set centring parameter
    Local $iLabel_Style = 0 ; $SS_LEFT
    If BitAND($iToast_Style, 1) = 1 Then
        $iLabel_Style = 1 ; $SS_CENTER
    ElseIf BitAND($iToast_Style, 2) = 2 Then
        $iLabel_Style = 2 ; $SS_RIGHT
    EndIf

    ; Check installed fonts
    Local $sX_Font = "WingDings"
    Local $sX_Char = "x"
    Local $i = 1
    While 1
        Local $sInstalled_Font = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $i)
        If @error Then ExitLoop
        If StringInStr($sInstalled_Font, "WingDings 2") Then
            $sX_Font = "WingDings 2"
            $sX_Char = "T"
        EndIf
        $i += 1
    WEnd

    ; Create title bar if required
    If $sTitle <> "" Then

        ; Create disabled background strip
        If $vToast_Header_BkCol[1] = "" Then
            ; Want solid
            GUICtrlCreateLabel("", 0, 0, $iToast_Width, $iTitle_Height)
                GUICtrlSetBkColor(-1, $vToast_Header_BkCol[0])
                    GUICtrlSetState(-1, 128) ; $GUI_DISABLE
        Else
            ; Want gradient
            Local $hPic = GUICtrlCreatePic("", 0, 0, $iToast_Width, $iTitle_Height)
                GUICtrlSetState(-1, 128) ; $GUI_DISABLE
                _Toast_Title_Gradient(GUICtrlGetHandle($hPic), $iToast_Width, $iTitle_Height)
        EndIf

        ; Set title bar width to offset text
        Local $iTitle_Width = $iToast_Width - 10

        ; Create closure [X] if needed
        If $iDelay < 0 Then
            ; Create [X]
            Local $iX_YCoord = Int(($iTitle_Height - 17) / 2)
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, $iX_YCoord, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Header_Col)
            ; Reduce title bar width to allow [X] to activate
            $iTitle_Width -= 18
        EndIf

        ; Create Title label with bold text, centred vertically in case bar is higher than line
        GUICtrlCreateLabel($sTitle, 10, 0, $iTitle_Width, $iTitle_Height, 0x0200) ; $SS_CENTERIMAGE
            GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
            GUICtrlSetColor(-1, $iToast_Header_Col)
            If BitAND($iToast_Style, 4) = 4 Then GUICtrlSetFont(-1, $iToast_Font_Size, 600)

    Else

        If $iDelay < 0 Then
            ; Only need [X]
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, 0, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Message_Col)
        EndIf

    EndIf

    ; Create icon
    If $iIcon_Reduction Then GUICtrlCreateIcon($sDLL, $iIcon_Style, 10, 10 + $iTitle_Height)

    ; Create Message label
    GUICtrlCreateLabel($sMessage, 10 + $iIcon_Reduction, 10 + $iTitle_Height, $iLabelwidth, $iLabelheight)
        GUICtrlSetStyle(-1, $iLabel_Style)
        If $iToast_Message_Col <> Default Then GUICtrlSetColor(-1, $iToast_Message_Col)

    ; Slide Toast Slice into view from behind systray and activate
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 1000, "long", $aToast_Data[2])

    ; Activate Toast without stealing focus
    GUISetState(@SW_SHOWNOACTIVATE, $hToast_Handle)

    ; If script is to pause
    If $fWait = True Then

        ; Begin timeout counter
        Local $iTimeout_Begin = TimerInit()

        ; Wait for timeout or closure
        While 1
            If GUIGetMsg() = $hToast_Close_X Or TimerDiff($iTimeout_Begin) / 1000 >= Abs($iDelay) Then ExitLoop
        WEnd

    ; If script is to continue and delay has been set
    ElseIf Abs($iDelay) > 0 Then

        ; Store timer info
        $iToast_Timer = Abs($iDelay * 1000)
        $iToast_Start = TimerInit()

        ; Register Adlib function to run timer
        AdlibRegister("_Toast_Timer_Check", 100)
        ; Register message handler to check for [X] click
        GUIRegisterMsg(0x0021, "_Toast_WM_EVENTS") ; $WM_MOUSEACTIVATE

    EndIf

    ; Reset original mode
    $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)

    ; Create array to return Toast dimensions
    Local $aToast_Data[3] = [$iToast_Width, $iToast_Height, $iLine_Height]

    Return $aToast_Data

EndFunc ; => _Toast_Show

; #FUNCTION# ========================================================================================================
; Name...........: _Toast_Hide
; Description ...: Hides a slice message from the systray
; Syntax.........: _Toast_Hide()
; Requirement(s).: v3.3.1.5 or higher - AdlibRegister used in _Toast_Show
; Return values .: Success: Returns 0
;                  Failure: If Toast does not exist returns -1 and sets @error to 1
; Author ........: Melba23
; Example........; Yes
;=====================================================================================================================

Func _Toast_Hide()

    ; If no Toast to hide, return
    If $hToast_Handle = 0 Then Return SetError(1, 0, -1)

    ; Slide Toast back behind systray
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 500, "long", $iToast_Move)

    ; Delete Toast slice
    GUIDelete($hToast_Handle)

    ; Set flag for "no Toast"
    $hToast_Handle = 0

EndFunc ; => _Toast_Hide

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Locate
; Description ...: Find Systray and determine Toast start position and movement direction
; Syntax ........: _Toast_Locate($iToast_Width, $iToast_Height)
; Parameters ....: $iToast_Width  - required width of slice
;                  $iToast_Height - required height of slice
; Author ........: Melba23, based on some original code by GioVit
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show
; ===============================================================================================================================
Func _Toast_Locate($iToast_Width, $iToast_Height)

    ; Define return array
    Local $aToast_Data[3]

    ; Find systray
    Local $iPrevMode = Opt("WinTitleMatchMode", 4)
    Local $aTray_Pos = WinGetPos("[CLASS:Shell_TrayWnd]")
    Opt("WinTitleMatchMode", $iPrevMode)

    ; If error in finding systray
    If Not IsArray($aTray_Pos) Then Return SetError(2, 0, -1)

    ; Determine direction of Toast motion and starting position
    If $aTray_Pos[1] > 0 Then
        $iToast_Move = 0x00050004 ; $AW_SLIDE_OUT_BOTTOM
        $aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
        $aToast_Data[1] = $aTray_Pos[1] - $iToast_Height
        $aToast_Data[2] = 0x00040008 ; $AW_SLIDE_IN_BOTTOM
    Elseif $aTray_Pos[0] > 0 Then
        $iToast_Move = 0x00050001 ; $AW_SLIDE_OUT_RIGHT
        $aToast_Data[0] = $aTray_Pos[0] - $iToast_Width
        $aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
        $aToast_Data[2] = 0x00040002 ; $AW_SLIDE_IN_RIGHT
    ElseIf $aTray_Pos[2] = @DesktopWidth Then
        $iToast_Move = 0x00050008 ; $AW_SLIDE_OUT_TOP
        $aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
        $aToast_Data[1] = $aTray_Pos[1] + $aTray_Pos[3]
        $aToast_Data[2] = 0x00040004 ; $AW_SLIDE_IN_TOP
    ElseIf $aTray_Pos[3] = @DesktopHeight Then
        $iToast_Move = 0x00050002 ; $AW_SLIDE_OUT_LEFT
        $aToast_Data[0] = $aTray_Pos[0] + $aTray_Pos[2]
        $aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
        $aToast_Data[2] = 0x00040001 ; $AW_SLIDE_IN_LEFT
    EndIf

    Return $aToast_Data

EndFunc ; => _Toast_Locate

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Timer_Check
; Description ...: Checks whether Toast has timed out or closure [X] clicked
; Syntax ........: _Toast_Locate($iToast_Width, $iToast_Height)
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show if the Wait parameter is set to False
; ===============================================================================================================================
Func _Toast_Timer_Check()

    ; Return if timeout not elapsed and [X] not clicked
    If TimerDiff($iToast_Start) < $iToast_Timer And $fToast_Close = False Then Return

    ; Unregister message handler
    GUIRegisterMsg(0x0021, "") ; $WM_MOUSEACTIVATE
    ; Unregister this function
    AdlibUnRegister("_Toast_Timer_Check")
    ; Reset flag
    $fToast_Close = False
    ; Retract slice
    _Toast_Hide()

EndFunc; => _Toast_Timer_Check

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_WM_EVENTS
; Description ...: Message handler to check if closure [X] clicked
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show if the Wait parameter is set to False
; ===============================================================================================================================
Func _Toast_WM_EVENTS($hWnd, $Msg, $wParam, $lParam)

    #forceref $wParam, $lParam
    If $hWnd = $hToast_Handle Then
        If $Msg = 0x0021 Then ; $WM_MOUSEACTIVATE
            ; Check mouse position
            Local $aPos = GUIGetCursorInfo($hToast_Handle)
            If $aPos[4] = $hToast_Close_X Then $fToast_Close = True
        EndIf
    EndIf
    Return 'GUI_RUNDEFMSG'

EndFunc; => _Toast_WM_EVENTS

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_GetDefFont
; Description ...: Determine system default MsgBox font and size
; Syntax ........: _Toast_GetDefFont($iData)
; Parameters ....: $iData - 0 = Font point size, 1 = Font name
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast functions
; ===============================================================================================================================
Func _Toast_GetDefFont($iData)

    ; Get default system font data
    Local $tNONCLIENTMETRICS = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
    DLLStructSetData($tNONCLIENTMETRICS, 1, DllStructGetSize($tNONCLIENTMETRICS))
    DLLCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($tNONCLIENTMETRICS), "ptr", DllStructGetPtr($tNONCLIENTMETRICS), "int", 0)
    ; Read font data for MsgBox font
    Local $tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DLLStructGetPtr($tNONCLIENTMETRICS, 15))
    Switch $iData
        Case 0
            ; Font size as integer
            Return Int((Abs(DllStructGetData($tLOGFONT, 1)) + 1) * .75)
        Case 1
            ; Font name
            Return DllStructGetData($tLOGFONT, 14)
    EndSwitch

EndFunc ;=>_Toast_GetDefFont

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Title_Gradient
; Description ...: Fills the Title bar with a user-defined 2 colour gradient
; Syntax ........: _Toast_Title_Gradient($hWnd, $iX, $iY, $iStyle)
; Parameters ....: $hWnd   - The Pic control to colour
;                  $iX     - The width of the Title bar
;                  $iY     - The height of the Title bar
;                  $iStyle - The direction of the gradient
; Author ........: Melba23, based on Yashied's WinAPIEx functions
; Modified.......: JamesBrooks, added direction
; Remarks .......: This function is used internally by _Toast_Show when a gradient is required
; ===============================================================================================================================
Func _Toast_Title_Gradient($hWnd, $iX, $iY)

    Local $aVertex [2][3] = [[0, 0, $vToast_Header_BkCol[0]], [$iX, $iY, $vToast_Header_BkCol[1]]]

    ; Create gradient
    $hDC = _WinAPI_GetDC($hWnd)
    $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iX, $iY)
    $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
    _WinAPI_GradientFill($hDestDC, $aVertex, 0, 1, $iToast_Grad_Style)

    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hDestDC, $hDestSv)
    _WinAPI_DeleteDC($hDestDC)

    ; Set gradient to control
    _SendMessage($hWnd, 0x0172, 0, $hBitmap) ; $STM_SETIMAGE
    $hObj = _SendMessage($hWnd, 0x0173) ; $STM_GETIMAGE
    If $hObj <> $hBitmap Then
        _WinAPI_FreeObject($hBitmap)
    EndIf

EndFunc
The two modified functions are:

  • _Toast_Set()
The new parameters for _Toast_Set() are outlined as:

_Toast_Set($vJust, [$vHdr_BkCol, [$iHdr_Col, [$iMsg_BkCol, [$iMsg_Col, [$sFont_Size, [$iFont_Name [, $fGrad]]]]]]])

Thinking about it, I may have put the option in the wrong place... Perhaps it should have been on the _Toast_Set() function along with the colours. I changed it around. It now works on _Toast_Set().

James

Edited by JamesBrooks
Link to comment
Share on other sites

  • Moderators

James,

Feel free to modify the UDF as much as you like - that is why I posted it. :D

However, rather than add yet another parameter to _Toast_Set, I would have added a third element to the array needed to define the colours - then when you define the colours for the gradient, you can define the direction at the same time. Something like this:

#include-once

; #INDEX# ============================================================================================================
; Title .........: Toast
; AutoIt Version : 3.3.2.0 - uses AdlibRegister/Unregister
; Language ......: English
; Description ...: Show and hides slice messages from the systray in user defined colours and fonts
; Author(s) .....: Melba23.  Credit to GioVit (tray location)
; ====================================================================================================================

;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

; #INCLUDES# =========================================================================================================
#include <StringSize.au3>

#include <WinAPIEx.au3>

; #GLOBAL VARIABLES# =================================================================================================
Global $iDef_Toast_Font_Size   = _Toast_GetDefFont(0)
Global $sDef_Toast_Font_Name   = _Toast_GetDefFont(1)

Global $hToast_Handle        = 0
Global $hToast_Close_X       = 9999
Global $iToast_Move          = 0
Global $iToast_Style         = 1 ; $SS_CENTER
Global $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
Global $vToast_Header_BkCol[3]  = [$aRet[0], "", ""]
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
Global $iToast_Header_Col    = $aRet[0]
Global $iToast_Header_Bold   = 0
Global $iToast_Message_BkCol = $iToast_Header_Col
Global $iToast_Message_Col   = $vToast_Header_BkCol[01]
Global $iToast_Font_Size     = $iDef_Toast_Font_Size
Global $sToast_Font_Name     = $sDef_Toast_Font_Name
Global $iToast_Timer         = 0
Global $iToast_Start         = 0
Global $fToast_Close         = False

; #CURRENT# ==========================================================================================================
; _Toast_Set:  Sets text justification and optionally colours and font, for _Toast_Show function calls
; _Toast_Show: Shows a slice message from the systray
; _Toast_Hide: Hides a slice message from the systray
; ====================================================================================================================

; #INTERNAL_USE_ONLY#=================================================================================================
; _Toast_Locate:        Find Systray and determine Toast start position and movement direction
; _Toast_Timer_Check:   Checks whether Toast has timed out or closure [X] clicked
; _Toast_WM_EVENTS:     Message handler to check if closure [X] clicked
; _Toast_GetDefFont:    Determine system default MsgBox font and size
; _Toast_Title_Gradient Fills the Title bar with a user-defined 2 colour gradient
; ====================================================================================================================

; #FUNCTION# =========================================================================================================
; Name...........: _Toast_Set
; Description ...: Sets text justification and optionally colours and font, for _Toast_Show function calls
; Syntax.........: _Toast_Set($vJust, [$vHdr_BkCol, [$iHdr_Col, [$iMsg_BkCol, [$iMsg_Col, [$sFont_Size, [$iFont_Name]]]]]])
; Parameters ....: $vJust     - 0 = Left justified, 1 = Centred (Default), 2 = Right justified
;                                Can use $SS_LEFT, $SS_CENTER, $SS_RIGHT
;                                + 4 = Header text in bold
;                       >>>>>    Setting this parameter to' Default' will reset ALL parameters to default values     <<<<<
;                       >>>>>    All optional parameters default to system MsgBox default values                     <<<<<
;                  $vHdr_BkCol - [Optional] The colour for the title bar background
;                                - If a single colour then the title bar is set to that colour
;                                - If a 3-element array, the title bar is set to a gradient between the 2 colours
;                                  - Elements 0 and 1 = colours, element 2 = Gradient direction (True (L-R) or False (Top-Down))
;                  $iHdr_Col   - [Optional] The colour for the title bar text
;                  $iMsg_BkCol - [Optional] The colour for the message background
;                  $iMsg_Col   - [Optional] The colour for the message text
;                                Omitting a colour parameter or setting it to -1 leaves it unchanged
;                                Setting a colour parameter to Default resets the system colour
;                  $iFont_Size - [Optional] The font size in points to use for the Toast
;                  $sFont_Name - [Optional] The font to use for the Toast
;                       >>>>>    Omitting a font parameter, setting size to -1 or name to "" leaves it unchanged     <<<<<
;                       >>>>>    Setting a font parameter to Default resets the system message box font or size      <<<<<
; Requirement(s).: v3.3.2.0 or higher - AdlibRegister/Unregister used in _Toast_Show
; Return values .: Success - Returns 1
;                  Failure - Returns 0 and sets @error to 1 with @extended set to parameter index number
; Author ........: Melba23
; Example........; Yes
;=====================================================================================================================

Func _Toast_Set($vJust, $vHdr_BkCol = -1, $iHdr_Col = -1, $iMsg_BkCol = -1, $iMsg_Col = -1, $iFont_Size = -1, $sFont_Name = "")

    ; Set parameters
    Switch $vJust
        Case Default
            $iToast_Style         = 1; $SS_CENTER
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $vToast_Header_BkCol[0]  = $aRet[0]
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iToast_Header_Col    = $aRet[0]
            $iToast_Message_BkCol = $iToast_Header_Col
            $iToast_Message_Col   = $vToast_Header_BkCol[0]
            $sToast_Font_Name     = $sDef_Toast_Font_Name
            $iToast_Font_Size     = $iDef_Toast_Font_Size
            Return
        Case 0, 1, 2, 4, 5, 6
            $iToast_Style = $vJust
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 1, 0)
    EndSwitch

    If IsArray($vHdr_BkCol) Then
        If UBound($vHdr_BkCol) <> 3 Then Return SetError(1, 2, 0)
        For $i = 0 To 1
            Switch $vHdr_BkCol[$i]
                Case 0 To 0xFFFFFF
                    ; Valid
                Case Else
                    Return SetError(1, 2, 0)
            EndSwitch
            $vToast_Header_BkCol[2] = True
            If $vHdr_BkCol[2] = False Then $vToast_Header_BkCol[2] = False
        Next
        ; Must be valid array
        $vToast_Header_BkCol = $vHdr_BkCol
    Else
        Switch $vHdr_BkCol
            Case Default
                $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
                $vToast_Header_BkCol[0]  = $aRet[0]
            Case 0 To 0xFFFFFF
                $vToast_Header_BkCol[0] = Int($vHdr_BkCol)
            Case -1
                ; Do nothing
            Case Else
                Return SetError(1, 2, 0)
        EndSwitch
        ; Set the second element to "" as a flag
        $vToast_Header_BkCol[1]  = ""
    EndIf

    Switch $iHdr_Col
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iToast_Header_Col  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Header_Col = Int($iHdr_Col)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 3, 0)
    EndSwitch

    Switch $iMsg_BkCol
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iToast_Message_BkCol  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Message_BkCol = Int($iMsg_BkCol)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 4, 0)
    EndSwitch

    Switch $iMsg_Col
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iToast_Message_Col  = $aRet[0]
        Case 0 To 0xFFFFFF
            $iToast_Message_Col = Int($iMsg_Col)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 5, 0)
    EndSwitch

    Switch $iFont_Size
        Case Default
            $iToast_Font_Size = $iDef_Toast_Font_Size
        Case 8 To 72
            $iToast_Font_Size = Int($iFont_Size)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 6, 0)
    EndSwitch

    Switch $sFont_Name
        Case Default
            $sToast_Font_Name = $sDef_Toast_Font_Name
        Case ""
            ; Do nothing
        Case Else
            If IsString($sFont_Name) Then
                $sToast_Font_Name = $sFont_Name
            Else
                Return SetError(1, 7, 0)
            EndIf
    EndSwitch

    Return 1

EndFunc ; => _Toast_Set

; #FUNCTION# =========================================================================================================
; Name...........: _Toast_Show
; Description ...: Shows a slice message from the systray
; Syntax.........: _Toast_Show($vIcon, $sTitle, $sMessage, [$iDelay [, $fWait [, $fRaw]]])
; Parameters ....: $vIcon    - 0 - No icon, 8 - UAC, 16 - Stop, 32 - Query, 48 - Exclamation, 64 - Information
;                              The $MB_ICON constant can also be used for the last 4 above
;                              If set to the name of an exe, the main icon of that exe will be displayed
;                              Any other value returns -1, error 1
;                  $sTitle   - Text to display on Title bar
;                  $sMessage - Text to display in Toast body
;                  $iDelay   - The delay in seconds before the Toast retracts or script continues (Default = 0)
;                              If negative, an [X] is added to the title bar. Clicking [X] retracts/continues immediately
;                  $fWait    - True  - Script waits for delay time before continuing and Toast remains visible (default)
;                              False - Script continues and Toast retracts automatically after delay time
;                  $fRaw     - True  - Message is not wrapped and Toast expands to show full width
;                            - False - Message is wrapped if over max preset Toast width
; Requirement(s).: v3.3.1.5 or higher - AdlibRegister/Unregister used in _Toast_Show
; Return values .: Success: Returns 2-element array: [Toast width, Toast height]
;                  Failure: Returns -1 and sets @error as follows:
;                           1 = Toast GUI creation failed
;                           2 = Taskbar not found
;                           3 = StringSize error
;                           4 = When using Raw, the Toast is too wide for the display
; Author ........: Melba23, based on some original code by GioVit for the Toast
; Notes .........; Any visible Toast is retracted by a subsequent _Toast_Hide or _Toast_Show, or clicking a visible [X]
; Example........; Yes
;=====================================================================================================================

Func _Toast_Show($vIcon, $sTitle, $sMessage, $iDelay = 0, $fWait = True, $fRaw = False)

    ; Store current GUI mode and set Message mode
    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    ; Retract any Toast already in place
    If $hToast_Handle <> 0 Then _Toast_Hide()

    ; Reset non-reacting Close [X] ControlID
    $hToast_Close_X = 9999

    ; Set minimum Toast widths
    Local $iToast_Width_max = 500
    Local $iToast_Width_min = 150

    ; Check for icon
    Local $iIcon_Style = 0
    Local $iIcon_Reduction = 50
    Local $sDLL = "user32.dll"
    If StringIsDigit($vIcon) Then
        Switch $vIcon
            Case 0
                $iIcon_Reduction = 0
            Case 8
                $sDLL = "imageres.dll"
                $iIcon_Style = 78
            Case 16 ; Stop
                $iIcon_Style = -4
            Case 32 ; Query
                $iIcon_Style = -3
            Case 48 ; Exclam
                $iIcon_Style = -2
            Case 64 ; Info
                $iIcon_Style = -5
            Case Else
                $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(1, 0, -1)
        EndSwitch
    Else
        $sDLL = $vIcon
        $iIcon_Style = 0
    EndIf

    ; Determine max message width
    Local $iMax_Label_Width = $iToast_Width_max - 20 - $iIcon_Reduction
    If $fRaw = True Then $iMax_Label_Width = 0

    ; Get message label size
    Local $aLabel_Pos = _StringSize($sMessage, $iToast_Font_Size, Default, Default, $sToast_Font_Name, $iMax_Label_Width)
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(3, 0, -1)
    EndIf

    ; Set text to match rectangle
    $sMessage = $aLabel_Pos[0]

    ;Set line height for this font
    Local $iLine_Height = $aLabel_Pos[1]

    ; Set label size
    Local $iLabelwidth  = $aLabel_Pos[2]
    Local $iLabelheight = $aLabel_Pos[3]

    ; Set Toast size
    Local $iToast_Width = $iLabelwidth + 20 + $iIcon_Reduction
    ; Check if Toast will fit on screen
    If $iToast_Width > @DesktopWidth - 20 Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(4, 0, -1)
    EndIf

    If $iToast_Width < $iToast_Width_min + $iIcon_Reduction Then
        ; Increase if below min size
        $iToast_Width = $iToast_Width_min + $iIcon_Reduction
        $iLabelwidth  = $iToast_Width_min - 20
    EndIf

    ; Set title bar height - with minimum for [X]
    Local $iTitle_Height = 0
    If $sTitle = "" Then
        If $iDelay < 0 Then $iTitle_Height = 6
    Else
        $iTitle_Height = $iLine_Height + 2
        If $iDelay < 0 Then
            If $iTitle_Height < 17 Then $iTitle_Height = 17
        EndIf
    EndIf

    ; Set Toast height as label height + title bar + bottom margin
    Local $iToast_Height = $iLabelheight + $iTitle_Height + 20
    ; Ensure enough room for icon if displayed
    If $iIcon_Reduction Then
        If $iToast_Height < $iTitle_Height + 42 Then $iToast_Height = $iTitle_Height + 47
    EndIf

    ; Get Toast starting position and direction
    Local $aToast_Data = _Toast_Locate($iToast_Width, $iToast_Height)

    ; Create Toast slice with $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW style and $WS_EX_TOPMOST extended style
    $hToast_Handle = GUICreate("", $iToast_Width, $iToast_Height, $aToast_Data[0], $aToast_Data[1], 0x80880000, BitOr(0x00000080, 0x00000008))
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(1, 0, -1)
    EndIf
        GUISetFont($iToast_Font_Size, Default, Default, $sToast_Font_Name)
        GUISetBkColor($iToast_Message_BkCol)

    ; Set centring parameter
    Local $iLabel_Style = 0 ; $SS_LEFT
    If BitAND($iToast_Style, 1) = 1 Then
        $iLabel_Style = 1 ; $SS_CENTER
    ElseIf BitAND($iToast_Style, 2) = 2 Then
        $iLabel_Style = 2 ; $SS_RIGHT
    EndIf

    ; Check installed fonts
    Local $sX_Font = "WingDings"
    Local $sX_Char = "x"
    Local $i = 1
    While 1
        Local $sInstalled_Font = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $i)
        If @error Then ExitLoop
        If StringInStr($sInstalled_Font, "WingDings 2") Then
            $sX_Font = "WingDings 2"
            $sX_Char = "T"
        EndIf
        $i += 1
    WEnd

    ; Create title bar if required
    If $sTitle <> "" Then

        ; Create disabled background strip
        If $vToast_Header_BkCol[1] = "" Then
            ; Want solid
            GUICtrlCreateLabel("", 0, 0, $iToast_Width, $iTitle_Height)
                GUICtrlSetBkColor(-1, $vToast_Header_BkCol[0])
                    GUICtrlSetState(-1, 128) ; $GUI_DISABLE
        Else
            ; Want gradient
            Local $hPic = GUICtrlCreatePic("", 0, 0, $iToast_Width, $iTitle_Height)
                GUICtrlSetState(-1, 128) ; $GUI_DISABLE
                _Toast_Title_Gradient(GUICtrlGetHandle($hPic), $iToast_Width, $iTitle_Height)
        EndIf

        ; Set title bar width to offset text
        Local $iTitle_Width = $iToast_Width - 10

        ; Create closure [X] if needed
        If $iDelay < 0 Then
            ; Create [X]
            Local $iX_YCoord = Int(($iTitle_Height - 17) / 2)
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, $iX_YCoord, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Header_Col)
            ; Reduce title bar width to allow [X] to activate
            $iTitle_Width -= 18
        EndIf

        ; Create Title label with bold text, centred vertically in case bar is higher than line
        GUICtrlCreateLabel($sTitle, 10, 0, $iTitle_Width, $iTitle_Height, 0x0200) ; $SS_CENTERIMAGE
            GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
            GUICtrlSetColor(-1, $iToast_Header_Col)
            If BitAND($iToast_Style, 4) = 4 Then GUICtrlSetFont(-1, $iToast_Font_Size, 600)

    Else

        If $iDelay < 0 Then
            ; Only need [X]
            $hToast_Close_X = GUICtrlCreateLabel($sX_Char, $iToast_Width - 18, 0, 17, 17)
                GUICtrlSetFont(-1, 14, Default, Default, $sX_Font)
                GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
                GUICtrlSetColor(-1, $iToast_Message_Col)
        EndIf

    EndIf

    ; Create icon
    If $iIcon_Reduction Then GUICtrlCreateIcon($sDLL, $iIcon_Style, 10, 10 + $iTitle_Height)

    ; Create Message label
    GUICtrlCreateLabel($sMessage, 10 + $iIcon_Reduction, 10 + $iTitle_Height, $iLabelwidth, $iLabelheight)
        GUICtrlSetStyle(-1, $iLabel_Style)
        If $iToast_Message_Col <> Default Then GUICtrlSetColor(-1, $iToast_Message_Col)

    ; Slide Toast Slice into view from behind systray and activate
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 1000, "long", $aToast_Data[2])

    ; Activate Toast without stealing focus
    GUISetState(@SW_SHOWNOACTIVATE, $hToast_Handle)

    ; If script is to pause
    If $fWait = True Then

        ; Begin timeout counter
        Local $iTimeout_Begin = TimerInit()

        ; Wait for timeout or closure
        While 1
            If GUIGetMsg() = $hToast_Close_X Or TimerDiff($iTimeout_Begin) / 1000 >= Abs($iDelay) Then ExitLoop
        WEnd

    ; If script is to continue and delay has been set
    ElseIf Abs($iDelay) > 0 Then

        ; Store timer info
        $iToast_Timer = Abs($iDelay * 1000)
        $iToast_Start = TimerInit()

        ; Register Adlib function to run timer
        AdlibRegister("_Toast_Timer_Check", 100)
        ; Register message handler to check for [X] click
        GUIRegisterMsg(0x0021, "_Toast_WM_EVENTS") ; $WM_MOUSEACTIVATE

    EndIf

    ; Reset original mode
    $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)

    ; Create array to return Toast dimensions
    Local $aToast_Data[3] = [$iToast_Width, $iToast_Height, $iLine_Height]

    Return $aToast_Data

EndFunc ; => _Toast_Show

; #FUNCTION# ========================================================================================================
; Name...........: _Toast_Hide
; Description ...: Hides a slice message from the systray
; Syntax.........: _Toast_Hide()
; Requirement(s).: v3.3.1.5 or higher - AdlibRegister used in _Toast_Show
; Return values .: Success: Returns 0
;                  Failure: If Toast does not exist returns -1 and sets @error to 1
; Author ........: Melba23
; Example........; Yes
;=====================================================================================================================

Func _Toast_Hide()

    ; If no Toast to hide, return
    If $hToast_Handle = 0 Then Return SetError(1, 0, -1)

    ; Slide Toast back behind systray
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 500, "long", $iToast_Move)

    ; Delete Toast slice
    GUIDelete($hToast_Handle)

    ; Set flag for "no Toast"
    $hToast_Handle = 0

EndFunc ; => _Toast_Hide

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Locate
; Description ...: Find Systray and determine Toast start position and movement direction
; Syntax ........: _Toast_Locate($iToast_Width, $iToast_Height)
; Parameters ....: $iToast_Width  - required width of slice
;                  $iToast_Height - required height of slice
; Author ........: Melba23, based on some original code by GioVit
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show
; ===============================================================================================================================
Func _Toast_Locate($iToast_Width, $iToast_Height)

    ; Define return array
    Local $aToast_Data[3]

    ; Find systray
    Local $iPrevMode = Opt("WinTitleMatchMode", 4)
    Local $aTray_Pos = WinGetPos("[CLASS:Shell_TrayWnd]")
    Opt("WinTitleMatchMode", $iPrevMode)

    ; If error in finding systray
    If Not IsArray($aTray_Pos) Then Return SetError(2, 0, -1)

    ; Determine direction of Toast motion and starting position
    If $aTray_Pos[1] > 0 Then
        $iToast_Move = 0x00050004 ; $AW_SLIDE_OUT_BOTTOM
        $aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
        $aToast_Data[1] = $aTray_Pos[1] - $iToast_Height
        $aToast_Data[2] = 0x00040008 ; $AW_SLIDE_IN_BOTTOM
    Elseif $aTray_Pos[0] > 0 Then
        $iToast_Move = 0x00050001 ; $AW_SLIDE_OUT_RIGHT
        $aToast_Data[0] = $aTray_Pos[0] - $iToast_Width
        $aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
        $aToast_Data[2] = 0x00040002 ; $AW_SLIDE_IN_RIGHT
    ElseIf $aTray_Pos[2] = @DesktopWidth Then
        $iToast_Move = 0x00050008 ; $AW_SLIDE_OUT_TOP
        $aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
        $aToast_Data[1] = $aTray_Pos[1] + $aTray_Pos[3]
        $aToast_Data[2] = 0x00040004 ; $AW_SLIDE_IN_TOP
    ElseIf $aTray_Pos[3] = @DesktopHeight Then
        $iToast_Move = 0x00050002 ; $AW_SLIDE_OUT_LEFT
        $aToast_Data[0] = $aTray_Pos[0] + $aTray_Pos[2]
        $aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
        $aToast_Data[2] = 0x00040001 ; $AW_SLIDE_IN_LEFT
    EndIf

    Return $aToast_Data

EndFunc ; => _Toast_Locate

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Timer_Check
; Description ...: Checks whether Toast has timed out or closure [X] clicked
; Syntax ........: _Toast_Locate($iToast_Width, $iToast_Height)
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show if the Wait parameter is set to False
; ===============================================================================================================================
Func _Toast_Timer_Check()

    ; Return if timeout not elapsed and [X] not clicked
    If TimerDiff($iToast_Start) < $iToast_Timer And $fToast_Close = False Then Return

    ; Unregister message handler
    GUIRegisterMsg(0x0021, "") ; $WM_MOUSEACTIVATE
    ; Unregister this function
    AdlibUnRegister("_Toast_Timer_Check")
    ; Reset flag
    $fToast_Close = False
    ; Retract slice
    _Toast_Hide()

EndFunc; => _Toast_Timer_Check

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_WM_EVENTS
; Description ...: Message handler to check if closure [X] clicked
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show if the Wait parameter is set to False
; ===============================================================================================================================
Func _Toast_WM_EVENTS($hWnd, $Msg, $wParam, $lParam)

    #forceref $wParam, $lParam
    If $hWnd = $hToast_Handle Then
        If $Msg = 0x0021 Then ; $WM_MOUSEACTIVATE
            ; Check mouse position
            Local $aPos = GUIGetCursorInfo($hToast_Handle)
            If $aPos[4] = $hToast_Close_X Then $fToast_Close = True
        EndIf
    EndIf
    Return 'GUI_RUNDEFMSG'

EndFunc; => _Toast_WM_EVENTS

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_GetDefFont
; Description ...: Determine system default MsgBox font and size
; Syntax ........: _Toast_GetDefFont($iData)
; Parameters ....: $iData - 0 = Font point size, 1 = Font name
; Author ........: Melba23
; Modified.......:
; Remarks .......: This function is used internally by _Toast functions
; ===============================================================================================================================
Func _Toast_GetDefFont($iData)

    ; Get default system font data
    Local $tNONCLIENTMETRICS = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
    DLLStructSetData($tNONCLIENTMETRICS, 1, DllStructGetSize($tNONCLIENTMETRICS))
    DLLCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($tNONCLIENTMETRICS), "ptr", DllStructGetPtr($tNONCLIENTMETRICS), "int", 0)
    ; Read font data for MsgBox font
    Local $tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DLLStructGetPtr($tNONCLIENTMETRICS, 15))
    Switch $iData
        Case 0
            ; Font size as integer
            Return Int((Abs(DllStructGetData($tLOGFONT, 1)) + 1) * .75)
        Case 1
            ; Font name
            Return DllStructGetData($tLOGFONT, 14)
    EndSwitch

EndFunc ;=>_Toast_GetDefFont

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _Toast_Title_Gradient
; Description ...: Fills the Title bar with a user-defined 2 colour gradient
; Syntax ........: _Toast_Title_Gradient($hWnd, $iX, $iY)
; Parameters ....: $hWnd - The Pic control to colour
;                  $iX   - The width of the Title bar
;                  $iY   - The height of the Title bar
; Author ........: Melba23, based on Yashied's WinAPIEx functions
; Modified.......:
; Remarks .......: This function is used internally by _Toast_Show when a gradient is required
; ===============================================================================================================================
Func _Toast_Title_Gradient($hWnd, $iX, $iY)

    Local $aVertex [2][3] = [[0, 0, $vToast_Header_BkCol[0]], [$iX, $iY, $vToast_Header_BkCol[1]]]

    ; Create gradient
    $hDC = _WinAPI_GetDC($hWnd)
    $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iX, $iY)
    $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
    _WinAPI_GradientFill($hDestDC, $aVertex, 0, 1, $vToast_Header_BkCol[2])

    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hDestDC, $hDestSv)
    _WinAPI_DeleteDC($hDestDC)

    ; Set gradient to control
    _SendMessage($hWnd, 0x0172, 0, $hBitmap) ; $STM_SETIMAGE
    $hObj = _SendMessage($hWnd, 0x0173) ; $STM_GETIMAGE
    If $hObj <> $hBitmap Then
        _WinAPI_FreeObject($hBitmap)
    EndIf

EndFunc

And an amended example script:

#include "Toast_Gradient.au3"

Local $sMsg, $hProgress, $aRet[2]

$sMsg  = "This Toast has a solid title bar." & @CRLF & @CRLF
$sMsg &= "It is easy to choose the colours for the bar and the text to "
$sMsg &= "ensure you can see both the text and the closure [X]"

_Toast_Set(0, 0xFF0000, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show(0, "Gradient Title Bar", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & @CRLF)

$sMsg  = "This Toast has a gradient filled title bar." & @CRLF & @CRLF
$sMsg &= "But you must choose the colours for the bar and the text carefully "
$sMsg &= "or you may have difficulty seeing both the text and the closure [X] "
$sMsg &= "as in this example"

Global $aColours[3] = [0xFF0000, 0x00FFFF, True]

_Toast_Set(5, $aColours, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show(0, "Gradient Title Bar", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & @CRLF)


Global $aColours[3] = [0xFF0000, 0x00FFFF, False]

_Toast_Set(5, $aColours, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show(0, "Gradient Title Bar", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & @CRLF)

$sMsg  = "And back to solid again"

_Toast_Set(0, 0xFF0000, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show(0, "Solid Title Bar", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & @CRLF)
_Toast_Hide()

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

James,

This is my take on the "Show Resource" version of the Toast UDF. You pass the resource name within [], and you need to add the type if it is not RC_DATA. Then the Toast code sorts it out - well it does for me! :huggles:

Change this line in the UDF:

; Create icon
If $iIcon_Reduction Then GUICtrlCreateIcon($sDLL, $iIcon_Style, 10, 10 + $iTitle_Height)

to read:

; Create icon
If $iIcon_Reduction Then
    ; Look for the []
    If StringInStr($sDLL, "[")  And StringInStr($sDLL, "]") Then
        ; If found then remove them
        $sDLL = StringRegExpReplace($sDLL, "\[|\]", "")
        ; Assume RC_DATA
        $iIcon_Style = $RT_RCDATA
        ; See if there is a specified type
        Local $aRet = StringSplit($sDLL, ";")
        If Not @error Then
            ; If there was then use it
            $sDLL = $aRet[1]
            $iIcon_Style = $aRet[2]
        EndIf
        ; Set the resource to the control
        GUICtrlCreatePic("", 10, 10 + $iTitle_Height, 16, 16) ; Max size 32x32 here
        _ResourceSetImageToCtrl(-1, $sDLL, $iIcon_Style)
    Else
        GUICtrlCreateIcon($sDLL, $iIcon_Style, 10, 10 + $iTitle_Height)
    EndIf
EndIf

You will also need to include Zedna's Resources within the UDF - I had to modify it slightly as both it and Yashied's WinAPIEx include were declaring the same constants. It just needs the Global Const $RT_ lines commenting out in one or the other include file.

And here is the little test script I used to develop it. I use Jos' new Beta AutoIt3Wrapper to get the resources in place - much neater than ResHacker IMHO. :

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_File_Add=Test.bmp, RT_BITMAP, RESOURCE_1
#AutoIt3Wrapper_Res_File_Add=Test.gif, RT_RCDATA, RESOURCE_2

#include "Toast_Resource.au3" ; I renamed the modified UDF

Global $aColor[3] = [0x97D9F5, 0xe9eff5, False]
_Toast_Set(0, $aColor, 0x000000, 0xe9eff5, 0x000000, 11, "Arial")
$aRet = _Toast_Show("[RESOURCE_1;" &  $RT_BITMAP & "]", "Title", "Some short text", 5)
$aRet = _Toast_Show("[RESOURCE_2]", "Title", "Some short text", 5)
_Toast_Hide()

I hope that does what you want in a suitable pleasing and eye-catching manner. :D

M23

Edit: Of course you can also use the actual constant value for $RT_BITMAP which makes the syntax a bit less complex:

$aRet = _Toast_Show("[RESOURCE_1;2]", "Title", "Some short text", 5)

Edit: Code changed to restore full functionality for showing icons & exes. Sorry! :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi.. Melba.. :mellow:

I have test U 1st sample in 1st page..

the title Text goes Here ~ Midwidth (OK)

max width and Normal Header (OK)

Unwrapped Toast (OK)

progress bar (OK)

Script Continuing Toast.. (Error)

Error in Toast.au3

AdlibRegister("_Toast_Timer_Check",100)

^Error

Unknown Funtion Name.. :lol::P

U are genius.. :(

Link to comment
Share on other sites

  • Moderators

eri,

What version of AutoIt are you using? AdlibRegister/Unregister came in with 3.3.2.0 and AdlibEnable/Disable was finally removed in 3.3.4.0. The Toast UDF does say:

; AutoIt Version : 3.3.2.0 - uses AdlibRegister/Unregister

You should really update if you are using a version before 3.3.2.0, but if you do not want to, then replace AdlibRegister with AdlibEnable and AdlibUnRegister with AdlibDisable . You should find that the UDF will work for you then. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...