Jump to content

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


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 post
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 post
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 post
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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By abberration
      Software Installer
      Version: 2.0
      It's been been a long year, but I finally got some time to rework this project. I re-wrote everything from scratch because the old version was getting too complicated with so many options and sub-menus. This new version is much easier to use and I have been testing for a few days and it seems very stable.
      For those who are new to this software, it helps you install software silently/unattended. This new version tries to determine the silent switch automatically. You can also re-organize the order in which the software installs by dragging & dropping them in the listview. It now supports creating profiles and checks for missing software (and automatically unchecks them, so it does not attempt to install non-existent software). One feature I included was because I have seen several people on Youtube talk about disliking bright screens at night. So, now you can choose from a few color theme (half of them are dark). I dabbled a bit more into GDI+ to draw a few things and show my logo with a transparent background (hint: I'm not good at GDI+).
      Under the Help menu, you will find a User Guide, which goes through most of it's features. I included a new icon if you want to use when you compile the script (in the Assets > Misc folder).
      If you have questions, comments or suggestions, all are welcome. Hope you enjoy!
      Here it is in action:

       
      Software_Installer_2.0.zip
    • By Jemboy
      Recently I was working on a script with icons using GuiCtrkCreatIcon.
      I decided to change the sub folder name of the icons to a more meaning name, however made a typo.

      I tested the .exe on my test computer and it worked flawlessly (because both icon folder where on my test computer) 😁
      But after I installed the script on the intended computers , I got chaos!😵
      Zooming into the problem, I discovered, that because the icons could not be found, the ControlID were returned with a value of 0
      and thus played havoc within the GuiGetMsg() switch/case statement.
      I have been able to reproduce this  (see example)
      #include <GUIConstantsEx.au3> ;============================================================================================================ ; PLEASE, do not save this example in the example folder: C:\Program Files (x86)\AutoIt3\Examples\Helpfile ;============================================================================================================ Example() Func Example() GUICreate(" My GUI Icons", 250, 250) $Icon1 = GUICtrlCreateIcon("shell32.dll", 10, 20, 20) $Icon2 = GUICtrlCreateIcon(@ScriptDir & '\Extras\horse.ani', -1, 20, 40, 32, 32) $Icon3 = GUICtrlCreateIcon("shell32.dll", 7, 20, 75, 32, 32) GUISetState(@SW_SHOW) ;$Icon2 = -1 ; ==> When this line is uncommented the script "works", so -1 could be a potential fix. ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Icon2 Beep (500,500) EndSwitch WEnd GUIDelete() EndFunc ;==>Example If you save the above script outside the Autoit example folder and run it, it will keep beeping because GuiCtrlCreatIcon did not find horse.ani and return $Icon2=0.
      At the moment GUICtrlCreateIcon () only returns the conntrolID on success and 0 on failure.
      I would like to propose a return of -1 on failure, so a existing and working script won't go awry when the icon can not be found.
       
    • By Colduction
      Hi guys!, i have a problem to convert Python code to AutoIt code, in fact i had not coded with Python yet!, this code is about permutation a string's case, i will be happy with your comments :)❤;

      Python code:
       
      # Python code to print all permutations # with respect to cases # Function to generate permutations def permute(inp): n = len(inp) # Number of permutations is 2^n mx = 1 << n # Converting string to lower case inp = inp.lower() # Using all subsequences and permuting them for i in range(mx): # If j-th bit is set, we convert it to upper case combination = [k for k in inp] for j in range(n): if (((i >> j) & 1) == 1): combination[j] = inp[j].upper() temp = "" # Printing current combination for i in combination: temp += i print(temp), # Driver code permute("Hello") # This code is contributed by Sachin Bisht
      My code in AutoIt:
      ; https://www.geeksforgeeks.org/permute-string-changing-case/ _PermuteCase("ABC") Func _PermuteCase($sText) If StringRegExp($sText, "^[A-Za-z]{1,}$") Then Local $iLength = StringLen($sText) ; Get length of the text. Local $iMaxPerm = 2 ^ $iLength ; Number of permutations is 2^n Local $sLow_Text = StringLower($sText) ; Converting string to lower case Local $asChrs = StringToASCIIArray($sLow_Text) ; Split the text into array of chars. For $i = 1 To $iMaxPerm Step 1 For $j = 0 To $asChrs[0] ;................................................... Next Next Else Return SetError(-1, 0, "Error: Input is incorrect!") EndIf EndFunc ;==>_PermuteCase  
       
       
       
       
       
      ====================== SOLUTION by @TheXman ======================
       
    • By banged
      Hello, i have issues with my code
      If not WinSetTrans (line 44.45 - Both, red and yellow), Then not Show Childs                               (--- if Func _BK run on line 6, then does no matter if WinSetTrans, Childs not show !!
      if WinSetTrans (line 44.45 - Both, red and yellow) , Then  Show Childs, why NEED WinSetTrans??             (--- if Func _BK run on line 6, then does no matter if WinSetTrans, Childs not show !!
      if WinSetTrans Child1(RED) ONLY, then Show Child1(RED)                                                     (--- if Func _BK run on line 6, then does no matter if WinSetTrans, Child not show !!
      if WinSetTrans (line 44 Child2(Yellow) ONLY), then Show Child1(RED) & Child2(Yellow), Why show Both ????     (--- if Func _BK run on line 6, then does no matter if WinSetTrans, Childs not show !!
       With $WS_POPUP (and $WS_EX_MDICHILD ) i have not above problems, but i need use $WS_CHILD
       Problems with $WS_POPUP : if change windows resolution (and restore next time), then childs change position on main form
                             : i Need WinSetTrans on all GUIS when fade,with popup i need winsettrans all guis one by one
                              : on minimize,restore Main GUI ,childs not following windows minimize/restore effect
       First i Create  Child1, Second Child2, Why Child1 is above child2 ? (i need child2 above child1, and i don't want create firts the child2 or this is only way???)
      #include <GuiConstants.au3> Global $idButton2,$pp1,$pp2,$bShow = True $Main_GUI = GUICreate("Main", 1000,500,Default,Default) ;_BK() ;<--------- FAIL $Child1_GUI = GUICreate("Child1", 700,200, 220, 200, $WS_CHILD+$WS_THICKFRAME,Default, $Main_GUI) $idButton = GUICtrlCreateButton("RED",25,25,50,30) GUISetBkColor (0xFF334C, $Child1_GUI ) ; RED $Child2_GUI = GUICreate("Child2", 700,200, 30, 200,$WS_CHILD, Default, $Main_GUI) $test = GUICtrlCreateButton("Yellow",10,10,250,20) GUISetBkColor (0xFFff4C, $Child2_GUI ) ; Yellow _BK() ;<--------- SUCCES Func _BK() GUISwitch($Main_GUI) $pp1 = GUICtrlCreatePic("C:\Program Files (x86)\AutoIt3\Examples\GUI\msoobe.jpg",0,0,1000,500) GUICtrlSetState($pp1,$GUI_DISABLE) $pp2 = GUICtrlCreatePic("C:\Program Files (x86)\AutoIt3\Examples\GUI\mslogo.jpg",200,100,600,350) GUICtrlSetState($pp2,$GUI_DISABLE) $idButton2 = GUICtrlCreateButton("Main",0,300,280,30) $idButton3 = GUICtrlCreateButton("Main2",0,315,280,30) EndFunc GUISetState(@SW_SHOW, $Main_GUI) GUISetState(@SW_SHOW, $Child1_GUI) GUISetState(@SW_SHOW, $Child2_GUI) WinSetTrans($Child1_GUI,"",200) ;RED WinSetTrans($Child2_GUI,"",100) ; Yellow while 1 $iMsg = GUIGetMsg() Switch $iMsg Case -3 _Fade($Main_GUI,"out",254) Exit Case $idButton,$test For $i = 254 To 0 Step - 4 Sleep(10) WinSetTrans($Main_GUI,"",$i) Next For $i = 0 To 254 Step 4 Sleep(10) WinSetTrans($Main_GUI,"",$i) Next Case $idButton2 If $bShow = True Then GUISetState(@SW_HIDE, $Child2_GUI) GUISetState(@SW_HIDE, $Child1_GUI) $bShow = False Else GUISetState(@SW_SHOW, $Child2_GUI) GUISetState(@SW_SHOW, $Child1_GUI) $bShow = True EndIf EndSwitch wend Func _Fade($hHdl,$InOut,$iMax = 255,$iSpeed = 4) If $InOut = "out" Then For $i = $iMax To 0 Step - $iSpeed Sleep(10) WinSetTrans($hHdl,"",$i) Next Else For $i = 0 To $iMax Step $iSpeed Sleep(10) WinSetTrans($hHdl,"",$i) Next EndIf EndFunc  
    • By Rhidlor
      First off, the project I'm working on revolves around AS/400 "Client Access software", it's foundation is directly influenced by the thread linked at the bottom of this post. Moving on, to explain the problem I'm facing; my project utilizes an infinite While loop and automatically performs semi-hard coded monotonous tasks to save users time and effort, the problem is, occasionally and unexpectedly "Display Messages" will popup and the core script will continue executing instead of dismissing said message and the script "breaks". As a countermeasure I've added some code to the While loop in an effort to intervene and dismiss these display messages before the core script has a chance to do anything... however it doesn't work. I hope I didn't do too bad of a job explaining that. 
      So I think my question is: How can I temporarily "pause" the core script when these messages spontaneously appear?
      The only other solution I thought of would be to check if a display message has appeared before executing every line of code but that obviously isn't very practical.
      Any and all help is greatly appreciated!
      Thanks
       
      ;Loop to keep script running and handle display messages While 1 dismiss_display_messages() Sleep(50) WEnd ;Function to dismiss display messages Func dismiss_display_messages() If $ps.SearchText("Display Messages") Then $ps.SendKeys("[enter]", 8, 1) ;This while loop waits until the display message has disappeared to resume the core script While $ps.SearchText("Display Messages") Sleep(100) WEnd EndIf EndFunc  
       
×
×
  • Create New...