Jump to content

Child window


charvi
 Share

Recommended Posts

Hi,

I would like to create a child window where it is not possible to get focus on the parent window by clicking on it.

The parent is a gray full screen window, if you click on the gray part, the child salmon window disappear, and that's what I want to avoid.

So far is my code as follows. What am I missing?

Thanks for any help.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>

GLOBAL $Form1,$Form2,$qubutton,$event

$Form1 = GUICreate("",1680,1050,0,0,BitOR($ws_popup, $ws_border))
GUISetBkColor(0x838b83,$Form1)
$qubutton = guictrlcreatebutton("Quit",200, 50, 60)
GUISetState()

$Form2 = GUICreate("You",500,500,160,160, $ws_popup, $ws_ex_dlgmodalframe)
GUISetBkColor(0xeecbad,$Form2)
GUISetState()

While 1
  $event = GUIGetMsg()
  Select
    Case $event = $GUI_EVENT_CLOSE or $event=$qubutton
      ExitLoop
  EndSelect
WEnd
Link to comment
Share on other sites

Thanks for your fast reply, dbzfanatic!

Where shall I place your code? If I put it in the While 1 loop, I believe it will overload the computer resources.

I thought there was an elegant way to indicate this behaviour while creating the window (through a Style or exStyle). I tried with $ws_ex_mdichild, but I am not sure what this is...

And another question, how do I close the child window? Sure, I should put a Quit button in the child window, but what is the command to close the child?

Thanks

Link to comment
Share on other sites

You must use GUISetState(@SW_DISABLE,$parent) before creating child and GUISetState(@SW_ENABLE,$parent) when destroying child.

example:

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 369, 276, 193, 125)
$Button1 = GUICtrlCreateButton("Create child", 64, 76, 229, 105, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
            _CreateChild()

    EndSwitch
WEnd

Func _CreateChild()
    GUISetState(@SW_DISABLE,$Form1)
    $child=GUICreate("Child - click on parent!",200,200,-1,-1,-1,-1,$Form1)
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(@SW_ENABLE,$Form1)
    GUIDelete($child)
EndFunc

Note how the child window flashes when you click parent.

-edit-

Actually, now that I tested your code, I see that this isn't really what you want.

You are missing something very important, the salmon GUi is NOT a child of the GRAY Gui. You must pass the handle of the parent to GUICREATE when creating the child GUI. Your code fixed:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>

GLOBAL $Form1,$Form2,$qubutton,$event

$Form1 = GUICreate("",1680,1050,0,0,BitOR($ws_popup, $ws_border))
GUISetBkColor(0x838b83,$Form1)
$qubutton = guictrlcreatebutton("Quit",200, 50, 60)
GUISetState()

$Form2 = GUICreate("You",500,500,160,160, $ws_popup, $ws_ex_dlgmodalframe,$Form1);I added the handle of the parent to the last parameter.
GUISetBkColor(0xeecbad,$Form2)
GUISetState()

While 1
  $event = GUIGetMsg()
  Select
    Case $event = $GUI_EVENT_CLOSE or $event=$qubutton
      ExitLoop
  EndSelect
WEnd

This way both windows will work and the child will be on top of the parent.

Edited by Nahuel
Link to comment
Share on other sites

Excellent Nahuel, the second solution is what I needed. Thank you very much!

And the first solution is very useful too, and contains the answer to close a window: GUIDelete($Form2). I was searching in the help file on the word Close, never thought about Delete! :mellow:

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...