Jump to content
Sign in to follow this  
cmattb

Call function from child GUI

Recommended Posts

cmattb

So im having a problem calling another function from a child GUI. For some reason, $button2 does not want to do anything. As far as I can tell, I have everything correct, but its probably something dumb that I missed.

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug",1)

    Global $gui1 = GUICreate("GUI numer one", 200, 200) 
    Global $button1 = GUICtrlCreateButton("Go GUI #2!", 50,50)
    GUICtrlSetOnEvent($button1, "gui2")
    GUISetState(@SW_SHOW)

    While 1 
        sleep(200)
    WEnd
    
Func gui2()
    Global $gui2 = GUICreate("GUI numer two", 150, 150) 
    Global $button2 = GUICtrlCreateButton("msg box", 20,50)
    GUICtrlSetOnEvent($button2, "mbox")
    GUISetState(@SW_SHOW)
    While 1 
        sleep(200)
    WEnd
EndFunc

Func mbox()
    msgbox(0,"","Im a message box!")
    
EndFunc

Thanks for taking a look

Edited by cmattb

Share this post


Link to post
Share on other sites
BrettF

Hi,

The second while loop is not needed. Maybe try this:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug", 1)

Global $gui1 = GUICreate("GUI numer one", 200, 200)
Global $button1 = GUICtrlCreateButton("Go GUI #2!", 50, 50)
GUICtrlSetOnEvent($button1, "gui2")
GUISetState(@SW_SHOW)

While 1
    Sleep(200)
WEnd

Func gui2()
    Global $gui2 = GUICreate("GUI numer two", 150, 150)
    Global $button2 = GUICtrlCreateButton("msg box", 20, 50)
    GUICtrlSetOnEvent($button2, "mbox")
    GUISetState(@SW_SHOW)
    GUISetState (@SW_DISABLE, $gui1)
EndFunc  ;==>gui2

Func mbox()
    MsgBox(0, "", "Im a message box!")

EndFunc  ;==>mbox

Cheers,

Brett

Share this post


Link to post
Share on other sites
cmattb

That fixed that. That was just an example script, and I was hoping that would answer enough for me to get the actual script working, but no go for that. So heres a more accurate example script. The problem is that the $ailoc GUI works great the first time, but the second time through the loop, the OK button no longer calls the second function. I've tried everything I can think of, but no success so far. If theres a better way to do something like this than using two functions, Im open to that idea as well.

#include <GUIConstants.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug",1)


Global $autoinstallgui = GUICreate("Parent", 200, 800) 
global $label=GUICtrlCreateEdit (""&@CRLF, 0,0,200,700)
GUISetState(@SW_SHOW, $autoinstallgui)

Global $aiinfo[5]
$aiinfo[1] = ""
$aiinfo[2] = ""
$aiinfo[3] = ""

Global $num = 1 
driverinstall()
while 1 
    sleep(200)
Wend

Func driverinstall()
Do 
    If $aiinfo[$num] = "" Then
        Global $locerror = guicreate("File Location Error",250,100)
        GUISwitch ($locerror)
        Global $ailoc = GUICtrlCreateInput("", 10, 5, 300, 20)
        $btn = GUICtrlCreateButton("&Ok", 40, 75, 60, 20, $BS_DEFPUSHBUTTON)
        GUICtrlSetOnEvent($btn, "updateloc")
        GUISetState (@SW_SHOW, $locerror)
            While 1
                    Sleep(200)
            WEnd
    Endif
GUICtrlSetData($label, $num& " - "&$aiinfo[$num]&@CRLF, 1)
$num = $num + 1
Until $num = 4
EndFunc

Func updateloc()
$aiinfo[$num] = GuiCtrlRead($ailoc)
GUISwitch ($autoinstallgui)
GUIDelete($locerror)
driverinstall()
EndFunc

Thanks again

Share this post


Link to post
Share on other sites
sandin

why using multiple do/while(s)?

try making all controls into single while 1

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

$Form1 = GUICreate("Form1", 400, 300)
$Button1 = GUICtrlCreateButton("Button1", 50, 80, 200, 50)
GUISetState(@SW_SHOW)

$Form2 = GUICreate("Form2", 200, 100)
$Button2 = GUICtrlCreateButton("Button2", 10, 10, 100, 30)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            If WinActive($Form2) Then
                GUIDelete($Form2)
                if (NOT WinExists($Form1)) then Exit
            ElseIf WinActive($Form1) Then
                GUIDelete($Form1)
                if (NOT WinExists($Form2)) then Exit
            EndIf
        case $Button1
            MsgBox(0, "Form1 msg", "button1 on form1 pressed")
        case $Button2
            MsgBox(0, "Form2 msg", "button2 on form2 pressed")
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
cmattb

The problem is the rest of the script is using Opt("GUIOnEventMode", 1) so I cant use case's. What I need is a parent window that cycles through an array, outputting the variables to Edit. If the variable is blank, then another window pops up, asking for the variable. The only way I could think of of doing this is with a child GUI.

The child GUI works great the first time, but if a second variable is missing from the array the OK button no longer calls the second function. I revised the code a bit so that the child GUI never gets deleted, only hidden, but the OK button still doesnt work the second time around.

#include <GUIConstants.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug",1)


Global $autoinstallgui = GUICreate("Parent", 200, 800) 
global $label=GUICtrlCreateEdit (""&@CRLF, 0,0,200,700)
GUISetState(@SW_SHOW, $autoinstallgui)

    Global $locerror = guicreate("File Location Error",250,100)
    GUISwitch ($locerror)
    Global $ailoc = GUICtrlCreateInput("", 10, 5, 300, 20)
    $btn = GUICtrlCreateButton("&Ok", 40, 75, 60, 20, $BS_DEFPUSHBUTTON)
    GUICtrlSetOnEvent($btn, "updateloc")
    GUISetState (@SW_HIDE, $locerror)
        
GUISwitch ($autoinstallgui)

Global $aiinfo[5]

Global $num = 1 
driverinstall()
while 1 
    sleep(200)
Wend

Func driverinstall()
Do 
    If $aiinfo[$num] = "" Then
            GUISwitch ($locerror)
            GUISetState (@SW_SHOW, $locerror)
            While 1
                    sleep(200)
            WEnd
    Endif
GUICtrlSetData($label, $num& " - "&$aiinfo[$num]&@CRLF, 1)
$num = $num + 1
Until $num = 4
EndFunc

Func updateloc()
$aiinfo[$num] = GuiCtrlRead($ailoc)
GUISwitch ($autoinstallgui)
driverinstall()
EndFunc
Edited by cmattb

Share this post


Link to post
Share on other sites
cmattb

I don't know whats up with the child GUI, but I just found the InputBox function. Its exactly what I need. If anyones interest, working code example is below:

#include <GUIConstants.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug",1)


Global $autoinstallgui = GUICreate("Parent", 200, 800) 
global $label=GUICtrlCreateEdit (""&@CRLF, 0,0,200,700)
GUISetState(@SW_SHOW, $autoinstallgui)
        

Global $aiinfo[5]

Global $num = 1 
driverinstall()
while 1 
    sleep(200)
Wend

Func driverinstall()
Do 
    If $aiinfo[$num] = "" Then $aiinfo[$num] = InputBox("Missing File Location", "File Location:", "", "")
    
GUICtrlSetData($label, $num& " - "&$aiinfo[$num]&@CRLF, 1)
$num = $num + 1
Until $num = 4
EndFunc

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  

×