Jump to content

Multiple tray notifications


czmaster
 Share

Recommended Posts

  • Moderators

czmaster,

The Toast UDF in my sig can produce a single popup notification. :graduated:

I have never seen anything in AutoIt to produce multiple notifications like that - sounds like a interesting project now the days are drawing in. ;)

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

The ahk code doesn't look very hard, it shouldn't be problematic to convert it (or make something similar) if needed. There are examples on the forum on regions.

Edited by AdmiralAlkex
Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

czmaster,

Is this the sort of thing you were looking for: :graduated:

Save this as Notify.au3: ;)

#include-once

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

; #GLOBAL VARIABLES# =================================================================================================

; Create array to hold data for Notifications
; [0][0] = Count            [n][0] = Handle
; [0][1] = Max avail        [n][1] = Timer duration
; [0][2] = X-coord          [n][2] = Timer stamp
; [0][3] = Low Y-coord      [n][3] = Clickable
; [0][4]                    [n][4] = X-Coord
Global $aNotify_Data[1][5] = [[0, Int((@DesktopHeight - 60) / 50), @DesktopWidth - 10, @DesktopHeight - 10]]
; Adjust values according to taskbar position
_Notify_Locate()
If @error Then MsgBox(0, "Error", "Could not find TaskBar")

; Create array to hold default and current Notification values [Style ($SS_CENTER), Col, BkCol, Font]
Global $aNotify_Settings[2][4] = [[1, 0, 0, _Notify_GetDefFont()]]
Global $aNotify_Ret = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
$aNotify_Settings[0][1] = $aNotify_Ret[0]
$aNotify_Ret = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
$aNotify_Settings[0][2] = $aNotify_Ret[0]
; Use the defaults as current settings
For $i = 0 To 3
    $aNotify_Settings[1][$i] = $aNotify_Settings[0][$i]
Next

; Start timer for Notify retraction function
AdlibRegister("_Notify_Timer", 1000)

Func _Notify_Locate()

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

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

    ; Determine Notify base position and adjust data array if necessary
    If $aTaskBar_Pos[1] > 0 Then
        $aNotify_Data[0][3] = @DesktopHeight - $aTaskBar_Pos[3] - 10
    ElseIf $aTaskBar_Pos[0] > 0 Then
        $aNotify_Data[0][2] = @DesktopWidth - $aTaskBar_Pos[2] - 10
    ElseIf $aTaskBar_Pos[2] = @DesktopWidth Then
        $aNotify_Data[0][1] = Int((@DesktopHeight - $aTaskBar_Pos[3] - 60) / 50)
    EndIf

EndFunc   ;==>_Notify_Locate

Func _Notify_Set($vJust, $iCol = -1, $iBkCol = -1, $sFont_Name = "")

    ; Set parameters
    Switch $vJust
        Case Default
            For $i = 0 To 3
                $aNotify_Settings[1][$i] = $aNotify_Settings[0][$i]
            Next
            Return
        Case 0, 1, 2
            $aNotify_Settings[1][0] = $vJust
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 1, 0)
    EndSwitch

    Switch $iCol
        Case Default
            $aNotify_Settings[1][1] = $aNotify_Settings[0][1]
        Case 0 To 0xFFFFFF
            $aNotify_Settings[1][1] = $iCol
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 2, 0)
    EndSwitch

    Switch $iBkCol
        Case Default
            $aNotify_Settings[1][2] = $aNotify_Settings[0][2]
        Case 0 To 0xFFFFFF
            $aNotify_Settings[1][2] = $iBkCol
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 3, 0)
    EndSwitch

    Switch $sFont_Name
        Case Default
            $aNotify_Settings[1][3] = $aNotify_Settings[0][3]
        Case ""
            ; Do nothing
        Case Else
            If IsString($sFont_Name) Then
                $aNotify_Settings[1][3] = $sFont_Name
            Else
                Return SetError(1, 4, 0)
            EndIf
    EndSwitch

    Return 1

EndFunc   ;==>_Notify_Set

Func _Notify_Show($vIcon, $sTitle, $sMessage, $iDelay = 0, $iClick = 1)

    If $aNotify_Data[0][0] = $aNotify_Data[0][1] Then
        Return SetError(7, 0, -1)
    EndIf

    Local $aLabel_Pos, $iLabel_Width, $iLabelheight = 20

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

    ; Set default auto-sizing Notify dimensions
    Local $iNotify_Width_max = 300
    Local $iNotify_Width_min = 150
    Local $iNotify_Height = 40

    ; Check for icon
    Local $iIcon_Style = 0
    Local $iIcon_Reduction = 36
    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 = $iNotify_Width_max - $iIcon_Reduction - 8

    ; Get text size
    If $sTitle Then
        ; Measure title
        $aLabel_Pos = _StringSize($sTitle, 9, Default, Default, $aNotify_Settings[1][3])
        If @error Then
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(3, 0, -1)
        EndIf
        If $aLabel_Pos[2] > $iMax_Label_Width Then
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(4, 0, -1)
        Else
            $iLabelwidth = $aLabel_Pos[2]
        EndIf
        ; Measure message
        $aLabel_Pos = _StringSize($sMessage, 9, Default, Default, $aNotify_Settings[1][3])
        If $aLabel_Pos[2] > $iMax_Label_Width Then
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(4, 0, -1)
        Else
            If $aLabel_Pos[2] > $iLabel_Width Then
                $iLabelwidth = $aLabel_Pos[2]
            EndIf
        EndIf
    Else
        $aLabel_Pos = _StringSize($sMessage, 9, Default, Default, $aNotify_Settings[1][3], $iMax_Label_Width)
        If @error Then
            ConsoleWrite(@error & @CRLF)
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(3, 0, -1)
        EndIf
        If $aLabel_Pos[3] > 40 Then
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(4, 0, -1)
        Else
            If $aLabel_Pos[2] > $iLabel_Width Then
                $iLabelwidth = $aLabel_Pos[2]
            EndIf
            $sMessage = $aLabel_Pos[0]
            $iLabelheight = 40
        EndIf
    EndIf

    ; Set Notify size
    Local $iNotify_Width = $iLabelwidth + 8 + $iIcon_Reduction

    ; Increase if below min size
    If $iNotify_Width < $iNotify_Width_min + $iIcon_Reduction Then
        $iNotify_Width = $iNotify_Width_min + $iIcon_Reduction
        $iLabelwidth = $iNotify_Width_min - 8
    EndIf

    ; Set Notify coords
    $iNotify_X = $aNotify_Data[0][2] - $iNotify_Width
    $iNotify_Y = $aNotify_Data[0][3] - (50 * ($aNotify_Data[0][0] + 1))

    ; Create Notify slice with $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW style and $WS_EX_TOPMOST extended style
    $hNotify_Handle = GUICreate("", $iNotify_Width, $iNotify_Height, $iNotify_X, $iNotify_Y, 0x80880000, BitOR(0x00000080, 0x00000008))
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(1, 0, -1)
    EndIf
    GUISetBkColor($aNotify_Settings[1][2])

    ; Create icon
    If $iIcon_Reduction Then GUICtrlCreateIcon($sDLL, $iIcon_Style, 4, 4)

    ; Create labels
    If $sTitle Then
        ; Title
        GUICtrlCreateLabel($sTitle, 4 + $iIcon_Reduction, 0, $iLabelwidth, $iLabelheight)
        ;GUICtrlCreateLabel($sTitle, 8 + $iIcon_Reduction, 0, $iLabelwidth, $iLabelheight)
        GUICtrlSetFont(-1, 9, 800, 0, $aNotify_Settings[1][3])
        GUICtrlSetBkColor(-1, $aNotify_Settings[1][2])
        GUICtrlSetColor(-1, $aNotify_Settings[1][1])
        GUICtrlSetStyle(-1, $aNotify_Settings[1][0])
        ; Message
        GUICtrlCreateLabel($sMessage, 4 + $iIcon_Reduction, 20, $iLabelwidth, $iLabelheight)
        GUICtrlSetFont(-1, 9, 400, 0, $aNotify_Settings[1][3])
        GUICtrlSetBkColor(-1, $aNotify_Settings[1][2])
        GUICtrlSetColor(-1, $aNotify_Settings[1][1])
        GUICtrlSetStyle(-1, $aNotify_Settings[1][0])
    Else
        ; Message
        GUICtrlCreateLabel($sMessage, 4 + $iIcon_Reduction, 0, $iLabelwidth, $iLabelheight)
        GUICtrlSetFont(-1, 9, 400, 0, $aNotify_Settings[1][3])
        GUICtrlSetBkColor(-1, $aNotify_Settings[1][2])
        GUICtrlSetColor(-1, $aNotify_Settings[1][1])
        GUICtrlSetStyle(-1, $aNotify_Settings[1][0])
    EndIf

    ; Slide Notify Slice into view from behind systray and activate
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hNotify_Handle, "int", 1000, "long", 0x00040002) ; $AW_SLIDE_IN_RIGHT

    ; Activate Notify without stealing focus
    GUISetState(@SW_SHOWNOACTIVATE, $hNotify_Handle)

    ; Store Notify data
    $aNotify_Data[0][0] += 1
    ReDim $aNotify_Data[$aNotify_Data[0][0] + 1][5]
    $aNotify_Data[$aNotify_Data[0][0]][0] = $hNotify_Handle
    $aNotify_Data[$aNotify_Data[0][0]][1] = $iDelay * 1000
    $aNotify_Data[$aNotify_Data[0][0]][2] = TimerInit()
    $aNotify_Data[$aNotify_Data[0][0]][3] = $iClick
    $aNotify_Data[$aNotify_Data[0][0]][4] = $iNotify_X

    ;_ArrayDisplay($aNotify_Data)

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

EndFunc   ;==>_Notify_Show

Func _Notify_RegMsg()

    GUIRegisterMsg(0x0021, "_Notify_WM_MOUSEACTIVATE") ; $WM_MOUSEACTIVATE
    $aNotify_Data[0][4] = 1

EndFunc

Func _Notify_Timer()

    Local $fMoved = False

    ; Pause Adlib as multiple retractions will overrun time
    AdlibUnRegister("_Notify_Timer")
    For $i = $aNotify_Data[0][0] To 1 Step -1
        ; Check timer if needed
        If $aNotify_Data[$i][1] And TimerDiff($aNotify_Data[$i][2]) > $aNotify_Data[$i][1] Then
            _Notify_Delete($i)
            $fMoved = True
        EndIf
    Next

    ; Adjust positions of Notifications
    If $fMoved Then
        _Notify_Reset()
    EndIf

    ; Restart Adlib
    AdlibRegister("_Notify_Timer", 1000)

EndFunc   ;==>_Notify_Timer

Func _Notify_WM_MOUSEACTIVATE($hWnd, $Msg, $wParam, $lParam)

    #forceref $wParam, $lParam

    ; Declare flag to prevent multiple clicks until a Notification is retracted
    Static $fRunning
    If $fRunning Then Return

    ; Declare flag
    Local $fMoved = False
    ; Set Running flag
    $fRunning = True

    For $i = $aNotify_Data[0][0] To 1 Step -1
        If $aNotify_Data[$i][3] And $hWnd = $aNotify_Data[$i][0] Then
            _Notify_Delete($i)
            $fMoved = True
        EndIf
    Next

    ; Adjust positions of Notifications
    If $fMoved Then
        _Notify_Reset()
    EndIf

    ; Clear Running flag
    $fRunning = False

    Return 'GUI_RUNDEFMSG'

EndFunc   ;==>_Notify_WM_MOUSEACTIVATE

Func _Notify_Delete($i)

    ; Retract and delete Notify
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $aNotify_Data[$i][0], "int", 500, "long", 0x00050001) ; $AW_SLIDE_OUT_RIGHT
    GUIDelete($aNotify_Data[$i][0])
    ; Adjust array
    For $j = $i + 1 To $aNotify_Data[0][0]
        For $k = 0 To 4
            $aNotify_Data[$j - 1][$k] = $aNotify_Data[$j][$k]
        Next
    Next
    ReDim $aNotify_Data[$aNotify_Data[0][0]][5]
    $aNotify_Data[0][0] -= 1

EndFunc

Func _Notify_Reset()

    For $i = 1 To $aNotify_Data[0][0]
        WinMove($aNotify_Data[$i][0], "", $aNotify_Data[$i][4], $aNotify_Data[0][3] - (50 * $i))
    Next

EndFunc

Func _Notify_GetDefFont()

    ; 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))
    ; Font name
    Return DllStructGetData($tLOGFONT, 14)

EndFunc   ;==>_Notify_GetDefFont

And then you can run this example from the same folder: ;)

#include "Notify.au3"

; Register message for click event
_Notify_RegMsg()

; Set notifications
_Notify_Show(0, "No Click", "Retracts after 20 secs", 20, 0)
_Notify_Set(0, 0xFF0000, 0xFFFF00, "Courier New")
_Notify_Show(0, "Clickable", "Red on Yellow to left")
_Notify_Set(Default)
_Notify_Show(0, "Clickable", "Reset to default colours")
_Notify_Set(2, 0x0000FF, 0xCCCCFF, "Comic MS")
_Notify_Show(48, "Clickable", "With an icon")
_Notify_Set(0, Default, 0xCCFF00, "Arial")
_Notify_Show(0, "", "No title so the message can span both lines without problem if it is long enough to need it")

Sleep(50000)

You will also need my StringSize UDF - you can find it in my sig below. :D

The UDF is still a bit rough around the edges, but it shows the basic principles. Let me know if you would like anything changed and I will see what I can do. :)

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

czmaster,

Glad you like it. :graduated:

I will polish it up a bit and then release it in proper UDF format in the Examples section sometime next week. ;)

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

czmaster,

Works fine for me: ;)

#include <GUIConstantsEx.au3>
#include "Notify.au3"

$iCount = 0

_Notify_RegMsg()

$hGUI = GUICreate("Test", 500, 500)

$hButton = GUICtrlCreateButton("Notify", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $iCount += 1
            _Notify_Show(0, "Notification " & $iCount, @Min & ":" & @SEC, 40)
    EndSwitch
WEnd

Post your code and I will take a look at it. :graduated:

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

Sorry your code work !

Before I had only one GUI and now with the notification I have many GUI, so i must specify which GUI to show and to hide with GUISetState.

Ex: GUISetState(@SW_HIDE,$GUI)

Edited by czmaster
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...