Jump to content

Add more icons in the notification area


Go to solution Solved by power1power1,

Recommended Posts

What should this additional icons be used for?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

power1power1,

And why would you want these extra icons? :huh:

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

Would it be enough to show a tooltip when the mouse is on the tray icon?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

power1power1,

The only way I can think of adding icons to the systray is to spawn child processes - and you would need to use some form of inter-process communication to tell them what to display. :)

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

Let's assume you have a main script which starts other scripts to show the status of different systems etc. Do the child scripts check the status and change the icon colour or is this something which is done by the main script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

power1power1,

You have just described my idea yourself. There are many IPC threads on the forum - a quick search will provide you with plenty of ideas. :)

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

Then you need IPC (Inter process communication) - which isn't too easy. Examples can be found when searching the forum.

Much easier to implement would be a script for each function with a separate icon. The child script would change the icon when the status changes and exit when the main script is no longer running. This could be achieved by passing the process ID of the main script to the child scripts.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

OnAutoItExitRegister('OnAutoItExit')
TraySetIcon("Shell32.dll", 4)
TraySetToolTip("ToolTip_3")

Global $hWnd = WinGetHandle(AutoItWinGetTitle())
Global Const $tagNOTIFYICONDATA = 'dword Size;hwnd hWnd;uint ID;uint Flags;uint CallbackMessage;ptr hIcon;wchar Tip[128];dword State;dword StateMask;wchar Info[256];uint Version;wchar InfoTitle[64];dword InfoFlags;'
Global $tNOTIFYICONDATA = DllStructCreate($tagNOTIFYICONDATA)
Global Const $NIF_ICON = 0x00000002
Global Const $NIM_ADD = 0x00000000
Global Const $NIM_DELETE = 0x00000002
Global Const $NIM_MODIFY = 0x00000001
Global Const $NIF_TIP = 0x00000004

DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA))
DllStructSetData($tNOTIFYICONDATA, 'hWnd', WinGetHandle(AutoItWinGetTitle()))
DllStructSetData($tNOTIFYICONDATA, 'Flags', $NIF_ICON)

;Icon_ID2
DllStructSetData($tNOTIFYICONDATA, 'ID', 2)
DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 166, 16, 16))
_WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA)

;Tooltip_ID2
$NID = DllStructCreate($tagNOTIFYICONDATA)
DllStructSetData($NID, "Size", DllStructGetSize($NID))
DllStructSetData($NID, "hWnd", WinGetHandle(AutoItWinGetTitle()))
DllStructSetData($NID, "ID", 2)
DllStructSetData($NID, "Flags", $NIF_TIP)
DllStructSetData($NID, "Tip", "ToolTip_2")
_WinAPI_ShellNotifyIcon($NIM_MODIFY, $NID)

;Icon_ID3
DllStructSetData($tNOTIFYICONDATA, 'ID', 3)
DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 130, 16, 16))
_WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA)

;Tooltip_ID3
$NID = DllStructCreate($tagNOTIFYICONDATA)
DllStructSetData($NID, "Size", DllStructGetSize($NID))
DllStructSetData($NID, "hWnd", WinGetHandle(AutoItWinGetTitle()))
DllStructSetData($NID, "ID", 3)
DllStructSetData($NID, "Flags", $NIF_TIP)
DllStructSetData($NID, "Tip", "ToolTip_1")
_WinAPI_ShellNotifyIcon($NIM_MODIFY, $NID)

While 1
    Sleep(1000)
WEnd

Func OnAutoItExit()
    DllStructSetData($tNOTIFYICONDATA, 'ID', 2)
    _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
    DllStructSetData($tNOTIFYICONDATA, 'ID', 3)
    _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
EndFunc   ;==>OnAutoItExit

Func _WinAPI_ShellNotifyIcon($iMessage, $tNOTIFYICONDATA)
    Local $Ret = DllCall('shell32.dll', 'int', 'Shell_NotifyIconW', 'dword', $iMessage, 'ptr', DllStructGetPtr($tNOTIFYICONDATA))
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_WinAPI_ShellNotifyIcon

Func _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)
    Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
    If (@error) Or (Not $Ret[0]) Or (Not $Ret[5]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc   ;==>_WinAPI_ShellExtractIcon

'?do=embed' frameborder='0' data-embedContent>>

Link to comment
Share on other sites

  • Moderators

johnmcloud,

Nice find. :thumbsup:

power1power1,

Here is a short example script based on Yashied's original where you can add, modify and delete icons to the systray at will:

#include <GUIConstantsEx.au3>
#include <WinAPIShellEx.au3>

OnAutoItExitRegister("_OnAutoItExit")

Global $aIcons[1] = [0]
; Selection of icons from shell32 DLL
Global $aIcon_ID[3] = [4, 130, 166]

Global $tNOTIFYICONDATA = DllStructCreate($tagNOTIFYICONDATA)

DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA))
DllStructSetData($tNOTIFYICONDATA, 'Flags', $NIF_ICON)

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

$cButton_Add = GUICtrlCreateButton("Add", 10, 10, 80, 30)
$cButton_Change = GUICtrlCreateButton("Change", 10, 110, 80, 30)
$cButton_Delete = GUICtrlCreateButton("Delete", 10, 210, 80, 30)

$cCombo_Change = GUICtrlCreateCombo("", 100, 110, 40, 20)
$cCombo_Delete = GUICtrlCreateCombo("", 100, 210, 40, 20)

GUISetState()

DllStructSetData($tNOTIFYICONDATA, 'hWnd', $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Add
            $aIcons[0] += 1
            ReDim $aIcons[$aIcons[0] + 1]
            $aIcons[$aIcons[0]] = 1
            _Create_Icon($aIcons[0])
            _Update_Combo()
        Case $cButton_Change
            $iID = Number(GUICtrlRead($cCombo_Change))
            If $iID Then
                _Change_Icon($iID)
            EndIf
        Case $cButton_Delete
            $iID = Number(GUICtrlRead($cCombo_Delete))
            If $iID Then
                _Delete_Icon($iID)
                $aIcons[$iID] = 0
                _Update_Combo()
            EndIf
    EndSwitch
WEnd

Func _Create_Icon($iID)
    ; Select random icon ID from shell32
    $iIcon_ID = $aIcon_ID[Random(0, 2, 1)]
    DllStructSetData($tNOTIFYICONDATA, 'ID', $iID)
    DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', $iIcon_ID, 16, 16))
    _WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA)
EndFunc   ;==>_Create_Icon

Func _Change_Icon($iID)
    ; Select random icon ID from shell32
    $iIcon_ID = $aIcon_ID[Random(0, 2, 1)]
    DllStructSetData($tNOTIFYICONDATA, 'ID', $iID)
    DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', $iIcon_ID, 16, 16))
    _WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNOTIFYICONDATA)
EndFunc   ;==>_Change_Icon

Func _Delete_Icon($iID)
    DllStructSetData($tNOTIFYICONDATA, 'ID', $iID)
    _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
EndFunc   ;==>_Delete_Icon

Func _Update_Combo()
    $sComboData = ""
    For $i = 1 To $aIcons[0]
        If $aIcons[$i] Then
            $sComboData &= "|" & $i
        EndIf
    Next
    GUICtrlSetData($cCombo_Change, $sComboData)
    GUICtrlSetData($cCombo_Delete, $sComboData)
EndFunc   ;==>_Update_Combo

Func _OnAutoItExit()
    For $i = 1 To $aIcons[0]
        If $aIcons[$i] Then
            DllStructSetData($tNOTIFYICONDATA, 'ID', $i)
            _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)

        EndIf
    Next
EndFunc   ;==>_OnAutoItExit
Please ask if you have any questions. :)

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

Thanks and cool script Melba  :thumbsup:

P.S. If you can and have some time for complete the script, you can add a different Menu by tray icon using:

_GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem()
_GUICtrlMenu_TrackPopupMenu()

And i think is necessary a WM_COMMAND or a callback

Edited by johnmcloud
Link to comment
Share on other sites

  • Moderators

johnmcloud,

I think it is a bit more complicated than that. But I have some ideas and I will see what I can come up with. :)

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

johnmcloud,

This is even more complicated than I thought it was. :sweating:

Here is some code to recognise a right-click on the additional icons. I am not very happy with using _IsPressed to recognise the right-click, but I have been concentrating on recognising that it took place on one of the icons and identifying which one: ;)

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WinAPIShellEx.au3>
#include <GuiToolbar.au3>
#include <Misc.au3>

OnAutoItExitRegister("_OnAutoItExit")

; Get systray handle
Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
; To store icon IDs
Global $aIcons[2]
; Selection of icons from shell32 DLL
Global $aIcon_Index[2] = [130, 166]
Global $iIcon_ID

Global $hDLL = DllOpen("user32.dll"), $fPressed = False

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

$cButton_Add = GUICtrlCreateButton("Add icons", 10, 10, 80, 30)

$cHit_Dummy = GUICtrlCreateDummy()

GUISetState()

; Create required icon structures
Global $tIcon_Rect = DllStructCreate("int Left;int Top;int Right;int Bottom")
Global $tNID = DllStructCreate($tagNOTIFYICONDATA)
DllStructSetData($tNID, 'Size', DllStructGetSize($tNID))
DllStructSetData($tNID, 'hWnd', $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Add
            For $i = 0 To 1
                $iRet = _Create_Icon($i + 1)
                $aIcons[$i] = $iRet
            Next
        Case $cHit_Dummy
            $iIcon_Index = GUICtrlRead($cHit_Dummy)
            MsgBox($MB_SYSTEMMODAL, "Info", "Rt Click on Add Icon " & $iIcon_Index)
    EndSwitch

    ; Look for right click
    If Not ($fPressed) And _IsPressed("02", $hDLL) Then
        $fPressed = True
    EndIf
    If $fPressed And Not _IsPressed("02", $hDLL) Then
        $fPressed = False
        _Check_Icons()
    EndIf
WEnd

Func _Create_Icon($iID)

    $iIcon_Index = $aIcon_Index[$iID - 1]
    DllStructSetData($tNID, 'ID', $iID)
    DllStructSetData($tNID, 'Flags', $NIF_ICON)
    DllStructSetData($tNID, 'hIcon', _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', $iIcon_Index, 16, 16))
    _WinAPI_ShellNotifyIcon($NIM_ADD, $tNID)

    DllStructSetData($tNID, "Flags", $NIF_TIP)
    DllStructSetData($tNID, "Tip", "Add Icon " & $iID)
    _WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNID)

    Return _GUICtrlToolbar_ButtonCount($hSysTray_Handle) - 1

EndFunc   ;==>_Create_Icon

Func _Check_Icons()

    ; Get count of buttons
    $iCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    ; Get position of tray
    $aTray_Pos = WinGetPos($hSysTray_Handle)
    ; get position of mouse
    $aMouse_Pos = MouseGetPos()

    ; Loop through buttons
    For $i = 0 To $iCount - 1
        ; Get button position in tray
        $aIcon_Pos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $i)
        ; Check absolute position of icon against mouse
        If ($aIcon_Pos[0] + $aTray_Pos[0] <= $aMouse_Pos[0]) And ($aIcon_Pos[2] + $aTray_Pos[0] >= $aMouse_Pos[0]) Then
            If ($aIcon_Pos[1] + $aTray_Pos[1] <= $aMouse_Pos[1]) And ($aIcon_Pos[3] + $aTray_Pos[1] >= $aMouse_Pos[1]) Then
                ; If this icon clicked
                For $j = 0 To 1
                    ; Check against the stored IDs fro teh add icons
                    If $aIcons[$j] = $i Then
                        ; If found then fire dummy
                        GUICtrlSendToDummy($cHit_Dummy, $j + 1)
                        ; No point in looking further
                        ExitLoop 2
                    EndIf
                Next
            EndIf
        EndIf
    Next

EndFunc

Func _OnAutoItExit()
    For $i = 0 To 1
        DllStructSetData($tNID, 'ID', $i + 1)
        _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNID)
    Next
EndFunc   ;==>_OnAutoItExit
You cannot use context or popup menus as the icon is not a control within the GUI - I am still working on that. As I am on using icons within the file itself (assuming it is compiled). ;)

If anyone else wants to jump in and help, please feel free. :)

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

johnmcloud,

I found an old post from SmOke_N which gave me the idea of how to do this, so credit to him for that. The rest is down to me: :D

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPIShellEx.au3>
#include <GuiToolbar.au3>
#include <Misc.au3>
#include <GuiMenu.au3>

OnAutoItExitRegister("_OnAutoItExit")

; Get systray handle
Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
; To store icon IDs
Global $aIcons[2]
; Selection of icons from shell32 DLL
Global $aIcon_Index[2] = [130, 166]
; Icon ID number
Global $iIcon_ID

Global $hDLL = DllOpen("user32.dll"), $fPressed = False

; Create hidden menu GUI
$hGUI_Menu = GUICreate("Menu", 10, 10, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW)

$cMenu_Label = GUICtrlCreateLabel("", 10, 10)
$cMenu_Dummy = GUICtrlCreateDummy()
$cMenu_Context = GUICtrlCreateContextMenu($cMenu_Dummy)
$hMenu_Context = GUICtrlGetHandle($cMenu_Context)

GUISetState(@SW_HIDE)

; Create placeholders for menu items
Global $cItem_1, $cItem_2, $cItem_About

; Create a non-hidden GUI
$hGUI = GUICreate("Test", 200, 200)

$cButton_Add = GUICtrlCreateButton("Add icons", 10, 10, 80, 30)

; Create all dummy controls in this GUI because they do not work if the GUI is hidden
$cHit_Dummy = GUICtrlCreateDummy()
$cItem_1_Dummy = GUICtrlCreateDummy()
$cItem_2_Dummy = GUICtrlCreateDummy()
$cItem_About_Dummy = GUICtrlCreateDummy()

GUISetState()

; Create required icon structures
Global $tIcon_Rect = DllStructCreate("int Left;int Top;int Right;int Bottom")
Global $tNID = DllStructCreate($tagNOTIFYICONDATA)
DllStructSetData($tNID, 'Size', DllStructGetSize($tNID))
DllStructSetData($tNID, 'hWnd', $hGUI)

; Register message to receive menu selection
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Add
            For $i = 0 To 1
                $iRet = _Create_Icon($i + 1)
                $aIcons[$i] = $iRet
            Next
        Case $cItem_1_Dummy
            MsgBox($MB_SYSTEMMODAL, "Item 1", "Icon " & $iIcon_ID & " was right-clicked" & @CRLF & "Item 1 selected")
        Case $cItem_2_Dummy
            MsgBox($MB_SYSTEMMODAL, "Item 2", "Icon " & $iIcon_ID & " was right-clicked" & @CRLF & "Item 2 selected")
        Case $cItem_About_Dummy
            MsgBox($MB_SYSTEMMODAL, "Info", "Icon " & $iIcon_ID & " was right-clicked" & @CRLF & "About selected")
        Case $cHit_Dummy
            ; Which icon?
            $iIcon_ID = GUICtrlRead($cHit_Dummy)
            ; Create menu items for clicked icon
            $cItem_1 = GUICtrlCreateMenuItem("Icon " & $iIcon_ID & " - Item 1", $cMenu_Context)
            $cItem_2 = GUICtrlCreateMenuItem("Icon " & $iIcon_ID & " - Item 2", $cMenu_Context)
            $cItem_Sep = GUICtrlCreateMenuItem("", $cMenu_Context)
            $cItem_About = GUICtrlCreateMenuItem("Icon " & $iIcon_ID & " - About", $cMenu_Context)
            ; Get position of mouse
            $aMPos = MouseGetPos()
            ; Move menu GUI to there
            WinMove($hGUI_Menu, "", $aMPos[0] - 20, $aMPos[1] - 20)
            ; Show popup menu
            _GUICtrlMenu_TrackPopupMenu ($hMenu_Context, $hGUI_Menu)
            ; Destroy menu items
            GUICtrlDelete($cItem_1)
            GUICtrlDelete($cItem_2)
            GUICtrlDelete($cItem_Sep)
            GUICtrlDelete($cItem_About)
    EndSwitch

    ; Look for right click
    If Not ($fPressed) And _IsPressed("02", $hDLL) Then
        $fPressed = True
    EndIf
    If $fPressed And Not _IsPressed("02", $hDLL) Then
        $fPressed = False
        _Check_Icons()
    EndIf
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    #forceref $iMsg, $ilParam
    ; If menu GUI
    If $hWnd = $hGUI_Menu Then
        ; Which item was clicked
        Switch $iwParam
            Case $cItem_1
                GUICtrlSendToDummy($cItem_1_Dummy)
            Case $cItem_2
                GUICtrlSendToDummy($cItem_2_Dummy)
            Case $cItem_About
                GUICtrlSendToDummy($cItem_About_Dummy)
        EndSwitch
    EndIf

EndFunc   ;==>WM_COMMAND

Func _Create_Icon($iID)

    $iIcon_Index = $aIcon_Index[$iID - 1]
    DllStructSetData($tNID, 'ID', $iID)
    DllStructSetData($tNID, 'Flags', $NIF_ICON)
    DllStructSetData($tNID, 'hIcon', _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', $iIcon_Index, 16, 16))
    _WinAPI_ShellNotifyIcon($NIM_ADD, $tNID)

    DllStructSetData($tNID, "Flags", $NIF_TIP)
    DllStructSetData($tNID, "Tip", "Add Icon " & $iID)
    _WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNID)

    Return _GUICtrlToolbar_ButtonCount($hSysTray_Handle) - 1

EndFunc   ;==>_Create_Icon

Func _Check_Icons()

    ; Get count of buttons
    $iCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    ; Get position of tray
    $aTray_Pos = WinGetPos($hSysTray_Handle)
    ; get position of mouse
    $aMouse_Pos = MouseGetPos()

    ; Loop through buttons
    For $i = 0 To $iCount - 1
        ; Get button position in tray
        $aIcon_Pos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $i)
        ; Check absolute position of icon against mouse
        If ($aIcon_Pos[0] + $aTray_Pos[0] <= $aMouse_Pos[0]) And ($aIcon_Pos[2] + $aTray_Pos[0] >= $aMouse_Pos[0]) Then
            If ($aIcon_Pos[1] + $aTray_Pos[1] <= $aMouse_Pos[1]) And ($aIcon_Pos[3] + $aTray_Pos[1] >= $aMouse_Pos[1]) Then
                ; If this icon clicked
                For $j = 0 To 1
                    ; Check against the stored IDs for the add icons
                    If $aIcons[$j] = $i Then
                        ; If found then fire dummy
                        GUICtrlSendToDummy($cHit_Dummy, $j + 1)
                        ; No point in looking further
                        ExitLoop 2
                    EndIf
                Next
            EndIf
        EndIf
    Next

EndFunc

Func _OnAutoItExit()
    For $i = 0 To 1
        DllStructSetData($tNID, 'ID', $i + 1)
        _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNID)
    Next
EndFunc   ;==>_OnAutoItExit
Now to look at detecting the right mouse click. ;)

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

Melba, maybe this can be useful:

#include <GUIConstants.au3>
#include "ModernMenuRaw.au3"
#NoTrayIcon

$hMainGUI = GUICreate("")
GUISetState(@SW_HIDE)

Global $nTrayIcon1 = _TrayIconCreate("Click me", "shell32.dll", -16, "MyTrayTipCallBack")
_TrayIconSetState()
Global $nTrayIcon2 = _TrayIconCreate("Click me", "shell32.dll", -17, "MyTrayTipCallBack")
_TrayIconSetState()

While 1
    Sleep(10000)
WEnd

_TrayIconDelete($nTrayIcon1)
_TrayIconDelete($nTrayIcon2)
Exit

Func MyTrayTipCallBack($nID, $nMsg)
    Switch $nID
        Case $nTrayIcon1
            Switch $nMsg
                Case $WM_RBUTTONUP
                    MsgBox(0, 0, "$nTrayIcon1")
            EndSwitch
        Case $nTrayIcon2
            Switch $nMsg
                Case $WM_RBUTTONUP
                    MsgBox(0, 0, "$nTrayIcon2")
            EndSwitch
    EndSwitch
EndFunc   ;==>MyTrayTipCallBack

Link to comment
Share on other sites

  • Moderators

johnmcloud,

So why am I bothering - seeing that the scripts you keep finding allow you to do it without my input. :D

M23

Edited by Melba23
Typo

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...