Sign in to follow this  
Followers 0
xtrax

newbie GUI help required

6 posts in this topic

#1 ·  Posted (edited)

hi i was wondering if you guys would tell me what im doing wrong

im sure its very simple but its driving me crazy

you see im trying to open a main gui then another from that

but as soon as i do the controls from the main window stop functioning.

thanks in advance.

CODE
#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

maingui ()

Func maingui ()

$Form1 = GUICreate("Form1", 367, 141, 193, 125)

$Button1 = GUICtrlCreateButton("msgbox", 56, 88, 75, 25, 0)

$Button2 = GUICtrlCreateButton("new gui", 168, 88, 75, 25, 0)

GUISetState(@SW_SHOW)

While 1

$nmsg = GUIGetMsg()

Switch $nmsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

MsgBox(0,"testing ","123")

Case $Button2

gui2 ()

EndSwitch

WEnd

EndFunc

Func gui2 ()

$Form2 = GUICreate("Form2", 307, 172, 303, 219)

$Button3 = GUICtrlCreateButton("close", 96, 120, 75, 25, 0)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Case $Button3

GUIDelete("Form2")

EndSwitch

WEnd

EndFunc

edit:i just noticed maybe i posted this in the wrong place, sorry muttley

Edited by xtrax

Share this post


Link to post
Share on other sites



That happens because AutoIt doesn't support 2 functions at the same time muttley

Try using GuiSetOnEvent and GuiCtrlSetOnEvent :)

Cheers,

L|M|TER

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 367, 141, 193, 125)
$Button1 = GUICtrlCreateButton("msgbox", 56, 88, 75, 25, 0)
$Button2 = GUICtrlCreateButton("new gui", 168, 88, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nmsg = GUIGetMsg()
    Switch $nmsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0,"testing ","123")
        Case $Button2
            gui2 ()
    EndSwitch
WEnd

Func gui2 ()
    $Form2 = GUICreate("Form2", 307, 172, 303, 219)
    $Button3 = GUICtrlCreateButton("close", 96, 120, 75, 25, 0)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete("Form2")
                Return
            Case $Button3
                GUIDelete("Form2")
                Return
        EndSwitch
    WEnd
EndFunc

The thing that has been done is after you delete the child gui then you should exit the function with 'return', so it doesn't stay in the while loop..

Regards

EDIT: LIMITER is right, but if you only want them to interact in the Child window while it is running you could do what I did show you..

Edited by newbiescripter

Share this post


Link to post
Share on other sites

Thank you guys, wish i had asked earlier.

Share this post


Link to post
Share on other sites

Try this :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Dim $form2

$Form1 = GUICreate("Form1", 367, 141, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
$Button1 = GUICtrlCreateButton("msgbox", 56, 88, 75, 25, 0)
GUICtrlSetOnEvent(-1,"button1")
$Button2 = GUICtrlCreateButton("new gui", 168, 88, 75, 25, 0)
GUICtrlSetOnEvent(-1,"button2")
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func gui2 ()
$Form2 = GUICreate("Form2", 307, 172, 303, 219)
$Button3 = GUICtrlCreateButton("close", 96, 120, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd
EndFunc

Func _exit()
Exit
EndFunc

Func _exitchild()
GUIDelete($Form2)
EndFunc

Func button1()
MsgBox(0,"testing ","123")
EndFunc

Func button2()
$Form2 = GUICreate("Form2", 307, 172, 303, 219)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exitchild")
$Button3 = GUICtrlCreateButton("close", 96, 120, 75, 25, 0)
GUICtrlSetOnEvent(-1,"_exitchild")
GUISetState(@SW_SHOW)
EndFunc

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Try this :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Dim $form2

$Form1 = GUICreate("Form1", 367, 141, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
$Button1 = GUICtrlCreateButton("msgbox", 56, 88, 75, 25, 0)
GUICtrlSetOnEvent(-1,"button1")
$Button2 = GUICtrlCreateButton("new gui", 168, 88, 75, 25, 0)
GUICtrlSetOnEvent(-1,"button2")
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func gui2 ()
$Form2 = GUICreate("Form2", 307, 172, 303, 219)
$Button3 = GUICtrlCreateButton("close", 96, 120, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd
EndFunc

Func _exit()
Exit
EndFunc

Func _exitchild()
GUIDelete($Form2)
EndFunc

Func button1()
MsgBox(0,"testing ","123")
EndFunc

Func button2()
$Form2 = GUICreate("Form2", 307, 172, 303, 219)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exitchild")
$Button3 = GUICtrlCreateButton("close", 96, 120, 75, 25, 0)
GUICtrlSetOnEvent(-1,"_exitchild")
GUISetState(@SW_SHOW)
EndFunc
I must say that I rather like the GuiGetmsg, since my exspirience with onevent isn't so good.

For example try pushing the new gui button let say 5 times and then press one of the close buttons.. only the one that has been opened last will close and from here it is imposible to close the others unless your close the main GUI..'

I'm not saying that your example is bad at all. I'm just saying that it's easy to create something that doesn't work as well as it should with onEvent..

Regards

EDIT:

You could use this easy way to tell that it isn't possible to use form1 when form2 is open:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 367, 141, 193, 125)
$Button1 = GUICtrlCreateButton("msgbox", 56, 88, 75, 25, 0)
$Button2 = GUICtrlCreateButton("new gui", 168, 88, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nmsg = GUIGetMsg()
    Switch $nmsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0,"testing ","123")
        Case $Button2
            gui2 ()
    EndSwitch
WEnd

Func gui2 ()
    $Form2 = GUICreate("Form2", 307, 172, 303, 219)
    $Button3 = GUICtrlCreateButton("close", 96, 120, 75, 25, 0)
    GUISetState(@SW_SHOW)

    While 1
        
        If WinActive ("Form1") Then
            WinActivate("Form2")
            MsgBox(48,"Error","Close form2 in order to interact with Form1")
        EndIf
        
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete("Form2")
                Return
            Case $Button3
                GUIDelete("Form2")
                Return
        EndSwitch
    WEnd
EndFunc

I've just inserted:

If WinActive ("Form1") Then
    WinActivate("Form2")
    MsgBox(48,"Error","Close form2 in order to interact with Form1")
EndIf

in the while loop in function gui2.. If there is a better way use that muttley

Edited by newbiescripter

Share this post


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
Sign in to follow this  
Followers 0