Jump to content

Two guis one script


 Share

Recommended Posts

Use the normal GuiCreate and modify like this:

#include <GUIConstants.au3>

$Gui1=GUICreate("My 1 GUI") ; will create a dialog box that when displayed is centered
$Button1=GUICtrlCreateButton ( "Go" , 0, 0 )

GUISetState (@SW_SHOW)    ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg1 = GUIGetMsg()
    If $msg1 = $GUI_EVENT_CLOSE Then 
        ExitLoop
    ElseIf $msg1 = $Button1 Then
        AnotherGui ()
    EndIf   
Wend

Func AnotherGui ()
$Gui2=GUICreate("My 2 GUI") ; will create a dialog box that when displayed is centered
$Button2=GUICtrlCreateButton ( "Stop" , 0, 0 )

GUISetState (@SW_SHOW)    ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg2 = GUIGetMsg()
    If $msg2 = $GUI_EVENT_CLOSE Then 
        ExitLoop
    ElseIf $msg2 = $Button2 Then
        GUIDelete ( $Gui2 )
        ExitLoop
    EndIf   
Wend
EndFunc

Be sure to use variables once, that's all.

And you could use OnEventMode to be more "responsive".

#include <GUIConstants.au3>

> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 
$mainwindow = GUICreate("Hello World", 200, 100)
> GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState(@SW_SHOW)

 

While 1
  Sleep(1000) ; Idle around
WEnd

 

Func CLOSEClicked()
 ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
 ;and @GUI_WINHANDLE would equal $mainwindow 
  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc
Edited by dabus
Link to comment
Share on other sites

Use the normal GuiCreate and modify like this:

#include <GUIConstants.au3>

$Gui1=GUICreate("My 1 GUI"); will create a dialog box that when displayed is centered
$Button1=GUICtrlCreateButton ( "Go" , 0, 0 )

GUISetState (@SW_SHOW)      ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg1 = GUIGetMsg()
    If $msg1 = $GUI_EVENT_CLOSE Then 
        ExitLoop
    ElseIf $msg1 = $Button1 Then
        AnotherGui ()
    EndIf    
Wend

Func AnotherGui ()
$Gui2=GUICreate("My 2 GUI"); will create a dialog box that when displayed is centered
$Button2=GUICtrlCreateButton ( "Stop" , 0, 0 )

GUISetState (@SW_SHOW)      ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg2 = GUIGetMsg()
    If $msg2 = $GUI_EVENT_CLOSE Then 
        ExitLoop
    ElseIf $msg2 = $Button2 Then
        GUIDelete ( $Gui2 )
        ExitLoop
    EndIf    
Wend
EndFunc

Be sure to use variables once, that's all.

And you could use OnEventMode to be more "responsive".

#include <GUIConstants.au3>

> Opt("GUIOnEventMode", 1); Change to OnEvent mode 
$mainwindow = GUICreate("Hello World", 200, 100)
> GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState(@SW_SHOW)

 

While 1
  Sleep(1000); Idle around
WEnd

 

Func CLOSEClicked()
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
;and @GUI_WINHANDLE would equal $mainwindow 
  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc
ok thank you this is very helpfull thanks so much for the examples !
Link to comment
Share on other sites

ok thank you this is very helpfull thanks so much for the examples !

I would recommend using the GUIGetMsg(1). It will allow you to poll both GUI's at the same time for events. Otherwise with the methods I have seen above you will only be able to perform on events happening in the last open GUI. It all really depends on what you are trying to do, and your preferences. The helpfile explains how to use the advanced message system to do what you are wanting done.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I would recommend using the GUIGetMsg(1). It will allow you to poll both GUI's at the same time for events. Otherwise with the methods I have seen above you will only be able to perform on events happening in the last open GUI. It all really depends on what you are trying to do, and your preferences. The helpfile explains how to use the advanced message system to do what you are wanting done.

JS

hi hmmm when i close gui 3 it shut downs the main gui is there a way to close just gui 3 ?

thank you

michael

GuiSetState()
While 1
    $msg3 = GuiGetMsg()
    If $Msg3 = $GUI_EVENT_CLOSE Then ExitLoop
Link to comment
Share on other sites

hi hmmm when i close gui 3 it shut downs the main gui is there a way to close just gui 3 ?

thank you

michael

GuiSetState()
While 1
    $msg3 = GuiGetMsg()
    If $Msg3 = $GUI_EVENT_CLOSE Then ExitLoop
Well you need to look into working with GUI's like I mentioned above. Using the advanced option of GUIGetMsg() I know it is alot of hassle to re-write some of the code to accomodate it, but it is fully worth it.

I will give an example soon. I am currently working on a script that has two GUI's and having no issues. I can close either one.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

  • 2 weeks later...

Well you need to look into working with GUI's like I mentioned above. Using the advanced option of GUIGetMsg() I know it is alot of hassle to re-write some of the code to accomodate it, but it is fully worth it.

I will give an example soon. I am currently working on a script that has two GUI's and having no issues. I can close either one.

JS

ok thank you will be looking fwd to it

Link to comment
Share on other sites

here is the example that i templet my gui interfaces from that open more windows. hope it helps or what u are looking for

#include <GuiConstants.au3>
#include <Process.au3>

Dim $intWindow
Dim $secwindow

DisplayGUI()

Func DisplayGUI()
    
    Local $intWindow
    Local $intBtnExit
    Local $intMsg
    Local $intBtnDelete
    
    $intWindow = GUICreate("script", 500, 180)
    
    $intBtnsec = GUICtrlCreateButton("Second", 100, 130, 70, 30)
    $intBtnExit = GUICtrlCreateButton("Exit", 385, 130, 70, 30)
    
    
    GUISetState()
    While 1
        $intMsg = GUIGetMsg()
        Select
            Case $intMsg = $GUI_EVENT_CLOSE Or $intMsg = $intBtnExit
                ExitLoop
            Case $intMsg = $intBtnsec
                sectest()
        EndSelect
    WEnd
    GUIDelete($intWindow)
EndFunc



Func sectest()
    
    $delwindow = GUICreate("Delete Printers", 400, 230, -1, -1, BitOR($WS_POPUP,$WS_CAPTION), -1, $intWindow)
    $DelBtnExit = GUICtrlCreateButton("Exit", 305, 190, 70, 30)

    
    GUISetState(@SW_SHOW)
    While 2
        $msg2 = GUIGetMsg()
        Select
        Case $msg2 = $DelBtnExit
            GUIDelete($delwindow)
            Return
            
        EndSelect
    WEnd
    Exit
EndFunc
Link to comment
Share on other sites

here is the example that i templet my gui interfaces from that open more windows. hope it helps or what u are looking for

#include <GuiConstants.au3>
#include <Process.au3>

Dim $intWindow
Dim $secwindow

DisplayGUI()

Func DisplayGUI()
    
    Local $intWindow
    Local $intBtnExit
    Local $intMsg
    Local $intBtnDelete
    
    $intWindow = GUICreate("script", 500, 180)
    
    $intBtnsec = GUICtrlCreateButton("Second", 100, 130, 70, 30)
    $intBtnExit = GUICtrlCreateButton("Exit", 385, 130, 70, 30)
    
    
    GUISetState()
    While 1
        $intMsg = GUIGetMsg()
        Select
            Case $intMsg = $GUI_EVENT_CLOSE Or $intMsg = $intBtnExit
                ExitLoop
            Case $intMsg = $intBtnsec
                sectest()
        EndSelect
    WEnd
    GUIDelete($intWindow)
EndFunc
Func sectest()
    
    $delwindow = GUICreate("Delete Printers", 400, 230, -1, -1, BitOR($WS_POPUP,$WS_CAPTION), -1, $intWindow)
    $DelBtnExit = GUICtrlCreateButton("Exit", 305, 190, 70, 30)

    
    GUISetState(@SW_SHOW)
    While 2
        $msg2 = GUIGetMsg()
        Select
        Case $msg2 = $DelBtnExit
            GUIDelete($delwindow)
            Return
            
        EndSelect
    WEnd
    Exit
EndFunc
thank you Zithen that is just what i was looking for
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...