Sign in to follow this  
Followers 0
beato

GUI set state?

3 posts in this topic

Can someone look at the following code and explain what I need to do to make the GUI stay present (properly) until I select Exit. I put in a loop at the end of each Function which does keep the GUI visible (I don't think I did this properly) but it seems to stay stuck on whatever check box was selected=> If I select a check box and then Run, wait for that process to finish and then try to run another check box nothing happens only one action will be performed. I would like to select a check box, select Run (wait for the process to finish) and then select another check box and select Run etc.. I dumbed down some of the code (names, passwords etc) but hopefully the general idea is there

Thanks

Dim $APP1_CHKBOX
Dim $APP2_CHKBOX
Dim $APP3_CHKBOX
Dim $APP4_CHKBOX
Dim $APP5_CHKBOX
Dim $APP6_CHKBOX
Dim $START
Dim $EXIT
Dim $status1
Dim $status2
Dim $status3
Dim $status4
Dim $status5
Dim $status6

#include <GUIConstantsEx.au3>   
#include <File.au3>
#include <ProgressConstants.au3>
#include "ServiceControl.au3"

;~ creates the inital GUI box
GUICreate("Service Setup", 300, 300) ;580
GUISetIcon(@SystemDir & "\mspaint.exe", 0)
GUISetFont(12, 600)
GUICtrlCreateLabel("Service Configurer", 30, 20)
GUISetFont(9, 400)
GUICtrlCreateLabel("Status:", 30, 260)
$StatusLabel = GUICtrlCreateLabel("", 80, 260, 250);, 240)
;~ GUICtrlCreateLabel("nnnnn:",80, 260);test location on label

$APP1_CHKBOX = GUICtrlCreateCheckbox("One Service register", 20, 50) ;Checkbox 1
$APP2_CHKBOX = GUICtrlCreateCheckbox("One Service Un-register", 20, 73) ;Checkbox 2
$APP3_CHKBOX = GUICtrlCreateCheckbox("Two Service register", 20, 96) ;Checkbox 3
$APP4_CHKBOX = GUICtrlCreateCheckbox("Two Service Un-register", 20, 119) ;Checkbox 4
$APP5_CHKBOX = GUICtrlCreateCheckbox("Three Service register", 20, 142) ;Checkbox 5
$APP6_CHKBOX = GUICtrlCreateCheckbox("Three Service Un-register", 20, 165) ;Checkbox 6
$START = GUICtrlCreateButton("Start", 30, 200, 100, 30) ;This in the Run button
$EXIT = GUICtrlCreateButton("Exit", 150, 200, 100, 30) ;This causes the application to exit
GUISetState()

Do
    $msg = GUIGetMsg()
;Reads the status of the Checkboxes and sets a variable to either 1 for checked or 4 for not checked
;This HAS to be included before the UNTIL statement
$status1 = GUICtrlRead($APP1_CHKBOX)
$status2 = GUICtrlRead($APP2_CHKBOX)
$status3 = GUICtrlRead($APP3_CHKBOX)
$status4 = GUICtrlRead($APP4_CHKBOX)
$status5 = GUICtrlRead($APP5_CHKBOX)
$status6 = GUICtrlRead($APP6_CHKBOX)
Until $msg = $EXIT Or $msg = $START

    If $msg = $EXIT Then Exit
;Checks the status of the Checkboxes and calls the application function(s) if the checkbox is enabled
If $status1 = 1 Then Call("One_Service_register")
If $status2 = 1 Then Call("One_Service_Unregister")
If $status3 = 1 Then Call("Two_Service_register")
If $status4 = 1 Then Call("Two_Service_Unregister")
If $status5 = 1 Then Call("Three_Service_register")
If $status6 = 1 Then Call("Three_Service_Unregister")
    
Func One_Service_register() 
    GUICtrlSetData($StatusLabel, "Registering service...")
;~ create Service
    $servicename = "service name here"
    $sDisplayName = "service name here"
    $sBinaryPath = "\\server name here\service name here.exe"
    $sServiceUser = "domain\user"
    $sPassword = "password here"
    _CreateService("", $servicename, $sDisplayName, $sBinaryPath, $sServiceUser, $sPassword)
    sleep(2000)
;~ starts servcice
    $sServiceName = "service name here"
    _StartService("", $sServiceName)
    GUICtrlSetData($StatusLabel, "Service Registered!!!")
    GUICtrlSetState ($APP1_CHKBOX, $GUI_DISABLE)
    While 1
        $msg = GUIGetMsg()
        If $msg = $EXIT Then ExitLoop
    WEnd
EndFunc

Func One_Service_Unregister() 
    GUICtrlSetData($StatusLabel, "Unregistering service...")
;~ stops service
    $sServiceName = "service name here"
    _StopService("", $sServiceName)
;~ deletes service
    $servicename = "service name here"
    _DeleteService("", $servicename)
    Sleep(1000)
    GUICtrlSetData($StatusLabel, "Service Unregistered!!!")
    GUICtrlSetState($APP2_CHKBOX, $GUI_DISABLE)
    While 1
        $msg = GUIGetMsg()
        If $msg = $EXIT Then ExitLoop
    WEnd
EndFunc

Share this post


Link to post
Share on other sites



You have to keep control over msg loop of main :instead of that

Do
    $msg = GUIGetMsg()
;Reads the status of the Checkboxes and sets a variable to either 1 for checked or 4 for not checked
;This HAS to be included before the UNTIL statement
..
$status5 = GUICtrlRead($APP5_CHKBOX)
$status6 = GUICtrlRead($APP6_CHKBOX)
Until $msg = $EXIT Or $msg = $START

    If $msg = $EXIT Then Exit
;Checks the status of the Checkboxes and calls the application function(s) if the checkbox is enabled
If $status1 = 1 Then Call("One_Service_register")
...
If $status6 = 1 Then Call("Three_Service_Unregister")

You should have something like

While 1
$msg = GUIGetMessage()
If GUICtrlRead($APP5_CHKBOX) = $GUI_CHECKED then
   procedure1
Endif
..

If $msg = $EXIT then ExitLoop
Wend

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It appears to me the problem is your do loop, seeing it only runs that till start or exit is hit. once start is hit it no longer checks the checkboxes, Maybe change it to a While $msg <> $exit or $msg <> $start. Then at the end of the func's clear $msg. I personally would have built it differently. But what ever floats your boat.

Edit: man I'm too slow.

Edited by youknowwho4eva

Giggity

Share this post


Link to post
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
Sign in to follow this  
Followers 0