Jump to content

closing GUICreate within a GUICreate


monte
 Share

Recommended Posts

Hello, I cannot seem to close a window created within another, without crashing the whole script...as the child window created has same pid as it's parent. Using winclose hangs the script, winkill kills the whole script and exitloop exit's the whole script. To be clear, all I want to do is run "opening pa" gui if needed and then close it when finished, but leave the "emc script" gui open. Here's what I have, thanks for your help!:

#include <GUIConstants.au3>
#include <array.au3>
#notrayicon
$checkRun = "Emc Script"
If WinExists($checkRun) Then Exit

GUICreate("Emc Script", 350, 210)
$button1 = GUICtrlCreateIcon ("C:\progra~1\pa.bmp",-1,10,10)
GUISetState ()
While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
   Select
      Case $msg = $button1
         pa()
   EndSelect
WEnd

func pa()
 If WinExists("pa") Then
  $vServerClip=clipget()
  $vServerString=stringsplit($vServerClip,@TAB)
  $vServer=$vServerString[22]
  WinActivate("pa")
  Send("{F10}tf")
  Send($vServer)
  send("{TAB}a")
  Send("{ENTER}")
  sleep(1000)
  send("{ENTER}")
 else
  global $mycmd="C:\progra~1\citrix\icacli~1\pn.exe /pn:" & '"farm"' & ' /app:"pa"'
  GUICreate("Opening pa", 300, 100)
  GUICtrlCreateLabel("Please press continue to open pa",20, 10,)
  GUICtrlCreateLabel("Once you have accessed pa, press OK",20,30)
  $okbutton = GUICtrlCreateButton("OK", 20, 70, 60)
  $continuebutton = GUICtrlCreateButton("Continue", 120, 70, 60)
  GUISetState(@SW_SHOW)
  While 1
   $msg = GUIGetMsg()
   Select
    Case $msg = $GUI_EVENT_CLOSE
      winkill("Opening pa")
    Case $msg = $continuebutton
      run($mycmd)
    Case $msg = $okbutton
      $vServerClip=clipget()
      $vServerString=stringsplit($vServerClip,@TAB)
      $vServer=$vServerString[22]
      WinActivate("pa")
      Send("{F10}tf")
      Send($vServer)
      send("{TAB}a")
      Send("{ENTER}")
      sleep(1000)
      send("{ENTER}")
      sleep(300)
      winkill("Opening pa")
   EndSelect
  WEnd 
 endif
endfunc
[\code]


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


cppman
            
            
                Posted 
                
            
        
    
    
        


cppman
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 1.5k
                            
                                
                            
                        
                        
                    
                
            
            
                

    
    
        
Anonymous
    
    

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                    (edited)
                
                
            
        
    

    

    

    
        
        
            are you trying to make the child close when the exit button is pressed?


#include <GUIConstants.au3>
#include <array.au3>
#notrayicon
$checkRun = "Emc Script"
If WinExists($checkRun) Then Exit
$MainGUI = GUICreate("Emc Script", 350, 210)
$button1 = GUICtrlCreateIcon("C:\progra~1\pa.bmp", -1, 10, 10)
GUISetState()
While 1
 $msg = GUIGetMsg()
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
 Select
  Case $msg = $button1
   pa()
 EndSelect
WEnd
Func pa()
 If WinExists("pa") Then
  $vServerClip = ClipGet()
  $vServerString = StringSplit($vServerClip, @TAB)
  $vServer = $vServerString[22]
  WinActivate("pa")
  Send("{F10}tf")
  Send($vServer)
  Send("{TAB}a")
  Send("{ENTER}")
  Sleep(1000)
  Send("{ENTER}")
 Else
  Global $mycmd = "C:\progra~1\citrix\icacli~1\pn.exe /pn:" & '"farm"' & ' /app:"pa"'
  $Child = GUICreate("Opening pa", 300, 100)
  GUICtrlCreateLabel("Please press continue to open pa", 20, 10,)
  GUICtrlCreateLabel("Once you have accessed pa, press OK", 20, 30)
  $okbutton = GUICtrlCreateButton("OK", 20, 70, 60)
  $continuebutton = GUICtrlCreateButton("Continue", 120, 70, 60)
  GUISetState(@SW_SHOW)
  While 1
   GUISwitch($MainGUI)
   $msg = GUIGetMsg()
   Select
    Case $msg = $GUI_EVENT_CLOSE
     WinKill("Opening pa")
     ExitLoop
     Case $msg = $continuebutton
     Run($mycmd)
    Case $msg = $okbutton
     $vServerClip = ClipGet()
     $vServerString = StringSplit($vServerClip, @TAB)
     $vServer = $vServerString[22]
     WinActivate("pa")
     Send("{F10}tf")
     Send($vServer)
     Send("{TAB}a")
     Send("{ENTER}")
     Sleep(1000)
     Send("{ENTER}")
     Sleep(300)
     WinKill("Opening pa")
   EndSelect
  WEnd 
 EndIf
EndFunc  ;==>pa

Is that what your trying to do?

Edited by CHRIS95219
Link to comment
Share on other sites

  • Moderators

Look at a few things: GUIDelete() / GUICreate() - And maybe GUISwitch()

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

OK, I've tried those.

guiswitch is not what I'm looking for as my functions are working under the newly created window.

running guidelete on newly created window handle, obtained from guicreate, does not work when implementing from the end of my $okbutton case, the end of my embedded guicreate while nor at the end of my pa()'s if.

I've also tried testing my embedded while againt a variable's value then changing that vaule at the end of $okbutton case, causing the while to end, then running guidelete on newly created window handle. This fails too.

Maybe I'm going about this all wrong. What I want is to run some commands within a program and if that program is not running, start it, then run my commands.... However, some user interaction is needed before my commands can be entered if the program needs to be started (of which autoit cannot duplicate). So my main window's icon checks for the running program, and if found runs my commands. If not found, the starts program and prompts the user with actions needed to be taken by them and then to press ok once those actions have been preformed...allowing my commands embedded within the script to execute.

I originally just put up a msgbox asking to press ok once user interaction has completed, but the whole script stops until ok is pressed. Any suggestions, if I havn't lost you! Thanks.

Link to comment
Share on other sites

  • Moderators

I still have no idea what you want from the dissertation above, but I did go thru it just a little bit, I don't have any of the programs/icons/etc... so I didn't test it for anything, and didn't make but 1 improvement I think, but the code is cleaner, and done the way I intrepreted your explination

#include <GUIConstants.au3>
#include <array.au3>
#notrayicon
$checkRun = "Emc Script"
If WinExists($checkRun) Then Exit
$MainGUI = GUICreate("Emc Script", 350, 210)
$button1 = GUICtrlCreateIcon("C:\progra~1\pa.bmp",-1,10,10)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Select
        Case $msg = $button1
            GUISetState($MainGUI, $GUI_DISABLE);disable current gui
            GUISetState($MainGUI, @SW_HIDE);now hide it so we can move on to the function
            pa()
            GUISetState($MainGUI, @SW_SHOW);now bring it back so we can work with it again
            GUISetState($MainGUI, $GUI_ENABLE);no enable it so it can be worked with
    EndSelect
WEnd
Func pa()
    ConsoleWrite('@@ (17) :(' & @MIN & ':' & @SEC & ') pa()' & @CR);### Trace Function
    If WinExists("pa") Then
        $vServerClip = ClipGet()
    ;$vServerString = StringSplit($vServerClip, @TAB)
        $vServer = StringSplit($vServerClip, @TAB);had a redundant variable above, this way it captures all (even if more than 21) into an array
        WinActivate("pa")
        Send("{F10}tf")
        Send($vServer)
        Send("{TAB}a")
        Send("{ENTER}")
        Sleep(1000)
        Send("{ENTER}")
    Else
        Global $mycmd = "C:\progra~1\citrix\icacli~1\pn.exe /pn:" & '"farm"' & ' /app:"pa"'
        $Pa_GUI = GUICreate("Opening pa", 300, 100)
        GUICtrlCreateLabel("Please press continue to open pa", 20, 10); there was an error here ',' at the end of 10
        GUICtrlCreateLabel("Once you have accessed pa, press OK", 20, 30)
        $okbutton = GUICtrlCreateButton("OK", 20, 70, 60)
        $continuebutton = GUICtrlCreateButton("Continue", 120, 70, 60)
        GUISetState(@SW_SHOW)
        While 1
            $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    GUIDelete($Pa_GUI)
                    ExitLoop
                Case $msg = $continuebutton
                    Run($mycmd)
                Case $msg = $okbutton
                    $vServerClip = ClipGet()
                ;$vServerString = StringSplit($vServerClip, @TAB)
                    $vServer = StringSplit($vServerClip, @TAB);had a redundant variable above, this way it captures all (even if more than 21) into an array
                    WinActivate("pa")
                    Send("{F10}tf")
                    Send($vServer)
                    Send("{TAB}a")
                    Send("{ENTER}")
                    Sleep(1000)
                    Send("{ENTER}")
                    Sleep(300)
                    GUIDelete($Pa_GUI)
                    ExitLoop
            EndSelect
        WEnd
    EndIf
EndFunc  ;==>pa

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

You may want to do a pseudo code so we can see what you want to do. Example:

1. Make main window with one button

2. If button pressed, goto 3

3. Make second window

4. get file from XXXX

5. Run file

6. close child window

7. set focus on main window, goto 2

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