Jump to content

Two problems with my first app


Recommended Posts

Hi,

My first problem is not work gui "Settings" after select in system tray icon and the second problem is how to combine left click and right click with diferent menus.
Sorry for my english!!! :sweating:
By the By, I am newbie in AutoIt

#include <GUIConstantsEx.au3>
#NoTrayIcon
Opt("TrayMenuMode", 1)
TraySetClick(16) ; Only click right 
TraySetIcon("shell32.dll", -28)
Local $About = TrayCreateItem("About")
Local $MenuSettings = TrayCreateItem("Settings")
Local $MenuShutdownExit = TrayCreateItem("Exit")
TraySetState()
While 1
    Local $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $About
            MsgBox(0, "About", "Create by Lapsop")
            TrayItemSetState($About, $TRAY_UNCHECKED)
         Case $msg = $MenuSettings
            _GetSettings()
            TrayItemSetState($MenuSettings, $TRAY_UNCHECKED)
        Case $msg = $MenuShutdownExit
            Exit
    EndSelect
WEnd
Exit

Func _GetSettings()
    $GUISettings = GUICreate("Settings", 400, 300)
    $MenuSettings = GUICtrlCreateMenu("Menu")
    $MenuSettingsRestore = GUICtrlCreateMenuItem("Restore", $MenuSettings)
    $MenuSettingsExit = GUICtrlCreateMenuItem("Exit", $MenuSettings)
    GUISetBkColor(0xFFFFFF)
    $GUIGroupCheckboxes = GUICtrlCreateGroup("Active or Deactive Shourtcut", 20, 20, 360, 190)
    Local $Checkboxes[10][2]
    $Checkboxes[0][1] = "Abort"
    $Checkboxes[1][1] = "Boot Options"
    $Checkboxes[2][1] = "Hybrid Shutdown"
    $Checkboxes[3][1] = "Shutdown"
    $Checkboxes[4][1] = "Restart"
    $Checkboxes[5][1] = "Hibernate"
    $Checkboxes[6][1] = "Sleep"
    $Checkboxes[7][1] = "Switch User"
    $Checkboxes[8][1] = "Sign Out"
    $Checkboxes[9][1] = "Lock"
    $TopPosition = 50
    $LeftPosition = 40
    For $i = 0 To UBound($Checkboxes, 1) - 1
        $Checkboxes[$i][0] = GUICtrlCreateCheckbox($Checkboxes[$i][1], $LeftPosition, $TopPosition, 160, 20)
        $TopPosition += 30
        If $i > 3 Then
            $LeftPosition = 210
        EndIf
        If $i = 4 Then
            $TopPosition = 50
        EndIf
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $SaveButton = GUICtrlCreateButton("Save", 20, 230, 75, 30)
    $CancelButton = GUICtrlCreateButton("Cancel", 120, 230, 75, 30)
    $HelpButton = GUICtrlCreateButton("Help", 305, 230, 75, 30)
    GUISetState(@SW_SHOW, $GUISettings)

    While 1
        $GUIMsg = GUIGetMsg()
        Select
            Case $GUIMsg = $MenuSettingsRestore
               Exit; undefined options
            Case $GUIMsg = $MenuSettingsExit
                GUISetState( @SW_HIDE, $GUISettings )
            Case $GUIMsg = $SaveButton
                For $i = 0 To UBound($Checkboxes, 1) - 1
                    If BitAND(GUICtrlRead($Checkboxes[$i][0]), $GUI_CHECKED) = $GUI_CHECKED Then
                        RegWrite("HKEY_CURRENT_USER\Software\Menu Shutdown", $Checkboxes[$i][1], "REG_SZ", "1")
                    Else
                        RegWrite("HKEY_CURRENT_USER\Software\Menu Shutdown", $Checkboxes[$i][1], "REG_SZ", "0")
                    EndIf
                Next
                GUISetState( @SW_HIDE, $GUISettings )
            Case $GUIMsg = $CancelButton
                GUISetState( @SW_HIDE, $GUISettings )
            Case $GUIMsg = $HelpButton
                MsgBox(0, "Help", "test help")
     Case $GUIMsg = $GUI_EVENT_CLOSE
        GUIDelete( $GUISettings )
        EndSelect
    WEnd
EndFunc
Edited by lapsop
Link to comment
Share on other sites

Well, a quick look at your code reveals you don't have an ExitLoop in your Settings function, only a GUIDelete and an Exit in another part, which will close your whole program altogether.

I haven't studied the rest of the logic of your code, but that's the place to start, as it appears it gets trapped in the Settings loop, which you probably aren't aware of, because you may have killed the GUI with the GUIDelete. You may get what you want by putting the ExitLoop just after that delete.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Not everything sorted, but see if this suits your needs better.. As for the different buttons for different menus, haven't tried that yet, not sure how to do it too..

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#NoTrayIcon
Opt("TrayMenuMode", 1)
TraySetClick(16) ; Only click right
TraySetIcon("shell32.dll", -28)
Local $About = TrayCreateItem("About")
Local $MenuSettings = TrayCreateItem("Settings")
Local $MenuShutdownExit = TrayCreateItem("Exit")
TraySetState()
While 1
    Local $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $About
            MsgBox(0, "About", "Create by 23r9i0")
            TrayItemSetState($About, $TRAY_UNCHECKED)
        Case $msg = $MenuSettings
            TrayItemSetState($MenuSettings, $TRAY_UNCHECKED)
            _GetSettings()
        Case $msg = $MenuShutdownExit
            Exit
    EndSelect
WEnd
Exit

Func _GetSettings()
    $GUISettings = GUICreate("Settings", 400, 300)
    $MenuSettings1 = GUICtrlCreateMenu("Menu")
    $MenuSettingsRestore = GUICtrlCreateMenuItem("Restore", $MenuSettings1)
    $MenuSettingsExit = GUICtrlCreateMenuItem("Exit", $MenuSettings1)
    GUISetBkColor(0xFFFFFF)
    $GUIGroupCheckboxes = GUICtrlCreateGroup("Active or Deactive Shourtcut", 20, 20, 360, 190)
    Local $Checkboxes[10][2]
    $Checkboxes[0][1] = "Abort"
    $Checkboxes[1][1] = "Boot Options"
    $Checkboxes[2][1] = "Hybrid Shutdown"
    $Checkboxes[3][1] = "Shutdown"
    $Checkboxes[4][1] = "Restart"
    $Checkboxes[5][1] = "Hibernate"
    $Checkboxes[6][1] = "Sleep"
    $Checkboxes[7][1] = "Switch User"
    $Checkboxes[8][1] = "Sign Out"
    $Checkboxes[9][1] = "Lock"
    $TopPosition = 50
    $LeftPosition = 40
    For $i = 0 To UBound($Checkboxes, 1) - 1
        $Checkboxes[$i][0] = GUICtrlCreateCheckbox($Checkboxes[$i][1], $LeftPosition, $TopPosition, 160, 20)
        $TopPosition += 30
        If $i > 3 Then
            $LeftPosition = 210
        EndIf
        If $i = 4 Then
            $TopPosition = 50
        EndIf
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $SaveButton = GUICtrlCreateButton("Save", 20, 230, 75, 30)
    $CancelButton = GUICtrlCreateButton("Cancel", 120, 230, 75, 30)
    $HelpButton = GUICtrlCreateButton("Help", 305, 230, 75, 30)
    GUISetState(@SW_SHOW, $GUISettings)

    While 1
        $GUIMsg = GUIGetMsg()
        Select
            Case $GUIMsg = $MenuSettingsRestore
               Exit; undefined options
           Case $GUIMsg = $MenuSettingsExit
                GUISetState( @SW_HIDE, $GUISettings )
                ExitLoop
            Case $GUIMsg = $SaveButton
                For $i = 0 To UBound($Checkboxes, 1) - 1
                    If BitAND(GUICtrlRead($Checkboxes[$i][0]), $GUI_CHECKED) = $GUI_CHECKED Then
                        RegWrite("HKEY_CURRENT_USER\Software\Menu Shutdown", $Checkboxes[$i][1], "REG_SZ", "1")
                    Else
                        RegWrite("HKEY_CURRENT_USER\Software\Menu Shutdown", $Checkboxes[$i][1], "REG_SZ", "0")
                    EndIf
                Next
                GUISetState( @SW_HIDE, $GUISettings )
            Case $GUIMsg = $CancelButton
                GUISetState( @SW_HIDE, $GUISettings )
                ExitLoop
            Case $GUIMsg = $HelpButton
                MsgBox(0, "Help", "test help")
     Case $GUIMsg = $GUI_EVENT_CLOSE
        GUIDelete( $GUISettings )
        ExitLoop
        EndSelect
    WEnd
EndFunc

PS: you can do the menus with

TraySetOnEvent ($TRAY_EVENT_PRIMARYDOWN, "Prim")
TraySetOnEvent ($TRAY_EVENT_SECONDARYDOWN, "Sec")

but it gets more complicated, but that's how i would do.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Thanks careca,

but not understand why it does not work the old code, it was for the include constants.au3 or by the order of TrayItemSetState($MenuSettings, $TRAY_UNCHECKED) and _GetSettings()?

Now I will look the code to enable the two menus in the system tray

Link to comment
Share on other sites

Added some ExitLoop's, because if you don't exit the loop when you cancel or close the settings window,

it will get stuck in there, just hidden in background, as 'TheSaint' said would happen, back in post #2.

As for TrayItemSetState($MenuSettings, $TRAY_UNCHECKED), you had it bellow the function call,

so the function was called, (jumped to function so to speak) and the code was never executed, so the item

was never unchecked.

Greetings

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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