Jump to content

Parent and child windows - how?


dickep
 Share

Recommended Posts

OK, I have researched this and now am really confused.

I have a script (included here) that has a main window and a child (if you click on "Select Processes" checkbox) will pop up. I can get that to work. However, I want to select (check) items, figure out how to save them to be passed back (later if possible), and then close the child window and return to the main application. The main is the "control" in that pressing OK will start the rest of what I need/want done.

SO, I have included the code (with all the things I put in for debugging, help, whatever).

Let me know what I have missed and/or done wrong.

Love Autoit - so POWERFUL!!

;===========================================================================
;
;  INCLUDE SECTION
;
;===========================================================================
#include <GUIConstants.au3>
#include <CompInfo.au3>
#include <Date.au3>


;============================================================================
;
;  GLOBAL CONSTANTS AND VARIBLES
;
;===========================================================================


#region Global Variables and Constants
Global $ChildGUI, $killbutton

#endregion Global Variables and Constants

#region Variable declarations

Dim $Processes, $i
Dim $mDisplayHeight, $mDisplayWidth, $mDispCtrW, $mDispCtrH, $mMenuWidth, $mMenuHeight, $tTempMins, $tTempSecs
Dim $tTriggerTime, $tNewHour, $tNewMin, $tNewSec, $tOldHour, $tOldMin, $tOldSec
dim $fLogFile1 = @DesktopDir & "\log.txt"
Dim $CB[42], $ChildCB[100]
Dim $fHandle1
Dim $mHeader[42] = ["Name","Command Line","Creation Class Name","Creation Date","Description","CS Creation Class Name","CS Name","Executable Path","Execution State","Handle","Handle Count","Kernel Mode Time","Maximum Working Set Size","Minimum Working Set Size","OS Creation Class Name","OS Name","Other Operation Count","Other Transfer Count","Page Faults","Page File Usage","Parent Process ID","Peak Page File Usage","Peak Virtual Size","Peak Working Set Size","Priority","Private Page Count","Process ID","Quota Non Paged Pool Usage","Quota Paged Pool Usage","Quota Peak Non Paged Pool Usage","Quota Peak Paged Pool Usage","Read Operation Count","Read Transfer Count","Session ID","Status","Thread Count","User Mode Time","Virtual Size","Windows Version","Working Set Size","Write Operation Count","Write Transfer Count"]
Dim $CBchecked[42]
Dim $fTemp, $mTemp, $a
Dim $mWaitMsg = "Waiting.."
Dim $iLimit = 5000000, $cnt
dim $sOld, $sTotal, $sStringLen

$mDisplayHeight = @DesktopHeight
$mDisplayWidth = @DesktopWidth
$mDispCtrW = Int($mDisplayWidth/2)
$mDispCtrH = Int($mDisplayHeight/2)
$mMenuWidth = 448
$mMenuHeight = 634

#endregion Variable declarations
;============================================================================
;
;  MAIN
;
;===========================================================================





;===========================================
;
; create a WAIT window for use later
;
;==========================================
$mWaitWin = GUICreate("Working....",300,100,45,75)
;$mWaitLabel1 = GUICtrlCreateLabel($mWaitMsg,25,75,100)
;$mT1 = GUICtrlCreateLabel("Now time: " & _DateTimeFormat(_nowcalc(), 3) & @CRLF & "Trigger Time " & _DateTimeFormat($tNewTime,3), 25, 90, 150, 50)

_ComputerGetProcesses($Processes)

; Make the first user input GUI
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Manitoba Test Tool", $mMenuHeight, $mMenuWidth, ($mDispCtrW - (int(633/2))), ($mDispCtrH - (448/2)))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUISetFont(10, 700)
$Label1 = GUICtrlCreateLabel("Enter time for each read (in seconds)", 32, 32, 267, 17)
$Label2 = GUICtrlCreateLabel("Check each item you wish to log for each Process", 5, 56, 350, 25)
$mTiming = GUICtrlCreateInput("", 272, 30, 60, 21)
$Label3 = GUICtrlCreateLabel("Process: ", 365, 56, 100, 17)
$ProcessInput = GUICtrlCreateInput("",425,58,150,25)
$Label3 = GUICtrlCreateLabel("Number of processes running: " & $Processes[0][0],375, 32, 300, 25 )
GUISetFont(8.5, 400)
$CB[0] = GUICtrlCreateCheckbox("Name", 40, 84, 150, 17)
$CB[1] = GUICtrlCreateCheckbox("Command Line", 40, 104, 150, 17)
$CB[2] = GUICtrlCreateCheckbox("Creation Class Name", 40, 124, 150, 17)
$CB[3] = GUICtrlCreateCheckbox("Creation Date", 40, 144, 150, 17)
$CB[4] = GUICtrlCreateCheckbox("Description", 40, 164, 150, 17)
$CB[5] = GUICtrlCreateCheckbox("CS Creation Class Name", 40, 184, 150, 17)
$CB[6] = GUICtrlCreateCheckbox("CS Name", 40, 204, 150, 17)
$CB[7] = GUICtrlCreateCheckbox("Executable Path", 40, 224, 150, 17)
$CB[8] = GUICtrlCreateCheckbox("Execution State", 40, 244, 150, 17)
$CB[9] = GUICtrlCreateCheckbox("Handle", 40, 264, 150, 17)
$CB[10] = GUICtrlCreateCheckbox("Handle Count", 40, 284, 150, 17)
$CB[11] = GUICtrlCreateCheckbox("Kernel Mode Time", 40, 304, 150, 17)
$CB[12] = GUICtrlCreateCheckbox("Maximum Working Set Size", 40, 324, 150, 17)
$CB[13] = GUICtrlCreateCheckbox("Minimum Working Set Size", 40, 344, 150, 17)
$CB[14] = GUICtrlCreateCheckbox("OS Creation Class Name", 40, 364, 150, 17)
$CB[15] = GUICtrlCreateCheckbox("OS Name", 240, 84, 150, 17)
$CB[16] = GUICtrlCreateCheckbox("Other Operation Count", 240, 104, 150, 17)
$CB[17] = GUICtrlCreateCheckbox("Other Transfer Count", 240, 124, 150, 17)
$CB[18] = GUICtrlCreateCheckbox("Page Faults", 240, 144, 150, 17)
$CB[19] = GUICtrlCreateCheckbox("Page File Usage", 240, 164, 150, 17)
$CB[20] = GUICtrlCreateCheckbox("Parent Process ID", 240, 184, 150, 17)
$CB[21] = GUICtrlCreateCheckbox("Peak Page File Usage", 240, 204, 150, 17)
$CB[22] = GUICtrlCreateCheckbox(" Peak Virtual Size", 240, 224, 150, 17)
$CB[23] = GUICtrlCreateCheckbox(" Peak Working Set Size", 240, 244, 150, 17)
$CB[24] = GUICtrlCreateCheckbox(" Priority", 240, 264, 150, 17)
$CB[25] = GUICtrlCreateCheckbox("Private Page Count", 240, 284, 150, 17)
$CB[26] = GUICtrlCreateCheckbox("Process ID", 240, 304, 150, 17)
$CB[27] = GUICtrlCreateCheckbox("Quota Non Paged Pool Usage", 240, 324, 180, 17)
$CB[28] = GUICtrlCreateCheckbox("Quota Paged Pool Usage", 240, 344, 150, 17)
$CB[29] = GUICtrlCreateCheckbox("Quota Peak Non Paged Pool Usage", 240, 364, 200, 17)
$CB[30] = GUICtrlCreateCheckbox("Quota Peak Paged Pool Usage", 440, 84, 180, 17)
$CB[31] = GUICtrlCreateCheckbox("Read Operation Count", 440, 104, 150, 17)
$CB[32] = GUICtrlCreateCheckbox("Read Transfer Count", 440, 124, 150, 17)
$CB[33] = GUICtrlCreateCheckbox("Session ID", 440, 144, 150, 17)
$CB[34] = GUICtrlCreateCheckbox("Status", 440, 164, 150, 17)
$CB[35] = GUICtrlCreateCheckbox("Thread Count", 440, 184, 150, 17)
$CB[36] = GUICtrlCreateCheckbox("User Mode Time", 440, 204, 150, 17)
$CB[37] = GUICtrlCreateCheckbox("Virtual Size", 440, 224, 150, 17)
$CB[38] = GUICtrlCreateCheckbox("Windows Version", 440, 244, 150, 17)
$CB[39] = GUICtrlCreateCheckbox("Working Set Size", 440, 264, 150, 17)
$CB[40] = GUICtrlCreateCheckbox("Write Operation Count", 440, 284, 150, 17)
$CB[41] = GUICtrlCreateCheckbox("Write Transfer Count", 440, 304, 150, 17)
$PGUI = GUICtrlCreateCheckbox("Select Processes",440, 324, 100, 17)
GUICtrlSetOnEvent($PGUI, "_CreateChild")
$Button1 = GUICtrlCreateButton("OK", 192, 400, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Cancel", 352, 400, 75, 25, 0)
GUISetState(@SW_SHOW, $Form1)
GUISwitch($Form1)

#EndRegion ### END Koda GUI section ###

#cs
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            ExitLoop
        case $button2
            Exit
    EndSwitch
WEnd
#ce

While 1
    $msg = GUIGetMsg(1)
       Select
    ;Check if user clicked on a close button of any of the 2 windows
        Case $msg[0] = $GUI_EVENT_CLOSE
        ;Check if user clicked on the close button of the child window
             If $msg[1] = $ChildGUI Then
                MsgBox(64, "Test", "Child GUI will now close.")
              ;Switch to the child window
                GUISwitch($ChildGUI)
              ;Destroy the child GUI including the controls
                GUIDelete()
        ;Check if user clicked on the close button of the parent window
             ElseIf $msg[1] = $Form1 Then
                MsgBox(64, "Test", "Parent GUI will now close.")
              ;Switch to the parent window
                GUISwitch($Form1)
              ;Destroy the parent GUI including the controls
                GUIDelete()
              ;Exit the script
                Exit
             EndIf
;        Case $msg[0] = $ChildGUI
;            GUISwitch($ChildGUI)
;            
;            MsgBox(0,"KILL","killbutton pressed and passed")
;       case $$Button1
;           ExitLoop
;       case $button2
;           Exit
       EndSelect
WEnd




;==============================================================================================
;
;  FUNCTION AREA
;
;=============================================================================================

Func _CreateChild()
    MsgBox(0,":INFORMATION","In the _CreateChild function")
    $ChildGUI = GUICreate("Main:Processes", 350, 260, 100, 100, -1, -1, $Form1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseChildGUI")
    GUICtrlCreateGroup(" All Processes Running ", 10, 10, 220, 228)
    GUIStartGroup()
    $treeproces = GUICtrlCreateTreeView(20, 30, 200, 192, $TVS_CHECKBOXES)
    $list = ProcessList()
    Dim $radeks[$list[0][0] + 1]

    For $i = 1 To $list[0][0]
        $radeks[$i] = GUICtrlCreateTreeViewItem($list[$i][0], $treeproces)
    Next
    
    GUICtrlCreateLabel("  Number of running processes :  ", 20, 230, 140, 15)
    GUICtrlCreateLabel($list[0][0], 160, 230, 20, 15)
    $killbutton = GUICtrlCreateButton("Submit", 260, 20, 60, 25)
    GUISetOnEvent($killbutton, "_CloseChildGUI")
    GUISetState(@SW_SHOW, $ChildGUI)    
    GUISwitch($ChildGUI)
EndFunc

Func _CloseChildGUI()
    GUIDelete($ChildGUI)
EndFunc  ;==>_CloseChildGUI

Func _Quit()
    Exit
EndFunc
Link to comment
Share on other sites

  • Moderators

First things first... You can't use GUIGetMsg with OnEventMode as well.... Fix that first. Also, keep in mind, when you need to have a specific variable contain a value, you'll need to make it Global variable, or have the function you are calling use a "Return" method with the desired values.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

First things first... You can't use GUIGetMsg with OnEventMode as well.... Fix that first. Also, keep in mind, when you need to have a specific variable contain a value, you'll need to make it Global variable, or have the function you are calling use a "Return" method with the desired values.

OK - if I cannot use the GUIGetMsg, how can I do this? I am not understanding how to get where I need now that you have pointed me in a direction I was afraid you would.

I am still learning and am open to all/any help.

Thanks

E

Link to comment
Share on other sites

;===========================================================================
;
;  INCLUDE SECTION
;
;===========================================================================
#include <GUIConstants.au3>
#include <CompInfo.au3>
#include <Date.au3>


;============================================================================
;
;  GLOBAL CONSTANTS AND VARIBLES
;
;===========================================================================


#region Global Variables and Constants
Global $ChildGUI, $killbutton

#endregion Global Variables and Constants

#region Variable declarations

Dim $Processes, $i
Dim $mDisplayHeight, $mDisplayWidth, $mDispCtrW, $mDispCtrH, $mMenuWidth, $mMenuHeight, $tTempMins, $tTempSecs
Dim $tTriggerTime, $tNewHour, $tNewMin, $tNewSec, $tOldHour, $tOldMin, $tOldSec
dim $fLogFile1 = @DesktopDir & "\log.txt"
Dim $CB[42], $ChildCB[100]
Dim $fHandle1
Dim $mHeader[42] = ["Name","Command Line","Creation Class Name","Creation Date","Description","CS Creation Class Name","CS Name","Executable Path","Execution State","Handle","Handle Count","Kernel Mode Time","Maximum Working Set Size","Minimum Working Set Size","OS Creation Class Name","OS Name","Other Operation Count","Other Transfer Count","Page Faults","Page File Usage","Parent Process ID","Peak Page File Usage","Peak Virtual Size","Peak Working Set Size","Priority","Private Page Count","Process ID","Quota Non Paged Pool Usage","Quota Paged Pool Usage","Quota Peak Non Paged Pool Usage","Quota Peak Paged Pool Usage","Read Operation Count","Read Transfer Count","Session ID","Status","Thread Count","User Mode Time","Virtual Size","Windows Version","Working Set Size","Write Operation Count","Write Transfer Count"]
Dim $CBchecked[42]
Dim $fTemp, $mTemp, $a
Dim $mWaitMsg = "Waiting.."
Dim $iLimit = 5000000, $cnt
dim $sOld, $sTotal, $sStringLen
Global $radeks[1]
Global $list

$mDisplayHeight = @DesktopHeight
$mDisplayWidth = @DesktopWidth
$mDispCtrW = Int($mDisplayWidth/2)
$mDispCtrH = Int($mDisplayHeight/2)
$mMenuWidth = 448
$mMenuHeight = 634

#endregion Variable declarations
;============================================================================
;
;  MAIN
;
;===========================================================================





;===========================================
;
; create a WAIT window for use later
;
;==========================================
$mWaitWin = GUICreate("Working....",300,100,45,75)
;$mWaitLabel1 = GUICtrlCreateLabel($mWaitMsg,25,75,100)
;$mT1 = GUICtrlCreateLabel("Now time: " & _DateTimeFormat(_nowcalc(), 3) & @CRLF & "Trigger Time " & _DateTimeFormat($tNewTime,3), 25, 90, 150, 50)

_ComputerGetProcesses($Processes)

; Make the first user input GUI
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Manitoba Test Tool", $mMenuHeight, $mMenuWidth, ($mDispCtrW - (int(633/2))), ($mDispCtrH - (448/2)))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUISetFont(10, 700)
$Label1 = GUICtrlCreateLabel("Enter time for each read (in seconds)", 32, 32, 267, 17)
$Label2 = GUICtrlCreateLabel("Check each item you wish to log for each Process", 5, 56, 350, 25)
$mTiming = GUICtrlCreateInput("", 272, 30, 60, 21)
$Label3 = GUICtrlCreateLabel("Process: ", 365, 56, 100, 17)
$ProcessInput = GUICtrlCreateInput("",425,58,150,25)
$Label3 = GUICtrlCreateLabel("Number of processes running: " & $Processes[0][0],375, 32, 300, 25 )
GUISetFont(8.5, 400)
$CB[0] = GUICtrlCreateCheckbox("Name", 40, 84, 150, 17)
$CB[1] = GUICtrlCreateCheckbox("Command Line", 40, 104, 150, 17)
$CB[2] = GUICtrlCreateCheckbox("Creation Class Name", 40, 124, 150, 17)
$CB[3] = GUICtrlCreateCheckbox("Creation Date", 40, 144, 150, 17)
$CB[4] = GUICtrlCreateCheckbox("Description", 40, 164, 150, 17)
$CB[5] = GUICtrlCreateCheckbox("CS Creation Class Name", 40, 184, 150, 17)
$CB[6] = GUICtrlCreateCheckbox("CS Name", 40, 204, 150, 17)
$CB[7] = GUICtrlCreateCheckbox("Executable Path", 40, 224, 150, 17)
$CB[8] = GUICtrlCreateCheckbox("Execution State", 40, 244, 150, 17)
$CB[9] = GUICtrlCreateCheckbox("Handle", 40, 264, 150, 17)
$CB[10] = GUICtrlCreateCheckbox("Handle Count", 40, 284, 150, 17)
$CB[11] = GUICtrlCreateCheckbox("Kernel Mode Time", 40, 304, 150, 17)
$CB[12] = GUICtrlCreateCheckbox("Maximum Working Set Size", 40, 324, 150, 17)
$CB[13] = GUICtrlCreateCheckbox("Minimum Working Set Size", 40, 344, 150, 17)
$CB[14] = GUICtrlCreateCheckbox("OS Creation Class Name", 40, 364, 150, 17)
$CB[15] = GUICtrlCreateCheckbox("OS Name", 240, 84, 150, 17)
$CB[16] = GUICtrlCreateCheckbox("Other Operation Count", 240, 104, 150, 17)
$CB[17] = GUICtrlCreateCheckbox("Other Transfer Count", 240, 124, 150, 17)
$CB[18] = GUICtrlCreateCheckbox("Page Faults", 240, 144, 150, 17)
$CB[19] = GUICtrlCreateCheckbox("Page File Usage", 240, 164, 150, 17)
$CB[20] = GUICtrlCreateCheckbox("Parent Process ID", 240, 184, 150, 17)
$CB[21] = GUICtrlCreateCheckbox("Peak Page File Usage", 240, 204, 150, 17)
$CB[22] = GUICtrlCreateCheckbox(" Peak Virtual Size", 240, 224, 150, 17)
$CB[23] = GUICtrlCreateCheckbox(" Peak Working Set Size", 240, 244, 150, 17)
$CB[24] = GUICtrlCreateCheckbox(" Priority", 240, 264, 150, 17)
$CB[25] = GUICtrlCreateCheckbox("Private Page Count", 240, 284, 150, 17)
$CB[26] = GUICtrlCreateCheckbox("Process ID", 240, 304, 150, 17)
$CB[27] = GUICtrlCreateCheckbox("Quota Non Paged Pool Usage", 240, 324, 180, 17)
$CB[28] = GUICtrlCreateCheckbox("Quota Paged Pool Usage", 240, 344, 150, 17)
$CB[29] = GUICtrlCreateCheckbox("Quota Peak Non Paged Pool Usage", 240, 364, 200, 17)
$CB[30] = GUICtrlCreateCheckbox("Quota Peak Paged Pool Usage", 440, 84, 180, 17)
$CB[31] = GUICtrlCreateCheckbox("Read Operation Count", 440, 104, 150, 17)
$CB[32] = GUICtrlCreateCheckbox("Read Transfer Count", 440, 124, 150, 17)
$CB[33] = GUICtrlCreateCheckbox("Session ID", 440, 144, 150, 17)
$CB[34] = GUICtrlCreateCheckbox("Status", 440, 164, 150, 17)
$CB[35] = GUICtrlCreateCheckbox("Thread Count", 440, 184, 150, 17)
$CB[36] = GUICtrlCreateCheckbox("User Mode Time", 440, 204, 150, 17)
$CB[37] = GUICtrlCreateCheckbox("Virtual Size", 440, 224, 150, 17)
$CB[38] = GUICtrlCreateCheckbox("Windows Version", 440, 244, 150, 17)
$CB[39] = GUICtrlCreateCheckbox("Working Set Size", 440, 264, 150, 17)
$CB[40] = GUICtrlCreateCheckbox("Write Operation Count", 440, 284, 150, 17)
$CB[41] = GUICtrlCreateCheckbox("Write Transfer Count", 440, 304, 150, 17)
$PGUI = GUICtrlCreateCheckbox("Select Processes",440, 324, 100, 17)
GUICtrlSetOnEvent($PGUI, "_ShowProcessChildWindow")
$Button1 = GUICtrlCreateButton("OK", 192, 400, 75, 25, 0)
GUICtrlSetOnEvent(-1,"_Main")
$Button2 = GUICtrlCreateButton("Cancel", 352, 400, 75, 25, 0)
GUICtrlSetOnEvent(-1,"_Quit")
GUISetState(@SW_SHOW, $Form1)
GUISwitch($Form1)

#EndRegion ### END Koda GUI section ###


_CreateChild()

While 1
    Sleep(100) ; So we don't kill the CPU
WEnd



;==============================================================================================
;
;  FUNCTION AREA
;
;=============================================================================================

Func _Main()
    Local $i
    
    For $i = 1 to $list[0][0]
        If GUICtrlRead($radeks[$i]) = 1 OR GUICtrlRead($radeks[$i]) = 257 Then
            MsgBox(1,"",$list[$i][0] & " is checked ")
        EndIf
    Next
    
EndFunc

Func _ShowProcessChildWindow()
    GUISetState(@SW_SHOW, $ChildGUI)    
EndFunc
    

Func _CreateChild()
    $ChildGUI = GUICreate("Main:Processes", 350, 260, 100, 100, -1, -1, $Form1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseChildGUI")
    GUICtrlCreateGroup(" All Processes Running ", 10, 10, 220, 228)
    GUIStartGroup()
    $treeproces = GUICtrlCreateTreeView(20, 30, 200, 192, $TVS_CHECKBOXES)
    $list = ProcessList()
    ReDim $radeks[$list[0][0] + 1]

    For $i = 1 To $list[0][0]
        $radeks[$i] = GUICtrlCreateTreeViewItem($list[$i][0], $treeproces)
    Next
    
    GUICtrlCreateLabel("  Number of running processes :  ", 20, 230, 140, 15)
    GUICtrlCreateLabel($list[0][0], 160, 230, 20, 15)
    $killbutton = GUICtrlCreateButton("Submit", 260, 20, 60, 25)
    GUICtrlSetOnEvent($killbutton, "_CloseChildGUI")
    GUISetState(@SW_HIDE, $ChildGUI)   
EndFunc

Func _CloseChildGUI()
    GUISetState(@SW_HIDE)
EndFunc  ;==>_CloseChildGUI

Func _Quit()
    Exit
EndFunc

Link to comment
Share on other sites

covaks

thanks - works like a charm.

now one more refinement so to speak.

how can i tell which of the treeview items in the child are checked?

i am just getting into autoit and having a lot of fun learning it!!!

thanks again (and a great thanks to all who post/view here)

E

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