Jump to content

GUI/Tray Menu with icons and colors


Holger
 Share

Recommended Posts

  • Moderators

dv8,

My pleasure. :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

  • 2 weeks later...

This is a welcomed addition to Menu and Tray Menu items! I very much wanted such functionality for a long time instead of the plain look and feel. I am going to implement this right away into my own codes.

Thank you!

By the way, is there a way to get the actual system tray icon to reflect text instead of an image? For instance, imitating the System Tray clock. I'd like to have my own system tray clock with these new modern menu.

I guess an example of this in C++ is here:

http://blogs.msdn.com/b/abhinaba/archive/2005/09/12/464150.aspx

But it doesn't seem AutoIT has similar commands in it's systemtray functions.

Thanks for any input or directing. :D

Link to comment
Share on other sites

  • 7 months later...

hi guy i have some problem

this is my code i dont understund why if i use this include the script block

: ERROR: $ILC_MASK previously declared as a 'Const'.

If Not IsDeclared("ILC_MASK") Then Global $ILC_MASK = 0x0001

my code

; ModernMenu2003 Gradient Example
; Syntax:
; ;_SetMenuIconGradBkColor(0x??????) ;where ? is a hexadecimal digit
; To prevent gradient, use this code:
; ;_SetMenuIconGradBkColor($nMenuIconBkClr)
;#include <GuiEdit.au3>
;#include <GUIConstantsEx.au3>
;#include <WindowsConstants.au3>
;#include <ButtonConstants.au3>
;#include <Date.au3>
;#include <editconstants.au3>
;#include <listviewconstants.au3>
;#include <staticconstants.au3>
;#include <windowsconstants.au3>
;#include <guilistview.au3>
;#include <Word.au3>
#include <GuiImageList.au3>
;#include <Timers.au3>
;#include <GuiListBox.au3>
;#include <GuiButton.au3>
;#include <ComboConstants.au3>
;#include <misc.au3>
;#include <Word.au3>
;#include <MPDF_UDF.au3>
;#include <GUIComboBox.au3>
;#include <Constants.au3>
;#include <DateTimeConstants.au3>
;#include <file.au3>
;#include <array.au3>
;#include <INet.au3>
;#include <Process.au3>
;#include <ColorPicker.au3>
;#include <WinAPI.au3>
;#include <GDIPlus.au3>
;#include <ScreenCapture.au3>
#include <GUIConstants.au3>
#include 'ModernMenu.au3'
Global Const $WM_CONTEXTMENU = 0x7B
$hMainGUI  = GUICreate('Sample Menu')
; Set default color values - BGR-values!
SetDefaultMenuColors()
; File-Menu
$FileMenu  = GUICtrlCreateMenu('&File')
$OpenItem  = _GUICtrlCreateODMenuItem('Open', $FileMenu, 'shell32.dll', 4)
$SaveItem  = _GUICtrlCreateODMenuItem('Save', $FileMenu, 'shell32.dll', 6)
_GUICtrlCreateODMenuItem('', $FileMenu) ; Separator
$RecentMenu  = _GUICtrlCreateODMenu('Recent Files', $FileMenu)
_GUICtrlCreateODMenuItem('', $FileMenu) ; Separator
$ExitItem  = _GUICtrlCreateODMenuItem('Exit', $FileMenu, 'shell32.dll', 27)
; Tools-Menu
$ToolsMenu  = GUICtrlCreateMenu('&Tools')
$CalcItem  = _GUICtrlCreateODMenuItem('Calculator', $ToolsMenu, 'calc.exe', 0)
$CmdItem  = _GUICtrlCreateODMenuItem('CMD', $ToolsMenu, 'cmd.exe', 0)
$EditorItem  = _GUICtrlCreateODMenuItem('Editor', $ToolsMenu, 'notepad.exe', 0)
$RegeditItem = _GUICtrlCreateODMenuItem('Regedit', $ToolsMenu, 'regedit.exe', 0)
; View-Menu
$ViewMenu  = GUICtrlCreateMenu('&View')
$ViewColorMenu = _GUICtrlCreateODMenu('Menu Colors', $ViewMenu, 'mspaint.exe', 0)
$SetDefClrItem = _GUICtrlCreateODMenuItem('Default', $ViewColorMenu, '', 0, 1)
_GUICtrlCreateODMenuItem('', $ViewColorMenu) ; Separator
$SetRedClrItem = _GUICtrlCreateODMenuItem('Red', $ViewColorMenu, '', 0, 1)
$SetGrnClrItem = _GUICtrlCreateODMenuItem('Green', $ViewColorMenu, '', 0, 1)
GUICtrlSetState(-1, $GUI_CHECKED)
$SetBlueClrItem = _GUICtrlCreateODMenuItem('Blue', $ViewColorMenu, '', 0, 1)
$ViewStateItem = _GUICtrlCreateODMenuItem('Enable Config', $ViewMenu)
GUICtrlSetState(-1, $GUI_CHECKED)
; Help-Menu
$HelpMenu  = GUICtrlCreateMenu('&?')
$HelpItem  = _GUICtrlCreateODMenuItem('Help Topics', $HelpMenu, 'shell32.dll', 23)
_GUICtrlCreateODMenuItem('', $HelpMenu) ; Separator
$AboutItem  = _GUICtrlCreateODMenuItem('About...', $HelpMenu, '', 0)
; You can also the same things on context menus
$GUIContextMenu = GUICtrlCreateContextMenu(-1)
$ConAboutItem = _GUICtrlCreateODMenuItem('About...', $GUIContextMenu, 'explorer.exe', 7)
_GUICtrlCreateODMenuItem('', $GUIContextMenu) ; Separator
$ConExitItem = _GUICtrlCreateODMenuItem('Exit', $GUIContextMenu, 'shell32.dll', 27)
; My_WM_MeasureItem and My_WM_DrawItem are registered in
; 'ModernMenu.au3' so they don't need to registered here
; Also OnAutoItExit() is in 'ModernMenu.au3' to cleanup the
; menu imagelist and special font
GUISetState()

; Main GUI Loop
While 1
$Msg = GUIGetMsg()
Switch $Msg
  Case $GUI_EVENT_CLOSE, $ExitItem, $ConExitItem
   ExitLoop
  Case $AboutItem, $ConAboutItem
   Msgbox(64, 'About', 'Menu color sample by Holger Kotsch')
  Case $ViewStateItem
   If BitAnd(GUICtrlRead($ViewStateItem), $GUI_CHECKED) Then
    GUICtrlSetState($ViewStateItem, $GUI_UNCHECKED)
    GUICtrlSetState($ViewColorMenu, $GUI_DISABLE)
   Else
    GUICtrlSetState($ViewStateItem, $GUI_CHECKED)
    GUICtrlSetState($ViewColorMenu, $GUI_ENABLE)
   EndIf
  Case $SetDefClrItem
   SetCheckedItem($SetDefClrItem)
   SetDefaultMenuColors()
  Case $SetRedClrItem
   SetCheckedItem($SetRedClrItem)
   SetRedMenuColors()
  Case $SetGrnClrItem
   SetCheckedItem($SetGrnClrItem)
   SetGreenMenuColors()
  Case $SetBlueClrItem
   SetCheckedItem($SetBlueClrItem)
   SetBlueMenuColors()
EndSwitch
WEnd
Exit

Func SetCheckedItem($DefaultItem)
GUICtrlSetState($SetDefClrItem, $GUI_UNCHECKED)
GUICtrlSetState($SetRedClrItem, $GUI_UNCHECKED)
GUICtrlSetState($SetGrnClrItem, $GUI_UNCHECKED)
GUICtrlSetState($SetBlueClrItem, $GUI_UNCHECKED)
GUICtrlSetState($DefaultItem, $GUI_CHECKED)
EndFunc

Func SetDefaultMenuColors()
_SetMenuBkColor(0xFFFFFF)
;_SetMenuIconBkColor(0xCACACA)
;_SetMenuIconGradBkColor(0xEFEFEF) ;;;
_SetMenuSelectBkColor(0xE5A2A0)
_SetMenuSelectRectColor(0x854240)
_SetMenuSelectTextColor(0x000000)
_SetMenuTextColor(0x000000)
EndFunc

Func SetRedMenuColors()
_SetMenuBkColor(0xAADDFF)
;_SetMenuIconBkColor(0x5566BB)
;_SetMenuIconGradBkColor(0x99CCEE) ;;;
_SetMenuSelectBkColor(0x70A0C0)
_SetMenuSelectRectColor(0x854240)
_SetMenuSelectTextColor(0x000000)
_SetMenuTextColor(0x000000)
EndFunc

Func SetGreenMenuColors()
_SetMenuBkColor(0xAAFFAA)
;_SetMenuIconBkColor(0x66BB66)
;_SetMenuIconGradBkColor(0x99EE99) ;;;
_SetMenuSelectBkColor(0xBBCC88)
_SetMenuSelectRectColor(0x222277)
_SetMenuSelectTextColor(0x770000)
_SetMenuTextColor(0x000000)
EndFunc

Func SetBlueMenuColors()
_SetMenuBkColor(0xFFB8B8)
;_SetMenuIconBkColor(0xBB8877)
;_SetMenuIconGradBkColor(0xEEA7A7) ;;;
_SetMenuSelectBkColor(0x662222)
_SetMenuSelectRectColor(0x4477AA)
_SetMenuSelectTextColor(0x66FFFF)
_SetMenuTextColor(0x000000)
EndFunc
Func _HiWord($x)
   Return BitShift($x, 16)
EndFunc   ;==>_HiWord
Func _LoWord($x)
   Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

can you help me?? :D

thankz

Link to comment
Share on other sites

  • 6 months later...
  • 9 months later...
  • 1 month later...
  • 9 months later...
  • 2 weeks later...

hello, few questions i have for anyone who has been using this great UDF:

1) is there a way to have the menu with the side title, but without icons (and without the icons placeholder)?

not setting icons at all does not do it - it reverts the modern menu back to standard.

2) is there a way to have a submenu without icons (and without the icons placeholder), but keep the modern menu colors?

3) is there a way to make the tray menu respond to double-click?

thanks for any hints.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Thanks for comments and likes.

1) and 2) Icons appear to be the main point of this UDF. I do not think that you can create menus without icons. It certainly can be done, but you have to implement the owner drawn menus yourself. You can find the code in the UDF.

3) No, not with this UDF. As far as I know most menus respond to a single click and then closes. The menu will never receive the double click. To implement double click in a standard menu, you probably have to use methods like hook procedures or menu subclassing.

You can get the updated (19.10.2014) UDF in post 289.

Link to comment
Share on other sites

  • 2 months later...

Thanks for comments and likes.

1) and 2) Icons appear to be the main point of this UDF. I do not think that you can create menus without icons. It certainly can be done, but you have to implement the owner drawn menus yourself. You can find the code in the UDF.

3) No, not with this UDF. As far as I know most menus respond to a single click and then closes. The menu will never receive the double click. To implement double click in a standard menu, you probably have to use methods like hook procedures or menu subclassing.

You can get the updated (19.10.2014) UDF in post 289.

 In post >251 was described error, I think need adding fix in your update.

Into func  _TrayIconSetState change  

SetTimer($TRAYMSGWND, $FLASHTIMERID, $FLASHTIMEOUT, 0)

to 

SetTimer($TRAYMSGWND, $nID, $FLASHTIMEOUT, 0)
Link to comment
Share on other sites

Thank you, I'll update the UDF.

Do you have an example that demonstrates the flashing? Just a small example like the examples by AZJIO. Then I'll add the example to the zip.

Link to comment
Share on other sites

Link to comment
Share on other sites

Because Holger isn't active for a long time, this topic started before 9 years and it is still active.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thank you, I'll update the UDF.

Do you have an example that demonstrates the flashing? Just a small example like the examples by AZJIO. Then I'll add the example to the zip.

Ex:

#NoTrayIcon
#include <ModernMenuRAW.au3>
#include <GUIConstantsEx.au3>
$tray_win=_TrayIconCreate('g',@ScriptName,0)
_SetTrayBkColor(0xAAFFAA)
_SetTrayIconBkColor(0xBB8877)
_SetTraySelectRectColor(0x4477AA)
_SetTrayTextColor(0x000000)
_TrayCreateContextMenu($tray_win)
$tray_start=_TrayCreateItem('Start')
_TrayItemSetIcon(-1, "", 0)
$star=False
GUICtrlSetState(-1,$star)
_TrayCreateItem('')
_TrayItemSetIcon(-1, "", 0)
$tray_exit=_TrayCreateItem('Exit')
_TrayItemSetIcon(-1,"shell32.dll", 28);28
While 1
$msg=GUIGetMsg()

Switch $msg
Case $tray_exit
exit
Case $tray_start
If $star Then
GUICtrlSetState($tray_start,$GUI_UNCHECKED)
_trayiconsetstate($tray_win,8)
Else
GUICtrlSetState($tray_start,$GUI_CHECKED)
_trayiconsetstate($tray_win,4)
EndIf
$star= Not $star
EndSwitch
WEnd

And some new improvement:

Func _GetIconID($nID, $sFile)
    #cs
    If StringRight($sFile, 4) = ".exe" Then
        If $nID < 0 Then
            $nID = - ($nID + 1)
        ElseIf $nID > 0 Then
            $nID = - $nID
        EndIf
    ElseIf StringRight($sFile, 4) = ".icl" And $nID < 0 Then
        $nID = - ($nID + 1)
    Else
        If $nID > 0 Then
            $nID = - $nID
        ElseIf $nID < 0 Then
            $nID = - ($nID + 1)
        EndIf
    EndIf
    #ce
    ;nickston
;#cs
    $nID = - $nID

    If $nID > 0 Then
        $nID -=1
    EndIf
;#ce
    Return $nID
EndFunc
Func _GetNewTrayIndex()
    Local $i, $bFreeFound = FALSE

    For $i = 1 To $TRAYNOTIFYIDS[0][0]
        If $TRAYNOTIFYIDS[$i][0] = 0 Then
            $bFreeFound = TRUE
            ExitLoop
        EndIf
    Next

    If Not $bFreeFound Then
        $TRAYNOTIFYIDS[0][0] += 1
        Local $nSize = UBound($TRAYNOTIFYIDS)

        ;If $TRAYNOTIFYIDS[0][0] > $nSize - 10 Then _
        ;   Redim $TRAYNOTIFYIDS[$nSize + 10][9]
        ;nickston
        If $TRAYNOTIFYIDS[0][0] > $nSize - 1 Then _
            Redim $TRAYNOTIFYIDS[$nSize + 10][9]
        $i = $TRAYNOTIFYIDS[0][0]
    EndIf

    Return $i
EndFunc
Func _TrayIconCreate($sToolTip = "", $sIconFile = @AutoItExe, $nIconID = 0, $sCallback = "", $nMsg = 0, $hIcon = 0)
    If $sToolTip = "" Then $sToolTip = $sDefaultTT
    ;nickston+
    #cs
    $nIconID = _GetIconID($nIconID, $sIconFile)

    If $sIconFile = "" Then
        If $hIcon = 0 Then
            If $nIconID = 0 Then
                $sIconFile = @AutoItExe
            Else
                $hIcon = LoadIcon(0, $nIconID)
            EndIf
        EndIf
    EndIf

    If $sIconFile <> "" Then
        Local $stIcon = DllStructCreate("hwnd")

        If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
            $hIcon = DllStructGetData($stIcon, 1)
        Else
            $hIcon = LoadIcon(0, 32516)
        EndIf
    EndIf

    If $TRAYMSGWND = 0 Then
        $TRAYMSGWND = GUICreate("", 1, 1, 9999, 9999, -1, 0x00000080)
        GUISetState()
        ShowWindow($TRAYMSGWND, @SW_HIDE)
    EndIf

    Local $nNID = _GetNewTrayIndex()
    If $nNID = 0 Then
        DestroyIcon($hIcon)
        Return 0
    EndIf
    #ce
    ;nickston-
;   #cs
    If $TRAYMSGWND = 0 Then
        $TRAYMSGWND = GUICreate("", 1, 1, 9999, 9999, -1, 0x00000080)
        GUISetState()
        ShowWindow($TRAYMSGWND, @SW_HIDE)
    EndIf

    Local $nNID = _GetNewTrayIndex()
    If $nNID = 0 Then
        ;DestroyIcon($hIcon)
        Return 0
    EndIf
    $hIcon=-1
;#ce
    $TRAYNOTIFYIDS[$nNID][0] = $nNID
    $TRAYNOTIFYIDS[$nNID][1] = $hIcon
    $TRAYNOTIFYIDS[$nNID][2] = 0
    $TRAYNOTIFYIDS[$nNID][3] = 9
    $TRAYNOTIFYIDS[$nNID][4] = $sToolTip
    $TRAYNOTIFYIDS[$nNID][5] = $sCallback
    $TRAYNOTIFYIDS[$nNID][6] = $nMsg
    $TRAYNOTIFYIDS[$nNID][7] = FALSE
    $TRAYNOTIFYIDS[$nNID][8] = FALSE

    _TrayIconSetIcon($nNID,$sIconFile,$nIconID)
    $TRAYLASTID = $nNID

    Return $nNID
EndFunc
Func _TrayIconDelete($nID)
    If $nID = -1 Then $nID = $TRAYLASTID
    If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
    ;nickston+
    #cs
    Local $stNID = DllStructCreate($sNOTIFYICONDATAW)

    DllStructSetData($stNID, 1, DllStructGetSize($stNID))
    DllStructSetData($stNID, 2, $TRAYMSGWND)
    DllStructSetData($stNID, 3, $nID)
    #ce
    ;nickston-
    Local $nResult = 0

    Local $i
    For $i = 1 To $TRAYNOTIFYIDS[0][0]
        If $nID = $TRAYNOTIFYIDS[$i][0] Then
            $stNID = DllStructCreate($sNOTIFYICONDATAW)

            DllStructSetData($stNID, 1, DllStructGetSize($stNID))
            DllStructSetData($stNID, 2, $TRAYMSGWND)
            DllStructSetData($stNID, 3, $nID)

            $nResult = Shell_NotifyIcon($NIM_DELETE, DllStructGetPtr($stNID))

            DestroyIcon($TRAYNOTIFYIDS[$i][1])
            $TRAYNOTIFYIDS[$i][8] = FALSE
            $TRAYNOTIFYIDS[$i][7] = FALSE
            $TRAYNOTIFYIDS[$i][6] = 0
            $TRAYNOTIFYIDS[$i][5] = ""
            $TRAYNOTIFYIDS[$i][4] = ""
            $TRAYNOTIFYIDS[$i][3] = 0

            If $TRAYNOTIFYIDS[$i][2] <> 0 Then GUIDelete($TRAYNOTIFYIDS[$i][2])

            $TRAYNOTIFYIDS[$i][2] = 0
            $TRAYNOTIFYIDS[$i][1] = 0
            $TRAYNOTIFYIDS[$i][0] = 0

            ExitLoop
        EndIf
    Next

    Return $nResult
EndFunc
Func _TrayIconSetState($nID = -1, $nState = 1)
    If $nState = 0 Then Return 1 ; No change

    If $nID = -1 Then $nID = $TRAYLASTID
    If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0

    Local $i, $nResult = 0, $bFound = FALSE

    For $i = 1 To $TRAYNOTIFYIDS[0][0]
        If $nID = $TRAYNOTIFYIDS[$i][0] Then
            $bFound = TRUE
            ExitLoop
        EndIf
    Next

    If Not $bFound Then Return 0

    Local $stNID = DllStructCreate($sNOTIFYICONDATAW)

    If BitAnd($nState, 1) Then
        DllStructSetData($stNID, 1, DllStructGetSize($stNID))
        DllStructSetData($stNID, 2, $TRAYMSGWND)
        DllStructSetData($stNID, 3, $nID)
        DllStructSetData($stNID, 4, BitOr($NIF_ICON, $NIF_MESSAGE))
        DllStructSetData($stNID, 5, $TRAYTIPMSG)
        DllStructSetData($stNID, 6, $TRAYNOTIFYIDS[$nID][1])

        $nResult = Shell_NotifyIcon($NIM_ADD, DllStructGetPtr($stNID))
        If $nResult Then _TrayIconSetToolTip($nID, $TRAYNOTIFYIDS[$nID][4])
    ElseIf BitAnd($nState, 2) Then
        DllStructSetData($stNID, 1, DllStructGetSize($stNID))
        DllStructSetData($stNID, 2, $TRAYMSGWND)
        DllStructSetData($stNID, 3, $nID)

        $nResult = Shell_NotifyIcon($NIM_DELETE, DllStructGetPtr($stNID))

    EndIf

    If BitAnd($nState, 4) Then
        If Not $TRAYNOTIFYIDS[$nID][7] Then
            If $hBlankIcon = 0 Then _CreateBlankIcon()
            If $hBlankIcon <> 0 Then
                ;SetTimer($TRAYMSGWND, $FLASHTIMERID, $FLASHTIMEOUT, 0)
                ;nickston
                SetTimer($TRAYMSGWND, $nID, $FLASHTIMEOUT, 0)
                $TRAYNOTIFYIDS[$nID][7] = TRUE
            EndIf
        EndIf
    ElseIf BitAnd($nState, 8) Then
        ;KillTimer($TRAYMSGWND, $FLASHTIMERID)
        KillTimer($TRAYMSGWND, $nID)

        DllStructSetData($stNID, 1, DllStructGetSize($stNID))
        DllStructSetData($stNID, 2, $TRAYMSGWND)
        DllStructSetData($stNID, 3, $nID)
        DllStructSetData($stNID, 4, $NIF_ICON)
        DllStructSetData($stNID, 6, $TRAYNOTIFYIDS[$nID][1])

        $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))

        $TRAYNOTIFYIDS[$nID][7] = FALSE
        $TRAYNOTIFYIDS[$nID][8] = FALSE
    EndIf

    Return $nResult
EndFunc
Func _TrayIconSetIcon($nID = -1, $sIconFile = @AutoItExe, $nIconID = 0)
    If $nID = -1 Then $nID = $TRAYLASTID
    If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0

    $nIconID = _GetIconID($nIconID, $sIconFile)

    Local $hIcon = 0

    If $sIconFile = "" Then
        If $nIconID = 0 Then
            $sIconFile = @AutoItExe
        Else
            $hIcon = LoadIcon(0, $nIconID)
        EndIf
    EndIf

    If $sIconFile <> "" Then
        Local $stIcon = DllStructCreate("hwnd")

        If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
            $hIcon = DllStructGetData($stIcon, 1)
        Else
            $hIcon = LoadIcon(0, 32516)
        EndIf
    EndIf

    Local $stNID    = DllStructCreate($sNOTIFYICONDATAW)
    DllStructSetData($stNID, 1, DllStructGetSize($stNID))
    DllStructSetData($stNID, 2, $TRAYMSGWND)
    DllStructSetData($stNID, 3, $nID)

    DllStructSetData($stNID, 6, $hIcon)
    ;nickston
    If  $TRAYNOTIFYIDS[$nID][1]=-1 Then
        DllStructSetData($stNID, 4, BitOr($NIF_ICON, $NIF_MESSAGE))
        DllStructSetData($stNID, 5, $TRAYTIPMSG)

        $nResult = Shell_NotifyIcon($NIM_ADD, DllStructGetPtr($stNID))
        ;Local $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
    Else
            DllStructSetData($stNID, 4, $NIF_ICON)
        DestroyIcon($TRAYNOTIFYIDS[$nID][1])
        Local $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
    EndIf


    If $nResult Then
        $TRAYNOTIFYIDS[$nID][1] = $hIcon
    Else
        DestroyIcon($hIcon)
        $TRAYNOTIFYIDS[$nID][1] = 0
    EndIf

    Return $nResult
EndFunc
Link to comment
Share on other sites

For all mouse buttions clicks:

Func _TrayNotifyIcon($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg
    ;Local $nClick = 0
    Local $nID = $wParam

    If $TRAYNOTIFYIDS[$nID][5] <> "" And _
        ($TRAYNOTIFYIDS[$nID][6] = 0 Or _
        $TRAYNOTIFYIDS[$nID][6] = $lParam) Then
        Call($TRAYNOTIFYIDS[$nID][5], $nID, $lParam)
    EndIf
    ;nickston+ 04.01.15 
    #cs
    Switch $lParam
        Case $WM_LBUTTONDOWN
            $nClick = 1
        case $WM_LBUTTONUP
            $nClick = 2
        case $WM_LBUTTONDBLCLK
            $nClick = 4
        case $WM_RBUTTONDOWN
            $nClick = 8
        case $WM_RBUTTONUP
            $nClick = 16
        case $WM_RBUTTONDBLCLK
            $nClick = 32
        case $WM_MOUSEMOVE
            $nClick = 64
    EndSwitch
    If BitAnd($nClick, $TRAYNOTIFYIDS[$nID][3]) And $TRAYNOTIFYIDS[$nID][2] > 0 Then
    #ce

$nClick=GetMouseCode($lParam)
    If BitAnd($nclick, $TRAYNOTIFYIDS[$nID][3]) And $TRAYNOTIFYIDS[$nID][2] > 0 Then
        Local $hMenu = GUICtrlGetHandle($TRAYNOTIFYIDS[$nID][2])
        If $hMenu <> 0 Then
            Local $stPoint = DllStructCreate("int;int")
            GetCursorPos(DllStructGetPtr($stPoint))

            SetForegroundWindow($hWnd)

            TrackPopupMenuEx($hMenu, 0, DllStructGetData($stPoint, 1), DllStructGetData($stPoint, 2), $hWnd, 0)

            PostMessage($hWnd, 0, 0, 0)
        EndIf
    EndIf
EndFunc
Func _TrayIconCreate($sToolTip = "", $sIconFile = @AutoItExe, $nIconID = 0, $sCallback = "", $nMsg = 0, $hIcon = 0)
    If $sToolTip = "" Then $sToolTip = $sDefaultTT
    ;nickston+
    #cs
    $nIconID = _GetIconID($nIconID, $sIconFile)

    If $sIconFile = "" Then
        If $hIcon = 0 Then
            If $nIconID = 0 Then
                $sIconFile = @AutoItExe
            Else
                $hIcon = LoadIcon(0, $nIconID)
            EndIf
        EndIf
    EndIf

    If $sIconFile <> "" Then
        Local $stIcon = DllStructCreate("hwnd")

        If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
            $hIcon = DllStructGetData($stIcon, 1)
        Else
            $hIcon = LoadIcon(0, 32516)
        EndIf
    EndIf

    If $TRAYMSGWND = 0 Then
        $TRAYMSGWND = GUICreate("", 1, 1, 9999, 9999, -1, 0x00000080)
        GUISetState()
        ShowWindow($TRAYMSGWND, @SW_HIDE)
    EndIf

    Local $nNID = _GetNewTrayIndex()
    If $nNID = 0 Then
        DestroyIcon($hIcon)
        Return 0
    EndIf
    #ce
    ;nickston-
;   #cs
    If $TRAYMSGWND = 0 Then
        $TRAYMSGWND = GUICreate("", 1, 1, 9999, 9999, -1, 0x00000080)
        GUISetState()
        ShowWindow($TRAYMSGWND, @SW_HIDE)
    EndIf

    Local $nNID = _GetNewTrayIndex()
    If $nNID = 0 Then
        ;DestroyIcon($hIcon)
        Return 0
    EndIf
    $hIcon=-1
;#ce
    $TRAYNOTIFYIDS[$nNID][0] = $nNID
    $TRAYNOTIFYIDS[$nNID][1] = $hIcon
    $TRAYNOTIFYIDS[$nNID][2] = 0
    ;nickston+ 04.01.15
    ;$TRAYNOTIFYIDS[$nNID][3] = 9
    $TRAYNOTIFYIDS[$nNID][3] = 10
    ;nickston-
    $TRAYNOTIFYIDS[$nNID][4] = $sToolTip
    $TRAYNOTIFYIDS[$nNID][5] = $sCallback
    $TRAYNOTIFYIDS[$nNID][6] = $nMsg
    $TRAYNOTIFYIDS[$nNID][7] = FALSE
    $TRAYNOTIFYIDS[$nNID][8] = FALSE

    _TrayIconSetIcon($nNID,$sIconFile,$nIconID)
    $TRAYLASTID = $nNID

    Return $nNID
EndFunc
Func GetMouseCode($WM_Code)
    Switch $WM_Code
        Case $WM_MOUSEFIRST
            $nClick = 1
        Case $WM_MOUSEMOVE
            $nClick = 1
        Case $WM_LBUTTONDOWN
            $nClick = 2
        case $WM_LBUTTONUP
            $nClick = 4
        case $WM_LBUTTONDBLCLK
            $nClick = 8
        case $WM_RBUTTONDOWN
            $nClick = 16
        case $WM_RBUTTONUP
            $nClick = 32
        case $WM_RBUTTONDBLCLK
            $nClick = 64
        case $WM_MBUTTONDOWN
            $nClick = 128
        case $WM_MBUTTONUP
            $nClick = 256
        case $WM_MBUTTONDBLCLK
            $nClick = 512
        case $WM_MOUSEWHEEL
            $nClick = 1024
        case $WM_XBUTTONDOWN
            $nClick = 2048
        case $WM_XBUTTONUP
            $nClick = 4096
        case $WM_XBUTTONDBLCLK
            $nClick = 8192
        case $WM_MOUSEHWHEEL
            $nClick = 16384
    EndSwitch
    Return $nClick
EndFunc
Edited by nickston
Link to comment
Share on other sites

UEZ, I don't understand at all why you want to close this tread. I could see your point

  • if the original code was faulty and outdated
  • if an update was completely depending on Holger
  • if I were adding a lot of new code to the UDF, and in that way creating a completely new UDF
  • if this thread had been inactive for several years, and I suddenly added an update to an UDF which isn't used anymore
A little simplified this UDF makes functions in Microsoft DLL files available to AutoIt and calls these functions in response to WM_DRAWITEM and WM_MEASUREITEM messages with the purpose of adding colors and icons to menu items. The code prepares and executes the DllCalls.

The functions in the DLL files are highly depending on structures. A lot of the code is used to create structures and fill the structures with data.

Another big part of the code is used to manipulate a bunch of arrays to keep track of the menu items.

Neither DllStruct-commands nor commands to read/write data in arrays have changed much since 2008. This means that the original code by Holger is not faulty and is not outdated. The code runs perfectly under the current versions of AutoIt (3.3.10/12).

Since the UDF (simplified) only prepares and executes DllCalls, the date of the UDF really doesn't matter as long as the code is working. What matters according to dates, are the dates of the DLL files. On a Win 7/8 PC the DLLs are much younger than the UDF.

Most of the code in the UDF is about calling functions in Microsoft DLLs with DllCall. To use DllCall you must implement the specifications as you find in the Microsoft documentation. This is what Holger has done. To be able to update the UDF all you have to do is to read the documentation. This is not depending on Holger.

Because so much of the code is about implementing Microsoft specifications, a completely new UDF would more or less look like the old UDF. The specifications has not changed much since 2008. The new and old code would be the same. What's the purpose then in creating a new UDF. It seems more reasonable to update the original UDF by Holger.

What I have done is nothing compared to the work by Holger. I have cleaned up the constants. Probably 5% of the code. Because constants in include files are reorganized from time to time, it's not surprising that an UDF from 2008 needs some updates to be able to run under the current AutoIt versions.

Then I have added a single line of code here and there. Code lines that I have copied directly from the posts in this thread. You can find a list in post 289. Some of the code lines added by Holger himself e.g. the x64 update in post 266 in january 2010.

I have not added a single line of my own code to the UDF. This is still the original code by Holger with a few modifications by ProgAndy. Because the code is still the original code, this thread is the proper place to add the update.

This thread seems still to be valuable for a lot of AutoIt users. The thread is still active. There has been added new posts more or less regularly.

I simply just don't understand the purpose of closing the thread. Don't do that. And I'll certainly not just steal the code created by Holger, and add it to a new thread as if it was my own code.

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