Jump to content
Sign in to follow this  
DarkBanana

Child GUI disappears when clicking on a tab twice

Recommended Posts

DarkBanana

Hey there,

I started to work with tabs earlier today but I can't figure out what the problem is.

#include <GuiTab.au3>
#include <WindowsConstants.au3>

Global $Height = @DesktopHeight
Global $Width = @DesktopWidth

$GUI = GUICreate("", $Width, $Height, 0, 0, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX))
GUICtrlCreateMenu("")
$Tab = GUICtrlCreateTab(20,20,$Width/1.2,$Height/1.2)
GUICtrlCreateTabItem("First")
GUICtrlCreateTabItem("Second")
GUISetState()

$GUI_Child_1 = GUICreate("", $Width / 1.3, $Height / 1.3, 100, 100, BitOR($WS_POPUP, $WS_BORDER))
GUISetBkColor(0xCCFFCC)
DllCall("user32.dll", "int", "SetParent", "hwnd", $GUI_Child_1, "hwnd", $GUI)
GUISetState(@SW_SHOW)

$GUI_Child_2 = GUICreate("", $Width / 1.3, $Height / 1.3, 100, 100, BitOR($WS_POPUP, $WS_BORDER))
GUISetBkColor(0xAAAAAAA)
DllCall("user32.dll", "int", "SetParent", "hwnd", $GUI_Child_1, "hwnd", $GUI)
GUISetState(@SW_HIDE)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $Tab
            $SelTab = _GUICtrlTab_GetCurSel($Tab)

            If $SelTab = 0 then
                GUISetState(@SW_HIDE,$GUI_Child_2)
                GUISetState(@SW_SHOW,$GUI_Child_1)
            EndIf

            If $SelTab = 1 then
                GUISetState(@SW_HIDE,$GUI_Child_1)
                GUISetState(@SW_SHOW,$GUI_Child_2)
            EndIf

    EndSwitch
WEnd

If you click twice on the second tab the ChildGUI will disappear and I would like to know why?
 What am I missing? 

Thanks for help.

Share this post


Link to post
Share on other sites
BrewManNH

If you move the GUI you'll see that child 2 isn't connected to the main GUI at all.so when you click the tab again, the gui goes to the back ground.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
jguinch

You main GUI has the focus so the child Window is behind.

You can use the $WS_EX_MDICHILD exstyle for this :

#include <GuiTab.au3>
#include <WindowsConstants.au3>

Global $Height = @DesktopHeight
Global $Width = @DesktopWidth

$GUI = GUICreate("", $Width, $Height, 0, 0, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX))
GUICtrlCreateMenu("")
$Tab = GUICtrlCreateTab(20,20,$Width/1.2,$Height/1.2)
GUICtrlCreateTabItem("First")
GUICtrlCreateTabItem("Second")
GUISetState()

$GUI_Child_1 = GUICreate("", $Width / 1.3, $Height / 1.3, 100, 100, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $GUI)
GUISetBkColor(0xCCFFCC)
GUISetState(@SW_SHOW)

$GUI_Child_2 = GUICreate("", $Width / 1.3, $Height / 1.3, 100, 100, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $GUI)
GUISetBkColor(0xAAAAAAA)
GUISetState(@SW_HIDE)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $Tab
            $SelTab = _GUICtrlTab_GetCurSel($Tab)
            Switch $SelTab
                Case 0
                    GUISetState(@SW_HIDE,$GUI_Child_2)
                    GUISetState(@SW_SHOW,$GUI_Child_1)
                Case 1
                    GUISetState(@SW_HIDE,$GUI_Child_1)
                    GUISetState(@SW_SHOW,$GUI_Child_2)
            EndSwitch
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
DarkBanana

There's one wrong number.... I assigned Child 1 twice.

DllCall("user32.dll", "int", "SetParent", "hwnd", $GUI_Child_1, "hwnd", $GUI)

;should be:

DllCall("user32.dll", "int", "SetParent", "hwnd", $GUI_Child_2, "hwnd", $GUI)

Thank you.

 

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  

×