Jump to content

Parent child problem; Child case in while loop running before called


MikahS
 Share

Go to solution Solved by BrewManNH,

Recommended Posts

I am having problem. I have script that has a main GUI window that allows you to select which kind of encryption you'd like to use. When I go to start the script, for some reason the case statement for the:

$iSubmit
button for the child GUI runs right away and tried to read the data from the input on the child window, which hasn't been created yet, and then pops up the MsgBox.

 

I have been scouring the forums for something of similar nature, but unsuccessful. I have checked helpfile and it seems I am doing this correct. Here is my script:

; includes
 
#include <GUIConstantsEx.au3>
#include <Crypt.au3>
 
; vars
Local $hGUI, $msg = 0, $hInput, $iButton, $hDecode, $dButton
Local $aChkBx[8], $cValue, $iChild, $iMsg, $iPswd, $iMsgBox
Local $iPswdBox, $iSubmit
;main line
 
GUI()
 
While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $hGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    Quit()
                Case $iButton
                    getCheckbox()
                    inputChild()
                    ;Crypt(, $cValue)
                Case $dButton
                    getCheckbox()
             EndSwitch
        Case $iChild
            Switch $msg[0]
                  Case $GUI_EVENT_CLOSE
                      GUIDelete($iChild)
                  Case $iSubmit
                      $iMsg = GUICtrlRead($iMsgBox)
                      $iPswd = GUICtrlRead($iPswdBox)
                      MsgBox(0, "title", "msg:" & $iMsg & " paswrd:" & $iPswd)
            EndSwitch
    EndSwitch
WEnd
 
;functions
 
Func GUI()
    $hGUI = GUICreate("Short-Order Encrypter", 300, 200)
    GUICtrlCreateLabel("Encrypt a Message!", 95, 15)
    GUICtrlCreateLabel("This is a simple input and output encryption program.", 25, 35)
    GUICtrlCreateLabel("You will select which method of encryption, then", 30, 48)
    GUICtrlCreateLabel("input your text by pressing the Input button,", 40, 61)
    GUICtrlCreateLabel("or you will press the Decode button to", 55, 74)
    GUICtrlCreateLabel("decode an encrypted message.", 65, 87)
    $iButton = GUICtrlCreateButton("Input", 50, 160, 70, 30)
    $dButton = GUICtrlCreateButton("Decode", 160, 160, 70, 30)
    $aChkBx[0] = GUICtrlCreateCheckbox("Text", 15, 105)
    $aChkBx[1] = GUICtrlCreateCheckbox("3DES", 67, 105)
    $aChkBx[2] = GUICtrlCreateCheckbox("AES (128bit)", 122, 105)
    $aChkBx[3] = GUICtrlCreateCheckbox("AES (192bit)", 208, 105)
    $aChkBx[4] = GUICtrlCreateCheckbox("AES (256bit)", 32, 130)
    $aChkBx[5] = GUICtrlCreateCheckbox("DES", 121, 130)
    $aChkBx[6] = GUICtrlCreateCheckbox("RC2", 172, 130)
    $aChkBx[7] = GUICtrlCreateCheckbox("RC4", 224, 130)
    GUISetState(@SW_SHOW)
EndFunc ;==>GUI
 
Func getCheckbox()
    Local $i, $readArray, $cCounter = 0
    For $i = 0 To UBound($aChkBx) - 1 Step 1
        $readArray = GUICtrlRead($aChkBx[$i])
        If $readArray = 1 Then
             $cCounter += 1
             $cValue &= $i
        EndIf
    Next
    If $cCounter > 1 Then
        MsgBox(0, "Encryption Type", "Could not specify encryption type due to multiple selections. Please make sure you have only selected on type of encryption")
        $cValue = ""
        Return
    ElseIf $cCounter = 0 Then
         MsgBox(0, "Encryption Type", "You must select an encryption type in the Short-Order Encrypter window")
         Return
    EndIf
EndFunc ;==>getCheckbox
 
Func inputChild()
    If $cValue = "" Then
         Return
    EndIf
    $iChild = GUICreate("Input Message", 386, 120, -1, -1, -1, -1, $hGUI)
    GUICtrlCreateLabel("Message", 5, 10)
    GUICtrlCreateLabel("Password", 200, 10)
    $iMsgBox = GUICtrlCreateInput("", 5, 25, 180, 60)
    $iPswdBox = GUICtrlCreateInput("", 200, 25, 180, 60)
    $iSubmit = GUICtrlCreateButton("Encrypt", 172, 90)
    GUISetState()
EndFunc ;==>inputChild
 
#cs
Func Crypt($iMsg, $iPass, $iflag)
    Local $mFlag[8]
    $mFlag[0] = "TEXT"
    $mFlag[1] = $CALG_3DES
    $mFlag[2] = $CALG_AES_128
    $mFlag[3] = $CALG_AES_192
    $mFlag[4] = $CALG_AES_256
    $mFlag[5] = $CALG_DES
    $mFlag[6] = $CALG_RC2
    $mFlag[7] = $CALG_RC4
EndFunc ;==>Crypt
#ce
 
Func Quit()
    GUIDelete($hGUI)
    Exit
EndFunc ;==>Quit

 

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

This works for me.

; includes

#include <GUIConstantsEx.au3>
#include <Crypt.au3>
Opt("TrayMenuMode", 1)
Opt("TrayIconHide", 0)
Opt("GUICoordMode", 1)
Opt("GUIResizeMode", 1)
Opt("TrayIconDebug", 1)
Opt("TrayAutoPause", 0)
Opt("MouseCoordMode", 2)
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
Opt("GUIEventOptions", 0)
Opt("TrayOnEventMode", 1)
Opt("ExpandEnvStrings", 1)
Opt("WinDetectHiddenText", 1)
; vars
Local $hGUI, $msg = 0, $hInput, $iButton, $hDecode, $dButton
Local $aChkBx[8], $cValue, $iChild, $iMsg, $iPswd, $iMsgBox
Local $iPswdBox, $iSubmit
;main line

GUI()

;functions

Func GUI()
    $hGUI = GUICreate("Short-Order Encrypter", 300, 200)
    GUICtrlCreateLabel("Encrypt a Message!", 95, 15)
    GUICtrlCreateLabel("This is a simple input and output encryption program.", 25, 35)
    GUICtrlCreateLabel("You will select which method of encryption, then", 30, 48)
    GUICtrlCreateLabel("input your text by pressing the Input button,", 40, 61)
    GUICtrlCreateLabel("or you will press the Decode button to", 55, 74)
    GUICtrlCreateLabel("decode an encrypted message.", 65, 87)
    $iButton = GUICtrlCreateButton("Input", 50, 160, 70, 30)
    GUICtrlSetOnEvent(-1, "iButton")
    $dButton = GUICtrlCreateButton("Decode", 160, 160, 70, 30)
    GUICtrlSetOnEvent(-1, "getCheckbox")
    $aChkBx[0] = GUICtrlCreateCheckbox("Text", 15, 105)
    $aChkBx[1] = GUICtrlCreateCheckbox("3DES", 67, 105)
    $aChkBx[2] = GUICtrlCreateCheckbox("AES (128bit)", 122, 105)
    $aChkBx[3] = GUICtrlCreateCheckbox("AES (192bit)", 208, 105)
    $aChkBx[4] = GUICtrlCreateCheckbox("AES (256bit)", 32, 130)
    $aChkBx[5] = GUICtrlCreateCheckbox("DES", 121, 130)
    $aChkBx[6] = GUICtrlCreateCheckbox("RC2", 172, 130)
    $aChkBx[7] = GUICtrlCreateCheckbox("RC4", 224, 130)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
    GUISetState(@SW_SHOW)
EndFunc ;==>GUI

Func iButton()
    getCheckbox()
    inputChild()
EndFunc

Func getCheckbox()
    Local $i, $readArray, $cCounter = 0
    For $i = 0 To UBound($aChkBx) - 1 Step 1
        $readArray = GUICtrlRead($aChkBx[$i])
        If $readArray = 1 Then
             $cCounter += 1
             $cValue &= $i
        EndIf
    Next
    If $cCounter > 1 Then
        MsgBox(0, "Encryption Type", "Could not specify encryption type due to multiple selections. Please make sure you have only selected on type of encryption")
        $cValue = ""
        Return
    ElseIf $cCounter = 0 Then
         MsgBox(0, "Encryption Type", "You must select an encryption type in the Short-Order Encrypter window")
         Return
    EndIf
EndFunc ;==>getCheckbox

Func inputChild()
    If $cValue = "" Then
         Return
    EndIf
    $iChild = GUICreate("Input Message", 386, 120, -1, -1, -1, -1, $hGUI)
    GUICtrlCreateLabel("Message", 5, 10)
    GUICtrlCreateLabel("Password", 200, 10)
    $iMsgBox = GUICtrlCreateInput("", 5, 25, 180, 60)
    $iPswdBox = GUICtrlCreateInput("", 200, 25, 180, 60)
    $iSubmit = GUICtrlCreateButton("Encrypt", 172, 90)
    GUICtrlSetOnEvent($iSubmit, "Encrypt")
    GUISetOnEvent($GUI_EVENT_CLOSE, "QuitChild")
    GUISetState()
EndFunc ;==>inputChild

#cs
Func Crypt($iMsg, $iPass, $iflag)
    Local $mFlag[8]
    $mFlag[0] = "TEXT"
    $mFlag[1] = $CALG_3DES
    $mFlag[2] = $CALG_AES_128
    $mFlag[3] = $CALG_AES_192
    $mFlag[4] = $CALG_AES_256
    $mFlag[5] = $CALG_DES
    $mFlag[6] = $CALG_RC2
    $mFlag[7] = $CALG_RC4
EndFunc ;==>Crypt
#ce

Func Quit()
    GUIDelete($hGUI)
    Exit
EndFunc ;==>Quit

Func QuitChild()
    GUIDelete($iChild)
EndFunc ;==>Quit

Func Encrypt()
    $iMsg = GUICtrlRead($iMsgBox)
    $iPswd = GUICtrlRead($iPswdBox)
    MsgBox(0, "title", "msg:" & $iMsg & " paswrd:" & $iPswd)
EndFunc

While 1
Sleep(100)
WEnd
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

  • Solution

All you need to do is change your declarations for the child gui and the controls on it.

; vars
Local $hGUI, $msg = 0, $hInput, $iButton, $hDecode, $dButton
Local $aChkBx[8], $cValue, $iChild=9999, $iMsg, $iPswd, $iMsgBox ; <<<<<<<<<<<<<<<<<<<<<<
Local $iPswdBox, $iSubmit=9999 ; <<<<<<<<<<<<<<<<<<<<<<<<
;main line

Because you haven't created the child GUI yet, the gui handle and all controls will equal zero. In a MessageLoop, GUIGetMsg returns 0 whenever nothing is happening in the GUI, so the child GUI handle will match and the $iSubmit id will match because both are zero. Set them to something that probably won't be a control ID, 9999 in my example above, and this won't happen. When the controls and the GUI are created, the default 9999 will be overwritten.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@careca Thank you for that solution, as it's something to think about :)

@BrewManNH Thank you, I really wanted to figure out what was going on and not change around the way I poll for events on the GUI. With this solution (tested) it worked :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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

×
×
  • Create New...