Sign in to follow this  
Followers 0
furroy

Help with child dialogs

2 posts in this topic

#1 ·  Posted (edited)

I have one main window and another second popup window, sort of like a modal dialog.

I'd like both a hot key to popup the second window, and a button on the main window to do the same thing. In my code, the hotkey works fine, but when activated by the button on the main window, the child doesn't work. I thought GuiSwitch() was supposed to fix this, but I don't seem to be using it properly.

Opt("MustDeclareVars", 1)

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

Global $counter = 0, $close_dialog = 0
Global $g_szVersion = "Test Console"

If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)

Opt("GUIOnEventMode", 1); Change to OnEvent mode

HotKeySet("!q", "Terminate")
HotKeySet("!r", "PopupChild")


Local $console = GuiCreate("Test Console", 200, 80, 100, 100, "", $WS_EX_TOPMOST)
Local $rButton = GuiCtrlCreateButton("Popup", 100, 0, 80, 20)
 GUICtrlSetOnEvent($rButton, "PopupChild")
 Local $stateLabel = GuiCtrlCreateLabel("Counter: 0", 0, 0, 100, 20)    

GUISetState(@SW_SHOW, $console)

AdLibEnable("DoUpdate", 1000)

    While 1
        Sleep(1000)
    Wend


Func DoUpdate()
 $counter = $counter + 1
  GuiCtrlSetData($stateLabel, "Counter: " & $counter)
EndFunc ;==>DoUpdate



Func PopupChild()
   $close_dialog = 0
   
   Local $hwnd = GUICreate("Make a Beep", 100, 50) 
     Local $old_gui = GuiSwitch($hwnd)
     ConsoleWrite("Old is " & $hwnd & " new hwnd is " & $old_gui &@LF)

   Local $search =GUICtrlCreateButton ("Beep", 10,10,80,20, $BS_DEFPUSHBUTTON )
   GUICtrlSetOnEvent(-1, "BeepPressed")   

     GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePressed")
   GUISetState(@SW_SHOW)
   
   While Not $close_dialog
      Sleep(50)
   Wend
   
     GuiSwitch($old_gui)
   GuiDelete($hwnd)
Endfunc


Func BeepPressed()
     MsgBox(4096, "test", "test")
        $close_dialog = 1
Endfunc   

Func ClosePressed()
        $close_dialog = 1
Endfunc   

Func Terminate()
     Exit
Endfunc
Edited by furroy

Share this post


Link to post
Share on other sites

I have one main window and another second popup window, sort of like a modal dialog.

I'd like both a hot key to popup the second window, and a button on the main window to do the same thing. In my code, the hotkey works fine, but when activated by the button on the main window, the child doesn't work. I thought GuiSwitch() was supposed to fix this, but I don't seem to be using it properly.

Opt("MustDeclareVars", 1)

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

Global $counter = 0, $close_dialog = 0
Global $g_szVersion = "Test Console"

If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)

Opt("GUIOnEventMode", 1); Change to OnEvent mode

HotKeySet("!q", "Terminate")
HotKeySet("!r", "PopupChild")


Local $console = GuiCreate("Test Console", 200, 80, 100, 100, "", $WS_EX_TOPMOST)
Local $rButton = GuiCtrlCreateButton("Popup", 100, 0, 80, 20)
 GUICtrlSetOnEvent($rButton, "PopupChild")
 Local $stateLabel = GuiCtrlCreateLabel("Counter: 0", 0, 0, 100, 20)    

GUISetState(@SW_SHOW, $console)

AdLibEnable("DoUpdate", 1000)

    While 1
        Sleep(1000)
    Wend


Func DoUpdate()
 $counter = $counter + 1
  GuiCtrlSetData($stateLabel, "Counter: " & $counter)
EndFunc;==>DoUpdate



Func PopupChild()
   $close_dialog = 0
   
   Local $hwnd = GUICreate("Make a Beep", 100, 50) 
     Local $old_gui = GuiSwitch($hwnd)
     ConsoleWrite("Old is " & $hwnd & " new hwnd is " & $old_gui &@LF)

   Local $search =GUICtrlCreateButton ("Beep", 10,10,80,20, $BS_DEFPUSHBUTTON )
   GUICtrlSetOnEvent(-1, "BeepPressed")   

     GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePressed")
   GUISetState(@SW_SHOW)
   
   While Not $close_dialog
      Sleep(50)
   Wend
   
     GuiSwitch($old_gui)
   GuiDelete($hwnd)
Endfunc


Func BeepPressed()
     MsgBox(4096, "test", "test")
        $close_dialog = 1
Endfunc   

Func ClosePressed()
        $close_dialog = 1
Endfunc   

Func Terminate()
     Exit
Endfunc
Yes, it is due to the fact that once an event calls a function then other events are blocked until that function returns. Here is a possible fix.

Opt("MustDeclareVars", 1)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include "onEventFunc.au3"

Global $counter = 0, $close_dialog = 0
Global $g_szVersion = "Test Console"

If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)

Opt("GUIOnEventMode", 1); Change to OnEvent mode

HotKeySet("!q", "Terminate")
HotKeySet("!r", "PopupChild")

Global $dopopup = False
Local $console = GUICreate("Test Console", 200, 80, 100, 100, "", $WS_EX_TOPMOST)
Local $rButton = GUICtrlCreateButton("Popup", 100, 0, 80, 20)
SetOnEvent($rButton, "setPopupChild")
Local $stateLabel = GUICtrlCreateLabel("Counter: 0", 0, 0, 100, 20)

GUISetState(@SW_SHOW, $console)

AdlibEnable("DoUpdate", 1000)

While 1
    If $dopopup Then
        PopupChild()
        $dopopup = False
    EndIf
    Sleep(1000)
WEnd

Func setPopupChild()
    $dopopup = True
EndFunc  ;==>setPopupChild

Func DoUpdate()
    $counter = $counter + 1
    GUICtrlSetData($stateLabel, "Counter: " & $counter)
EndFunc  ;==>DoUpdate



Func PopupChild()
    $close_dialog = 0

    Local $hwnd = GUICreate("Make a Beep", 100, 50)

    Local $old_gui = GUISwitch($hwnd)
    Opt("GUIOnEventMode", 1);
    ConsoleWrite("Old is " & $hwnd & " new hwnd is " & $old_gui & @LF)

    Local $search = GUICtrlCreateButton("Beep", 10, 10, 80, 20, $BS_DEFPUSHBUTTON)
    GUICtrlSetOnEvent(-1, "BeepPressed")

    GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePressed")
    GUISetState(@SW_SHOW)

    While Not $close_dialog
        Sleep(50)
    WEnd

    GUIDelete($hwnd)
    GUISwitch($old_gui)

EndFunc  ;==>PopupChild


Func BeepPressed()
    MsgBox(4096, "test", "test")
    $close_dialog = 1
EndFunc  ;==>BeepPressed

Func ClosePressed()
    $close_dialog = 1
EndFunc  ;==>ClosePressed

Func Terminate()
    Exit
EndFunc  ;==>Terminate

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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