Jump to content

Launching a series of programs from a GUI with checked check boxes


aa2zz6
 Share

Recommended Posts

I am trying to launch a series of programs based off a few checked checkbox's but I can't get the button to launch anything. I tried using the GUICtrlCreateButton example in the help file but that won't even open notepad. Am I setting this up incorrectly?

https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm

Script -

#include <AutoItConstants.au3>
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <GUIImageList.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
Global $hGUI = GUICreate("Form", 500, 500, @DesktopWidth / 2 - 500 / 2, @DesktopHeight / 2 - 700 / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $label = GUICtrlCreateLabel("Esri Products", 35, 10) ; first cell 70 width
Global $Checkbox1 = GUICtrlCreateCheckbox("ArcGIS Desktop", 35, 25, 97, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("ArcGIS Catalog", 35, 45, 97, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("ArcGIS PRO", 35, 65, 97, 17)
Global $LoadSoftware = GUICtrlCreateButton("Launch", 30, 200, 85, 25)
Global $Save = GUICtrlCreateButton("Save", 30, 95, 75, 25, 0)
GUICtrlSetOnEvent(-1, "SaveClick")
Global $Load = GUICtrlCreateButton("Load", 30, 130, 75, 25, 0)
GUICtrlSetOnEvent(-1, "LoadClick")
Global $Clear = GUICtrlCreateButton("Clear", 30, 165, 75, 25, 0)
GUICtrlSetOnEvent(-1, "ClearClick")
Global $log = GUICtrlCreateEdit("", 20, 285, 460, 200, BitOR($ES_WANTRETURN, $ES_READONLY, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetFont($log, 12, 800, "verdana") ;Change Font Size to 12
GUICtrlSetBkColor($log, 0xFFFFFF)
GUICtrlSetColor($log, $COLOR_Green)
GUICtrlSetResizing(-1, 802)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idClose
            ExitLoop

        Case $LoadSoftware
            If IsChecked($Checkbox1) Then
                GUICtrlSetData($log, _NowTime() & " Loading ArcGIS Desktop.." & @CRLF, 1)
                Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
                ;"C:\EIS\EIS\eis shape\MAP WORKSPACE - Office Use.mxd"
            Else
                MsgBox($MB_SYSTEMMODAL, "", " Unable to locate file path..", 0, $hGUI)
            EndIf
            If IsChecked($Checkbox2) Then
                GUICtrlSetData($log, _NowTime() & " Loading ArcGIS Catalog.." & @CRLF, 1)
                Run("C:\Program Files (x86)\ArcGIS\Desktop10.5\bin", "", @SW_SHOWMAXIMIZED)
            Else
                MsgBox($MB_SYSTEMMODAL, "", " Unable to locate file path..", 0, $hGUI)
            EndIf
            If IsChecked($Checkbox3) Then
                GUICtrlSetData($log, _NowTime() & " Loading ArcGIS Pro.." & @CRLF, 1)
                Run("C:\EIS\EIS\eis shape\ArcGIS Pro Workspace.aprx", "", @SW_SHOWMAXIMIZED)
            Else
                MsgBox($MB_SYSTEMMODAL, "", " Unable to locate file path..", 0, $hGUI)
            EndIf
    EndSwitch
WEnd

Func ClearClick()
    SetCheckedState($Checkbox1, 0)
    SetCheckedState($Checkbox2, 0)
    SetCheckedState($Checkbox3, 0)
EndFunc   ;==>ClearClick

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

Func LoadClick()
    SetCheckedState($Checkbox1, IniRead(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox1", False))
    SetCheckedState($Checkbox2, IniRead(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox2", False))
    SetCheckedState($Checkbox3, IniRead(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox3", False))
EndFunc   ;==>LoadClick

Func SaveClick()
    IniWrite(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox1", IsChecked($Checkbox1))
    IniWrite(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox2", IsChecked($Checkbox2))
    IniWrite(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox3", IsChecked($Checkbox3))
EndFunc   ;==>SaveClick


; ===============================================================================================================================
; SetChecked State      : Set checked state of Checkbox or Radio button
; ===============================================================================================================================
Func SetCheckedState($nCtrl, $iState)
    If $iState > 0 Then
        GUICtrlSetState($nCtrl, $GUI_CHECKED)
        If $nCtrl = 4 Then
            GUICtrlSetData($log, _NowTime() & " ArcGIS Desktop is checked" & @CRLF, 1)
        EndIf
        If $nCtrl = 5 Then
            GUICtrlSetData($log, _NowTime() & " ArcGIS Catalog is checked" & @CRLF, 1)
        EndIf
        If $nCtrl = 6 Then
            GUICtrlSetData($log, _NowTime() & " ArcGIS PRO is checked" & @CRLF, 1)
        EndIf
    Else
        GUICtrlSetState($nCtrl, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>SetCheckedState

; ===============================================================================================================================
; IsChecked             :Get checked state of Checkbox or Radio button
; ===============================================================================================================================
Func IsChecked($nCtrl)
    If BitAND(GUICtrlRead($nCtrl), $GUI_CHECKED) = $GUI_CHECKED Then Return 1
    Return 0
EndFunc   ;==>IsChecked

 

Link to comment
Share on other sites

  • Developers

Just define an GUICtrlSetOnEvent() for the button like the other buttons and put the logic for in it its own Func.

Jod

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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