Sign in to follow this  
Followers 0
charvi

How to control an opened window?

5 posts in this topic

Okay, I would like to know how to control a window. In the simplified code below, you will see three windows, where my own _debug_ window is open, and at a time I would like to close the _debug_ window with the X button, and setting $debugActive = False. The problem is that it closes the entire program.

The _debug_ window is always at top. I was thinking of making the _debug_ window a $ws_ex_dlgmodalframe and adding a button like the 'Quit' in the other windows, but I wonder if it is necessary?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <File.au3>


Opt("MustDeclareVars", True)

Global $debugActive = True
Dim $nEvent

Dim $hWin1 = GUICreate("", 1680, 1050, 0, 0, $ws_popup)
GUISetBkColor(0x838b83,$hWin1)
Dim $hButQuit1 = GUICtrlCreateButton("Quit", 0, 0, 60, 30)
GUISetState()

Dim $hWin2 = GUICreate("Child Window", 600, 400, 20, 100, $ws_popup, $ws_ex_dlgmodalframe,$hWin1)
GUISetBkColor(0xb0e0ff,$hWin2)
Dim $hButQuit2 = GUICtrlCreateButton("Quit", 0, 0, 60, 30)
GUISetState()

_Debug_("Program started")

While 1
    $nEvent = GUIGetMsg()
    Switch $nEvent
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hButQuit1
            ExitLoop
    EndSwitch
WEnd

Func _Debug_($var)
    ; Main program needs: Global $debugActive = True
    Global $debugWinPopup, $hDebug, $hDebugList
    Dim $Debug_Event
    If $debugActive = False Then Return
    
    Dim $hCf = WinGetHandle("","") ;("[ACTIVE]", "") ; way to get the current window handle that has focus

    If $debugWinPopup = False Then
        $hDebug = GUICreate("Debug window",3+300+3, 600, 730, 100, $ws_sysmenu,$ws_ex_topmost)
        $hDebugList = GUICtrlCreateList("", 0, 0, 300, 550)
        GUISetState(@SW_SHOW)
        $debugWinPopup = True
    EndIf   
    WinActivate($hDebug)
    GUICtrlSetData($hDebugList, $var)
    WinActivate($hCf)

EndFunc

Share this post


Link to post
Share on other sites



Currently you check for a guimsg, then checks it value and if it is equal to GUI_EVENT_CLOSE then you exit the loop

You need to check what window that caused the event and if it is the debug window either hide or guidelete it. if it is the parent window then exit the whole program


My Scripts:Radioblog Club Music DownloaderOther stuff:Fun movieIm serious read the help file it helps :PFight 'Till you drop. Never stop, You Cant give up. Til you reach the top Fight! you’re the best in town Fight!

Share this post


Link to post
Share on other sites

Indeed, clicking on the X gives the GUI_EVENT_CLOSE the value -3, which window it might be.

What is the directive to check which window caused that event please?

Below code slightly modified to see the msgbox I added.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <File.au3>


Opt("MustDeclareVars", True)

Global $debugActive = True
Dim $nEvent

Dim $hWin1 = GUICreate("", 1680, 1050, 0, 0)
GUISetBkColor(0x838b83,$hWin1)
Dim $hButQuit1 = GUICtrlCreateButton("Quit", 0, 0, 60, 30)
GUISetState()

Dim $hWin2 = GUICreate("Child Window", 300, 200, 20, 100,$hWin1)
GUISetBkColor(0xb0e0ff,$hWin2)
Dim $hButQuit2 = GUICtrlCreateButton("Quit", 0, 0, 60, 30)
GUISetState()

_Debug_("Program started")

While 1
    $nEvent = GUIGetMsg()
    Switch $nEvent
    Case $GUI_EVENT_CLOSE
        msgbox(0,"which closer?", $nEvent)
            ExitLoop
        Case $hButQuit1
            ExitLoop
    EndSwitch
WEnd




Func _Debug_($var)
    ; Main program needs: Global $debugActive = True
    Global $debugWinPopup, $hDebug, $hDebugList
    Dim $Debug_Event
    If $debugActive = False Then Return
    
    Dim $hCf = WinGetHandle("","") ;("[ACTIVE]", "") ; way to get the current window handle that has focus

    If $debugWinPopup = False Then
        $hDebug = GUICreate("Debug window",3+300+3, 400, 330, 100, $ws_sysmenu,$ws_ex_topmost)
        $hDebugList = GUICtrlCreateList("", 0, 0, 300, 550)
        GUISetState(@SW_SHOW)
        $debugWinPopup = True
    EndIf   
    WinActivate($hDebug)
    GUICtrlSetData($hDebugList, $var)
    WinActivate($hCf)

EndFunc

Share this post


Link to post
Share on other sites

@rasim: Thank you! It was indeed what I needed; it were the advanced features of GUIGetMsg() that I was missing. Now it works like a charm!

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