Jump to content

GUI/Tray Menu with icons and colors


Holger
 Share

Recommended Posts

I added

#NoTrayIcon
_TrayIconCreate("Bot V 1.0 - ©Acanis", @ScriptDir & "/tray.ico")
_TrayIconSetState()

to my script... But I get this error-msg ->

C:\Program Files\AutoIt3\Include\ModernMenuRaw.au3(133,77) : ERROR: $WM_MOUSEMOVE previously declared as a 'Const'
If Not IsDeclared("WM_MOUSEMOVE")           Then Global Const $WM_MOUSEMOVE = 0x0200
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Include\ModernMenuRaw.au3(135,77) : ERROR: $WM_LBUTTONUP previously declared as a 'Const'
If Not IsDeclared("WM_LBUTTONUP")           Then Global Const $WM_LBUTTONUP = 0x0202
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Acanis\Desktop\AutoIT\***\***.au3 - 2 error(s), 0 warning(s)
!>18:48:09 AU3Check ended.rc:2

What can I do?...

Thanks

Regards,

Acanis

Edited by Acanis
Link to comment
Share on other sites

  • 2 months later...

Go to the line that the error is on and comment it out. Somewhere else in the script, that constant has already been declared and you can't redeclare a constant because it is... well... constant.

Edit: Actually, this happens quite a bit in these scripts. Because of the way it is declared in the udf, you can either comment out the line or click "Continue Anyway" when the error comes up. Either method will work fine.

Edited by dantay9
Link to comment
Share on other sites

  • 2 weeks later...
  • 5 weeks later...

Hi Max ;)

replace in the files "ModernMenu.au3"/"ModernMenuRaw.au3" the line:

Local $stDrawItem   = DllStructCreate("uint;uint;uint;uint;uint;dword;dword;int[4];dword", $lParam)

with

Local $stDrawItem   = DllStructCreate("uint;uint;uint;uint;uint;hwnd;hwnd;int[4];dword", $lParam)

That should solve the x64-problem.

Didn't made an update for this script (and will make none, only if I find some minutes...).

Greets

Holger

Link to comment
Share on other sites

Who is that man that just stampeded through here? I think it may have been our long lost friend Holger.

Glad to see you are stil amongst the living. Come back soon when you have some time to stay.

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

Hi Max :evil:

replace in the files "ModernMenu.au3"/"ModernMenuRaw.au3" the line:

Local $stDrawItem   = DllStructCreate("uint;uint;uint;uint;uint;dword;dword;int[4];dword", $lParam)

with

Local $stDrawItem   = DllStructCreate("uint;uint;uint;uint;uint;hwnd;hwnd;int[4];dword", $lParam)

That should solve the x64-problem.

Didn't made an update for this script (and will make none, only if I find some minutes...).

Greets

Holger

Hi Holger :evil:

God bless you ! I'm thank you very much for your quick reply.

I want to ask a question to you. I compile sampleGUIandTray.au3 as 64-bit or 32-bit and I am running sampleGUIandTray.exe on the Vista. And I am running again after closing the current shell (Explorer, BsExplorer or LiteStep) but I can not see the sampleGUIandTray.exe's tray icons in the taskbar ! Especially when this problem shows itself to change the shell of VistaPE (for the vpeldr try icon) !

How can i enable without closing again the tray icon of sampleGUIandTray.exe after again when it run the current shell ?

Best regards ;)

post-36686-12628986024172_thumb.jpg

Edited by maxrealqnx
Link to comment
Share on other sites

As a small workaround just add something like these lines in your script:

$nTaskBarCreated = DllCall("user32.dll", "uint", "RegisterWindowMessageA", "str", "TaskbarCreated")
GUIRegisterMsg($nTaskBarCreated[0], "RecreateIcons")
...
; Main GUI Loop
...

Func RecreateIcons()
    _TrayIconSetState($nTrayIcon1, 2)
    _TrayIconSetState($nTrayIcon1, 1)
    _TrayIconSetState($nTrayIcon3, 2)
    _TrayIconSetState($nTrayIcon3, 1)
EndFunc
...

Greats

Holger

Link to comment
Share on other sites

Pn Vista and Win7 you have to call an additional function

DllCall("user32.dll", "none", "ChangeWindowMessageFilter", "UINT", $nTaskBarCreated[0], "dword", 1)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

As a small workaround just add something like these lines in your script:

$nTaskBarCreated = DllCall("user32.dll", "uint", "RegisterWindowMessageA", "str", "TaskbarCreated")
GUIRegisterMsg($nTaskBarCreated[0], "RecreateIcons")
...
; Main GUI Loop
...

Func RecreateIcons()
    _TrayIconSetState($nTrayIcon1, 2)
    _TrayIconSetState($nTrayIcon1, 1)
    _TrayIconSetState($nTrayIcon3, 2)
    _TrayIconSetState($nTrayIcon3, 1)
EndFunc
...

Greats

Holger

Hi Holger and ProgAndy :evil:

I'm thank you very much for your interest and support. God bless you !

Best regards ;)

Link to comment
Share on other sites

  • 6 months later...

How do I change the background color of the main menu? Function _GUICtrlMenu_SetMenuBackground does not work. Unfortunately I can not detect that the script specified by the author.

edit:

ok now i know :blink:

example:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiMenu.au3>

Global Const $COLOR_ACTIVECAPTION = 2
Global Const $COLOR_GRADIENTACTIVECAPTION = 27

_Main()

Func _Main()
    Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]
    ; Red and Yellow
    Local $aColors[2] = [255, 65535], $aSaveColors[2]
   
    $hGui = GUICreate("My GUI", 300, 200)

    $FileMenu = GUICtrlCreateMenu("&File")
    $OpenItem = GUICtrlCreateMenuItem("&Open", $FileMenu)
    $SaveItem = GUICtrlCreateMenuItem("&Save", $FileMenu)
    GUICtrlCreateMenuItem("", $FileMenu)

    $OptionsMenu = GUICtrlCreateMenu("O&ptions", $FileMenu)
    $ViewItem = GUICtrlCreateMenuItem("View", $OptionsMenu)
    GUICtrlCreateMenuItem("", $OptionsMenu)
    $ToolsItem = GUICtrlCreateMenuItem("Tools", $OptionsMenu)

    GUICtrlCreateMenuItem("", $FileMenu)
    $ExitItem = GUICtrlCreateMenuItem("&Exit", $FileMenu)

    $HelpMenu = GUICtrlCreateMenu("&?")
    $AboutItem = GUICtrlCreateMenuItem("&About", $HelpMenu)

    $EndBtn = GUICtrlCreateButton("End", 110, 140, 70, 20)

    ; Minimum OS are Windows98 and 2000
    If @OSVersion <> "WIN_95" And @OSVersion <> "WIN_NT4" Then
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($FileMenu), _WinAPI_CreateSolidBrush(0xEEBB99))
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($OptionsMenu), _WinAPI_CreateSolidBrush(0x66BB99))
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($HelpMenu), _WinAPI_CreateSolidBrush(0x99BBEE))
          $hmenu = _GUICtrlMenu_GetMenu($hGui)
        _GUICtrlMenu_SetMenuBackground($hmenu, _WinAPI_CreateSolidBrush(0x99BBEE))
    EndIf

    $aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)
    $aSaveColors[1] = _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)

    _WinAPI_SetSysColors2($aElements, $aColors)

    GUISetState()

    While 1
        $Msg = GUIGetMsg()

        Switch $Msg
            Case $EndBtn, $GUI_EVENT_CLOSE
                ExitLoop

            Case $AboutItem
                MsgBox(64, "About...", "Colored menu sample")
        EndSwitch
    WEnd

    GUIDelete()
   
    _WinAPI_SetSysColors2($aElements, $aSaveColors)

    Exit

EndFunc   ;==>_Main

Func _WinAPI_SetSysColors2($vElements, $vColors)
    Local $isEArray = IsArray($vElements), $isCArray = IsArray($vColors)
    Local $iElementNum
   
    If Not $isCArray And Not $isEArray Then
        $iElementNum = 1
    ElseIf $isCArray Or $isEArray Then
        If Not $isCArray Or Not $isEArray Then Return SetError(-1, -1, False)
        If UBound($vElements) <> UBound($vColors) Then Return SetError(-1, -1, False)
        $iElementNum = UBound($vElements)
    EndIf
   
    Local $tElements = DllStructCreate("int Element[" & $iElementNum & "]")
    Local $tColors = DllStructCreate("int NewColor[" & $iElementNum & "]")
    Local $pElements = DllStructGetPtr($tElements)
    Local $pColors = DllStructGetPtr($tColors)


    If Not $isEArray Then
        DllStructSetData($tElements, "Element", $vElements, 1)
    Else
        For $x = 0 To $iElementNum - 1
            DllStructSetData($tElements, "Element", $vElements[$x], $x + 1)
        Next
    EndIf

    If Not $isCArray Then
        DllStructSetData($tColors, "NewColor", $vColors, 1)
    Else
        For $x = 0 To $iElementNum - 1
            DllStructSetData($tColors, "NewColor", $vColors[$x], $x + 1)
        Next
    EndIf
    Local $iResults = DllCall("user32.dll", "int", "SetSysColors", "int", $iElementNum, "ptr", $pElements, "ptr", $pColors)
    If @error Then Return SetError(-1, -1, False)
    Return $iResults[0] <> 0
EndFunc   ;==>_WinAPI_SetSysColors
Edited by ZwinnyRolnik
Link to comment
Share on other sites

  • 3 months later...

Hi guys

Im loving the modern menu udf but ive come across a snag for myself. Ive created a prog.ini and in it currently is just the calc.exe. Ive integrated it into the menu and it all looks fine however a few seconds after starting the calculator suddenly starts popping up repeatedly. I think it has some thing to do with the $iIndex = _ArraySearch($aProg, $msg, 1) ShellExecute($aProg[$iIndex][1]) lines. can anyone point me in the right direction

thanks

#include <GUIConstants.au3>
#include "ModernMenuRaw.au3" ; Only unknown constants are declared here
#include <array.au3>
#NoTrayIcon

$aProg = IniReadSection(@ScriptDir & "\prog.ini", "Prog")
$aUserProg = IniReadSection(@ScriptDir & "\prog.ini", "UserProg")
$aWeb = IniReadSection(@ScriptDir & "\prog.ini", "Web")
$aUserWeb = IniReadSection(@ScriptDir & "\prog.ini", "UserWeb")
$aDrive = IniReadSection(@ScriptDir & "\prog.ini", "Drive")

$hMainGUI       = GUICreate("Sample Menu")

SetBlueTrayColors()

_SetFlashTimeOut(250)



$testbutton = GUICtrlCreateButton("Test", 100, 200, 70, 20)
GUISetState()

; *** Create the tray icon ***
$nTrayIcon1     = _TrayIconCreate("Tools", "shell32.dll", -13)
_TrayIconSetClick(-1, 16)
_TrayIconSetState() ; Show the tray icon

; *** Create the tray context menu ***
$nTrayMenu1     = _TrayCreateContextMenu() ; is the same like _TrayCreateContextMenu(-1) or _TrayCreateContextMenu($nTrayIcon1)
$nSideItem3     = _CreateSideMenu($nTrayMenu1)
_SetSideMenuText($nSideItem3, "HealthCheck")
_SetSideMenuColor($nSideItem3, 0x00FFFF) ; yellow; default color - white
_SetSideMenuBkColor($nSideItem3, 0x802222) ; bottom start color - dark blue
_SetSideMenuBkGradColor($nSideItem3, 0x4477AA) ; top end color - orange
;_SetSideMenuImage($nSideItem3, "shell32.dll", 309, TRUE)

$MenuMenu       = _TrayCreateMenu("Menu") ; is the same like _TrayCreateMenu("Menu", -1) or _TrayCreateMenu("Menu", $nTrayMenu1)
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0)
$MenuDrives     = _TrayCreateMenu("Driveinfo")
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0); Force changing to ownerdrawn sometimes needed, i.e. in mixed menu
$MenuTools      = _TrayCreateMenu("Tools")
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0)
$TrayHelp       = _TrayCreateItem("Help")
$TrayRun        = _TrayCreateItem("Run...")
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0)
$TrayExit       = _TrayCreateItem("Exit")

_TrayItemSetIcon($MenuMenu, "", 0)
_TrayItemSetIcon($MenuDrives, "shell32.dll", -9)
_TrayItemSetIcon($MenuTools, "shell32.dll", -20)
_TrayItemSetSelIcon($MenuTools, "shell32.dll", -44)
_TrayItemSetIcon($TrayHelp, "shell32.dll", -24)
_TrayItemSetIcon($TrayRun, "shell32.dll", -25)
_TrayItemSetIcon($TrayExit, "shell32.dll", -28)

GUICtrlSetState($TrayHelp, $GUI_DEFBUTTON)

; *** Sub menu items ***
$TrayAdvanced   = _TrayCreateItem("Modern", $MenuMenu, -1, 1)
$TraySimple     = _TrayCreateItem("Classic", $MenuMenu, -1, 1)

_TrayItemSetIcon($TrayAdvanced, "", 0)
_TrayItemSetIcon($TraySimple, "", 0)

GUICtrlSetState($TrayAdvanced, $GUI_CHECKED)

If IsArray($aProg) Then
        For $i = 1 To $aProg[0][0]
        $aProg[$i][0] = _TrayCreateItem($aProg[$i][0], $MenuTools) ;the name of the program is replaced by the ID of the control. The link stays in the array.
        _TrayItemSetIcon($aProg[$i][0],$aProg[$i][0] , 0)
    Next
EndIf
$TrayCalc       = _TrayCreateItem("Calculator", $MenuTools)
$TrayCMD        = _TrayCreateItem("CMD", $MenuTools)
$TrayNotepad    = _TrayCreateItem("Notepad", $MenuTools)
$TrayRegedit    = _TrayCreateItem("Regedit", $MenuTools)

_TrayItemSetIcon($TrayCalc, "calc.exe", 0)
_TrayItemSetIcon($TrayCMD, "cmd.exe", 0)
_TrayItemSetIcon($TrayNotepad, "notepad.exe", 0)
_TrayItemSetIcon($TrayRegedit, "regedit.exe", 0)

GUICtrlSetState($TrayNotepad, $GUI_DISABLE)

_TrayCreateItem("Free Space:", $MenuDrives)
_TrayCreateItem("", $MenuDrives)

$arDrives = DriveGetDrive("FIXED")
For $i = 1 To $arDrives[0]
    _TrayCreateItem(StringUpper($arDrives[$i]) & " -> " & _
        StringFormat("%.2f GB", DriveSpaceFree($arDrives[$i])), $MenuDrives)
Next

; WM_MEASUREITEM and 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 font

Dim $nTrayIcon2 = 0

; Create an icon which demonstrates how to use click event - see the function 'MyTrayTipCallBack'
;Dim $nTrayIcon3 ;= _TrayIconCreate("Click me", "shell32.dll", -16, "MyTrayTipCallBack")
_TrayIconSetState()

; Main GUI Loop



While 1
    $Msg = GUIGetMsg()

    Switch $Msg
        Case $GUI_EVENT_CLOSE, $TrayExit
            ExitLoop
        Case $testbutton
            exit
        Case $TrayAdvanced, $TraySimple
            If BitAnd(GUICtrlRead($TraySimple), $GUI_CHECKED) Then
                GUICtrlSetState($TraySimple, $GUI_UNCHECKED)
                GUICtrlSetState($TrayAdvanced, $GUI_CHECKED)
                $bUseAdvTrayMenu = TRUE
            Else
                GUICtrlSetState($TraySimple, $GUI_CHECKED)
                GUICtrlSetState($TrayAdvanced, $GUI_UNCHECKED)
                $bUseAdvTrayMenu = FALSE
            EndIf

        Case $TrayCMD
            run(@WindowsDir & "\system32\cmd.exe")

        Case $TrayHelp
            If $nTrayIcon2 = 0 Then
                $nTrayIcon2 = _TrayIconCreate("New message", "shell32.dll", -14, "MyTrayTipCallBack")
                _TrayIconSetState(-1, 5) ; Show icon and start flashing -> 1 + 4
            Else
                _TrayIconSetState($nTrayIcon2, 5) ; Show icon and start flashing -> 1 + 4
            EndIf

            _TrayTip($nTrayIcon2, "New message", "A new message has arrived." & @CRLF & "Please click here to read...", 15, $NIIF_INFO)
            Case Else
            ;check if the control ID is present in an array,
            $iIndex = _ArraySearch($aProg, $msg, 1)
            ShellExecute($aProg[$iIndex][1]) ;if so execute the link that goes with it

    EndSwitch
WEnd

_TrayIconDelete($nTrayIcon1)


If $nTrayIcon2 > 0 Then _TrayIconDelete($nTrayIcon2)

Exit



Func SetBlueTrayColors()
    _SetTrayBkColor(0xFFD8C0)
    _SetTrayIconBkColor(0xEE8877)
    _SetTrayIconBkGrdColor(0x703330)
    _SetTraySelectBkColor(0x662222)
    _SetTraySelectRectColor(0x4477AA)
    _SetTraySelectTextColor(0x66FFFF)
    _SetTrayTextColor(0x000000)
EndFunc

Drunken Frat-Boy Monkey Garbage

Link to comment
Share on other sites

  • 9 months later...
  • 2 months later...

Hi Holger,

first I would like to thank you too for the great UDF that you have shared. I hope this message is catching you in good health.

Second i would like to ask if you can help me determine what is causing this peculiar problem...

Below is a very simple example GUI with a red button. The problem is that once the ;#include "ModernMenu.au3" line is un-commented, or in other words when ModernMenu.au3 is included, the button gets invisible. It is still there, but invisible.

Any idea why this is happening?

#include <GUIConstantsEx.au3>
;#include "ModernMenu.au3"
$GUI=GUICreate("Test",100,100)
$BTN=GUICtrlCreateButton("Colorful",10,10,80,80)
GUICtrlSetBKColor($BTN,0xff0000)
GUISetState()
While 1
$msg=GUIGetMSG()
Switch $MSG
  Case $GUI_EVENT_CLOSE
   ExitLoop
  Case $BTN
         MsgBox(64,"Hello","Hello World!")
EndSwitch
WEnd
Link to comment
Share on other sites

Holger hasn't been seen on the forums for alnost 2 years now. I suggest you ask in General Help and Support.

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

dv8,

The problem is actually a conflict between ModernMenu.au3 and the GUICtrlSetBkColor line - if either are commented the button is visible.

I cannot comment on ModernMenu, but I do know that colouring button is fraught with danger. There is a bug deep in the AutoIt core code which has been known about for years - the Devs have stated they will not fix it for fear of creating even bigger problems. :rip:

But you can use a BMP to colour your buttons and still have text on them - this will work with ModernMenu. This script shows you how to do it: :oops:

#include <GUIConstantsEx.au3>
#Include <GuiImageList.au3>
#include <GuiButton.au3>
 
#include "ModernMenu.au3"
 
$GUI = GUICreate("Test", 100, 100)
$BTN = GUICtrlCreateButton("Colorful", 10, 10, 80, 80)
 
$Image = _GUIImageList_Create(70, 70, 5, 3)
_GUIImageList_AddBitmap($Image, "C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Red.bmp")
_GUICtrlButton_SetImageList($BTN, $Image, 4)
 
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $BTN
            MsgBox(64, "Hello", "Hello World!")
    EndSwitch
WEnd

Any help? :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

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