PeterlFF Posted March 15, 2022 Posted March 15, 2022 (edited) I have been building a script in pieces and I am not trying to put it all together with a GUI. The GUI will be like a wizard with different pages you reveal by clicking the Next button. It will be very linear with no need for a Back button. The first page will automatically check for a couple of installed apps. The second page will have the user input 2 values. The third page will open Excel and run some macros. The fourth page will display text saying it is done and the Finish button. I have all of the code to do the actions on the different pages but I am not sure where to put it inside the GUI code. I have a While loop for the GUI to react to the buttons being clicked but I am not sure if this is what I need. Any suggestions? Here is what I have for the GUI code so far: expandcollapse popup#include <GuiConstants.au3> Dim $show = 0, $Child_[5], $children = 4 $Main = GUICreate("MS Excel Data Workflow", 516, 323, (@DesktopWidth - 516) / 2, (@DesktopHeight - 323) / 2) $Button_1 = GUICtrlCreateButton("&Next >", 335, 290, 80, 25) $Button_2 = GUICtrlCreateButton("&Finish", 420, 290, 80, 25) $Button_3 = GUICtrlCreateButton("", 10, 270, 495, 3, -1, $WS_EX_STATICEDGE) GUICtrlSetState($Button_2, $GUI_HIDE) GUISetState() $Child_[1] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Check for Required Apps", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) $Label_2 = GuiCtrlCreateLabel ("Label1", 10, 70, 260, 20) $Label_3 = GuiCtrlCreateLabel ("Label2", 10, 130, 260, 20) GUISetState() $Child_[2] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Input Runs and Wait Time", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) $Label_2 = GuiCtrlCreateLabel ("Number of Runs", 10, 70, 120, 20) $Runs = GUICtrlCreateInput("5", 10, 90, 50, 20, $ES_NUMBER) $Label_3 = GuiCtrlCreateLabel ("Wait time (seconds)", 10, 130, 120, 20) $Wait = GUICtrlCreateInput("10", 10, 150, 50, 20, $ES_NUMBER) GUISetState(@SW_HIDE) $Child_[3] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Test in Process", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) $Label_2 = GuiCtrlCreateLabel ("Run", 10, 70, 120, 20) $Label_3 = GuiCtrlCreateLabel ("Task", 10, 130, 120, 20) GUISetState(@SW_HIDE) $Child_[4] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Complete", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) GUISetState(@SW_HIDE) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 Set_Next() Case $msg = $Button_2 ExitLoop EndSelect WEnd ;--------- Functions ------------------- Func Set_Next() For $x = 1 To $children - 1 $Nwin = WinGetState($Child_[$x]) If $Nwin > 5 Then GUISetState(@SW_HIDE, $Child_[$x]) GUISetState(@SW_SHOW, $Child_[$x + 1]) Return EndIf If $x = 2 Then GUICtrlSetState($Button_2, $GUI_SHOW) GUICtrlSetState($Button_1, $GUI_HIDE) EndIf Next EndFunc Func _IsChecked($control) Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Edited March 15, 2022 by PeterlFF
PeterlFF Posted March 15, 2022 Author Posted March 15, 2022 Taking some shots in the dark and here is what I have. Again, this is like a wizard dialog box where you can only click Next to advanced to the next page. There is no Back button. I'm trying to figure out what to best place my code inside of the this GUI code. I added some code inside the Set_Next function. So when the user clicks Next, I have If statements checking what page number we are on and then it will execute the code for that page. It will be a lot of code (all of the processing I need to do) inside of the Set_Next function. This doesn't seem right to me but I think I can get it to work. Is this how it is done or is there a better way to do this? expandcollapse popup#include <GuiConstants.au3> Dim $show = 0, $Child_[6], $children = 5 Global $sRegPathx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" Global $sRegPathx64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" Global $bSearch[3] $Main = GUICreate("MS Excel Data Workflow", 516, 323, (@DesktopWidth - 516) / 2, (@DesktopHeight - 323) / 2) $Button_1 = GUICtrlCreateButton("&Next >", 335, 290, 80, 25) $Button_2 = GUICtrlCreateButton("&Finish", 420, 290, 80, 25) $Button_3 = GUICtrlCreateButton("", 10, 270, 495, 3, -1, $WS_EX_STATICEDGE) GUICtrlSetState($Button_2, $GUI_HIDE) GUISetState() $Child_[1] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Click Next to get started.", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) GUISetState() $Child_[2] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Check for Required Apps", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) $Label_2 = GuiCtrlCreateLabel ("Microsoft Office 365", 10, 70, 260, 20) $Label_2r = GuiCtrlCreateLabel ("", 10, 90, 460, 20) $Label_3 = GuiCtrlCreateLabel ("Microsoft Access Database Engine 2016", 10, 130, 260, 20) $Label_3r = GuiCtrlCreateLabel ("", 10, 150, 460, 20) GUISetState() $Child_[3] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Input Runs and Wait Time", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) $Label_2 = GuiCtrlCreateLabel ("Number of Runs", 10, 70, 120, 20) $Runs = GUICtrlCreateInput("5", 10, 90, 50, 20, $ES_NUMBER) $Label_3 = GuiCtrlCreateLabel ("Wait time (seconds)", 10, 130, 120, 20) $Wait = GUICtrlCreateInput("10", 10, 150, 50, 20, $ES_NUMBER) GUISetState(@SW_HIDE) $Child_[4] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Test in Process", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) $Label_2 = GuiCtrlCreateLabel ("Run", 10, 70, 30, 20) $Label_2t = GuiCtrlCreateLabel ("", 40, 70, 40, 20) $Label_3 = GuiCtrlCreateLabel ("Task", 10, 130, 30, 20) $Label_3t = GuiCtrlCreateLabel ("", 40, 130, 40, 20) GUISetState(@SW_HIDE) $Child_[5] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main) $Label_1 = GuiCtrlCreateLabel("Complete", 40, 10, 290, 30) GUICtrlSetFont(-1, 10, 650) GUISetState(@SW_HIDE) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 Set_Next() Case $msg = $Button_2 ExitLoop EndSelect WEnd ;--------- Functions ------------------- Func Set_Next() For $x = 1 To $children - 1 $Nwin = WinGetState($Child_[$x]) ;ConsoleWrite($x & " " & $Nwin & @CRLF) If $x = 4 Then GUICtrlSetState($Button_2, $GUI_SHOW) GUICtrlSetState($Button_1, $GUI_HIDE) EndIf If $x = 1 Then _RegSearch($sRegPathx86, "Microsoft Access database engine") If $bSearch[0] = "True" Then GUICtrlSetData($Label_3r, $bSearch[1] & " Version: " & $bSearch[2]) ConsoleWrite("86 " & $bSearch[0] & " " & $bSearch[1] & " " & $bSearch[2] & @CRLF) $bSearch[0] = "" EndIf _RegSearch($sRegPathx64, "Microsoft Access database engine") If $bSearch[0] = "True" Then GUICtrlSetData($Label_3r, $bSearch[1] & " Version: " & $bSearch[2]) ConsoleWrite("64 " & $bSearch[0] & " " & $bSearch[1] & " " & $bSearch[2] & @CRLF) $bSearch[0] = "" EndIf EndIf If $Nwin > 5 Then GUISetState(@SW_HIDE, $Child_[$x]) GUISetState(@SW_SHOW, $Child_[$x + 1]) Return EndIf Next EndFunc Func _IsChecked($control) Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func _RegSearch($sRegPath, $sSearch) Local $sKey, $sSubKey = "", $i = 1 While 1 $sSubKey = RegEnumKey($sRegPath, $i) If @error Then ExitLoop $sDisplay = RegRead($sRegPath & $sSubKey, "DisplayName") If $sDisplay <> "" And StringInStr($sDisplay, $sSearch) Then $bSearch[0] = "True" $bSearch[1] = RegRead($sRegPath & $sSubKey, "DisplayName") $bSearch[2] = RegRead($sRegPath & $sSubKey, "DisplayVersion") ExitLoop EndIf $i += 1 WEnd Return $bSearch EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now