Jump to content

Nesting GUI within ModernMenu tray


Recommended Posts

I'm beginning to learn how to use ModernMenu, and I'm having some issues creating a GUI from a tray item. This is my MenuEvents function:

Func MenuEvents()
    
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE, $trExit
            _TrayIconDelete($nTrayIcon); Works fine
            Exit
        Case $trAbout 
            ShellExecute(@ScriptDir & "\Readme.txt"); Works fine
        Case $trSettings
            Settings(); Doesn't work :(
    EndSwitch

EndFunc

And this is my Settings function:

Func Settings()
    Global $buSubPath = "In BackUp's subfolder"; 0
    Global $buSub = "In subfolder of each file's root folder"; 1
    Global $buUser = "Choose my own location"; 2
    $SettingsGUI = GUICreate("BackUp! Settings", 220, 120, -1, -1); will create a dialog box that when displayed is centered
    GUICtrlCreateLabel("Where should backups be stored?", 10, 10, 200, 20)
; Read the config INI to find the default value
    If FileExists($buIniPath) Then
        Local $buPathReadDefault = IniRead($buIniPath, "BackUp.Settings", "bupath", $sIniErrorMsg)
    Else
        $buPathDefault = $buSubPath
    EndIf
    If FileExists($buIniPath) And $buPathReadDefault = 0 Then
        $buPathDefault = $buSubPath
    EndIf                       
    If FileExists($buIniPath) And $buPathReadDefault = 1 Then
        $buPathDefault = $buSub
    EndIf
    If FileExists($buIniPath) And $buPathReadDefault = 2 Then
        $buPathDefault = $buUser
        $buSetGlobal = 1
    EndIf
    
    $sDefaultGlobal = IniRead($buIniPath, "BackUp.Settings", "global", $sIniErrorMsg)
    $sConfigCombo = GUICtrlCreateCombo ($buSub, 10, 30); create first item                  
    GUICtrlSetData(-1,$buSubPath & "|" & $buUser, $buPathDefault); add other item snd set a new default
    $sConfigGlobal = GUICtrlCreateCheckbox("Global?", 10, 55, 120, 20)
    GUICtrlSetState($sConfigGlobal, $GUI_DISABLE)
    If $buSetGlobal = 1 And $sDefaultGlobal = 1 Then
        GUICtrlSetState($sConfigGlobal, $GUI_CHECKED)
    EndIf

    $sConfigGlobalEnabled = False
    $sSave = GUICtrlCreateButton("Save", 10, 80, 65)
    $sRestore = GUICtrlCreateButton("Restore", 78, 80, 65)
    $sCancel = GUICtrlCreateButton("Cancel", 146, 80, 65)

    GUISetState(@SW_SHOW, $SettingsGUI)
    While 1
        $sMsg = GUIGetMsg()
        $sGetCombo = GUICtrlRead($sConfigCombo)
        Global $sGetGlobal = GUICtrlRead($sConfigGlobal)
        Select
            Case $sMsg = $GUI_EVENT_CLOSE Or $sMsg = $sCancel
                GUISetState(@SW_HIDE, $SettingsGUI)
                GUIDelete($SettingsGUI)
                ExitLoop
            Case $sGetCombo = $buSub And $sConfigGlobalEnabled
                GUICtrlSetState($sConfigGlobal, $GUI_DISABLE)
                $sConfigGlobalEnabled = False
            Case $sGetCombo = $buSubPath And $sConfigGlobalEnabled
                GUICtrlSetState($sConfigGlobal, $GUI_DISABLE)
                $sConfigGlobalEnabled = False
            Case $sGetCombo = $buUser And Not $sConfigGlobalEnabled
                GUICtrlSetState($sConfigGlobal, $GUI_ENABLE)
                $sConfigGlobalEnabled = True
            Case $sMsg = $sConfigGlobal And $sGetGlobal = 1
                Global $buGlobalPath = FileSelectFolder("Where should all backups be stored?", @MyDocumentsDir)
            Case $sMsg = $sSave
                $sBackUpPath = GuiCtrlRead($sConfigCombo)
                    If $sBackUpPath = $buSubPath Then
                        $buPath = 0
                    EndIf
                    If $sBackUpPath = $buSub Then
                        $buPath = 1
                    EndIf
                    If $sBackUpPath = $buUser Then
                        $buPath = 2
                    EndIf                               
                IniWrite($buIniPath, "BackUp.Settings", "bupath", $buPath)
                IniWrite($buIniPath, "BackUp.Settings", "global", $sGetGlobal)
                IniWrite($buIniPath, "BackUp.Settings", "globalpath", $buGlobalPath)
                GUISetState(@SW_HIDE)
                ExitLoop
            Case $sMsg = $sRestore
                GUISetState(@SW_HIDE)
                FileDelete($buIniPath)
                MsgBox(0, "BackUp! Settings", "The default settings have been restored.")
                ExitLoop
            EndSelect
        Wend
EndFunc

I'm migrating this over from AutoIt's native tray menu, where the GUI works fine. But when I use it in conjunction with Modern Menu, none of the buttons work any more. Can anybody see where I'm going wrong? Thanks.

Edit: You can ignore my GUI/Settings function, as that's not the problem. I've tried it with a sample GUI from the documentation (specifically the CreateButton example) and the buttons still don't work. I've tried placing the GUI code directly after the respective Case, as well as storing it in a function. Bupkis. muttley

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