Jump to content

Nesting Tab Controls


Recommended Posts

Hello! 

I am trying to figure out how to nest a tab control within another tab control. 

The help file says that one GUI can not have more than one Tab control and they show this example: 

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

 $hGUI = GUICreate("Test", 500, 500)

 GUISetState()

 ; Create child GUIs to hold tabs
 $hTab_Win0 = GUICreate("", 400, 200, 50, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
 $hTab_0 = GUICtrlCreateTab(10, 10, 380, 180)
     $hTab_00 = GUICtrlCreateTabitem("00")
         GUICtrlCreateButton("00", 160, 90, 80, 30)
     $hTab_01 = GUICtrlCreateTabitem("01")
         GUICtrlCreateButton("01", 160, 90, 80, 30)

 GUICtrlCreateTabitem ("")
 GUISetState()

 $hTab_Win1 = GUICreate("", 400, 200, 50, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
 $hTab_1 = GUICtrlCreateTab(10, 10, 380, 180)
     $hTab_10 = GUICtrlCreateTabitem("10")
         GUICtrlCreateButton("10", 160, 90, 80, 30)
     $hTab_11 = GUICtrlCreateTabitem("11")
         GUICtrlCreateButton("11", 160, 90, 80, 30)
 GUICtrlCreateTabitem ("")
 GUISetState()

 While 1
     Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
             Exit
     EndSwitch
 WEnd

They are creating 2 Gui's and each one has its own Tab control, it follows the rules and works as expected! 

Now, my question is - Can I create a GUI on one of the Tab Items and put a tab control onto that GUI with its own tab items? 

I have tried changing the parent to $hTab_Win0, I also tried $hTab_0 as a parent and neither one of those options gives me what I want.

Edited by JakeKenmode
Link to comment
Share on other sites

  • Moderators

JakeKenmode,

You need yet more child GUIs - and you need to manage which appears when the tab is changed: ;)

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

; Main GUI
$hGUI = GUICreate("Test", 500, 500)

GUISetState()

; Create top child GUI to hold tabs
$hTab_Win0 = GUICreate("", 400, 200, 50, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$cTab_0 = GUICtrlCreateTab(10, 10, 380, 180)
$cTab_00 = GUICtrlCreateTabItem("00")
$cTab_01 = GUICtrlCreateTabItem("01")

GUICtrlCreateTabItem("")
GUISetState()

; Create bottom child GUI to hold tabs
$hTab_Win1 = GUICreate("", 400, 200, 50, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$cTab_1 = GUICtrlCreateTab(10, 10, 380, 180)
$cTab_10 = GUICtrlCreateTabItem("10")
GUICtrlCreateButton("10", 160, 90, 80, 30)
$cTab_11 = GUICtrlCreateTabItem("11")
GUICtrlCreateButton("11", 160, 90, 80, 30)
GUICtrlCreateTabItem("")
GUISetState()

; Create child GUI to hold internal tab for first tab of top child
$hTabWin0_Child0 = GUICreate("", 330, 120, 40, 50, $WS_POPUP, $WS_EX_MDICHILD, $hTab_Win0)
GUISetBkColor(0xFF0000)
$cTab_0_ChildTab_0 = GUICtrlCreateTab(10, 10, 310, 100)
$cTab_0000 = GUICtrlCreateTabItem("000")
GUICtrlCreateButton("0000", 50, 50, 80, 30)
$cTab_0001 = GUICtrlCreateTabItem("001")
GUICtrlCreateButton("0001", 50, 50, 80, 30)
GUICtrlCreateTabItem("")
GUISetState()

; Create child GUI to hold internal tab for second tab of top child
$hTabWin0_Child1 = GUICreate("", 330, 120, 40, 50, $WS_POPUP, $WS_EX_MDICHILD, $hTab_Win0)
GUISetBkColor(0x00FF00)
$cTab_0_ChildTab_1 = GUICtrlCreateTab(10, 10, 310, 100)
$cTab_0110 = GUICtrlCreateTabItem("000")
GUICtrlCreateButton("0110", 50, 50, 80, 30)
$cTab_0111 = GUICtrlCreateTabItem("001")
GUICtrlCreateButton("0111", 50, 50, 80, 30)
GUICtrlCreateTabItem("")

GUISetState(@SW_HIDE)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cTab_0
            ; Which tab has been selected?
            Switch GUICtrlRead($cTab_0)
                Case 0
                    ; Adjust child GUIs accordingly
                    GUISetState(@SW_HIDE, $hTabWin0_Child1)
                    GUISetState(@SW_SHOW, $hTabWin0_Child0)
                Case 1
                    GUISetState(@SW_HIDE, $hTabWin0_Child0)
                    GUISetState(@SW_SHOW, $hTabWin0_Child1)
            EndSwitch
    EndSwitch
WEnd
I hope that the code is clear enough - but you will have to wait until tomorrow if you want a more detailed explanation as it has been a tiring day. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks agian Melba!, The hiding and showing of the GUI's was the part I was missing. 

Uhg! This might get messy though! 

I will have 2 Main tabs and on each of those main tabs there will be various other tabs. 

For starters it will be like this. 

Tab1 - 

     Tab a

     Tab b

Tab2 - 

     Tab a

     Tab b

     Tab c

     Tab d

     Tab e

That's a good amount of hide/show management haha! 

I also need to have all of this resize itself correctly! Below is where I am currently. The second list view will turn into the Tab control and each tab will house the listview. 

My question now is on the GUICtlrsetResize() Function. I am assuming this only works for controls. If I have GUI's on each tab, when I resize, I'm thinking my controls will resize as expected, but I will have to do something else to "dock" and resize all of my GUI's. 

I'll experiment a little and come back in a bit! 

#Region Includes
#include "winapi.au3"
#include "GuiToolbar.au3"
#include "GuiImageList.au3"
#include "GuiConstantsEx.au3"
#include <WindowsConstants.au3>
#include "GUITab.au3"
#EndRegion

AutoItSetOption('MouseCoordMode', 2)

#Region URL ref
;This is a site I used to trial and error finding the Id's for the Icons I wanted.
;http://diymediahome.org/windows-icons-reference-list-with-details-locations-images/
#EndRegion

#Region Vars
;Only Tested on Win7 64 machine
Local $fIconsLoc1 = "imageres.dll"
Local $fIconsLoc2 = "Resources\Icons\Undo.ico"

Global $aStrings[12]
Local $iNew,$iBrowse,$iEdit,$iDelete,$iSave,$iPrint
Global Enum $e_new =0, $e_edit, $e_delete, $e_save, $e_print, $e_undo

; Icon Index from DLL
$iNew = 2
;$iBrowse = 202
$iEdit = 111
$iDelete = 84
$iSave = 23
$iPrint = 46

$DividerOffset = 250

$BkColor = 0xf0f0f0

;Create Form, Toobar and ImageList
$hGui = GUICreate("Test",660, 320, 192, 125, BitOR($WS_OVERLAPPEDWINDOW, $WS_POPUP))
$hToolbar1 = _GUICtrlToolbar_Create($hGui)
$imgs = _GUIImageList_Create(32,32,5) ; change first 2 params to Size the icons accordingly.

#EndRegion Vars

#Region Toolbar
;Populate Image List
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iNew,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iEdit,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iDelete,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iSave,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iPrint,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc2,0,True)

;Add Text to Buttons in Toolbar
$aStrings[$e_new] = _GUICtrlToolbar_AddString($hToolbar1, "&New")
$aStrings[$e_edit] = _GUICtrlToolbar_AddString($hToolbar1, "&Edit")
$aStrings[$e_delete] = _GUICtrlToolbar_AddString($hToolbar1, "&Delete")
$aStrings[$e_save] = _GUICtrlToolbar_AddString($hToolbar1, "&Save")
$aStrings[$e_print] = _GUICtrlToolbar_AddString($hToolbar1, "&Print")
$aStrings[$e_undo] = _GUICtrlToolbar_AddString($hToolbar1, "&Undo")

;Set Imagelist of Toolbar to my ImageList
$t = _GUICtrlToolbar_SetImageList($hToolbar1, $imgs)

;Add buttons to toolbar
_GUICtrlToolbar_AddButton($hToolbar1, 1000, $e_new,$aStrings[$e_new])
_GUICtrlToolbar_AddButton($hToolbar1, 1001, $e_edit,$aStrings[$e_edit])
_GUICtrlToolbar_AddButton($hToolbar1, 1002, $e_delete,$aStrings[$e_delete])
_GUICtrlToolbar_AddButton($hToolbar1, 1003, $e_save,$aStrings[$e_save])
_GUICtrlToolbar_AddButton($hToolbar1, 1004, $e_print,$aStrings[$e_print])
_GUICtrlToolbar_AddButton($hToolbar1, 1005, $e_undo,$aStrings[$e_undo])

#EndRegion Toolbar

GUISetState()

#Region Create Tabs
$hTab = GUICtrlCreateTab(-1,60,665,265)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH,$GUI_DOCKRIGHT))

; Create Tab Items
GUICtrlCreateTabItem("Tab1")
GUICtrlCreateLabel("",-1,82,665,265)
GUICtrlSetBkColor(-1, $BkColor)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH,$GUI_DOCKRIGHT))
GUICtrlSetState(-1, $GUI_DISABLE)

$ListView1  = GUICtrlCreateListView("col1|col2|col3", 5, 85, $DividerOffset - 5, 232)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH))

$ListView2 = GUICtrlCreateListView("col1|col2|col3", $DividerOffset + 5, 85, 660 - $DividerOffset - 10, 232)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKRIGHT))

$Divider1 = GUICtrlCreateLabel('', $DividerOffset, 85, 5, 232)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM))

GUICtrlSetCursor(-1, 13)

GUICtrlCreateTabItem("Tab2")
GUICtrlCreateLabel("",0,82,665,265)
GUICtrlSetBkColor(-1, $BkColor)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH,$GUI_DOCKRIGHT))
GUICtrlSetState(-1, $GUI_DISABLE)

$ListView3  = GUICtrlCreateListView("col1|col2|col3", 5, 85, $DividerOffset - 5, 232)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH))

$ListView4 = GUICtrlCreateListView("col1|col2|col3", $DividerOffset + 5, 85, 660 - $DividerOffset - 10, 232)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKRIGHT))

$Divider2 = GUICtrlCreateLabel('', $DividerOffset, 85, 5, 232)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM))

GUICtrlSetCursor(-1, 13)

; Finished Creating Tabs

GUICtrlCreateTabItem("")
GUISetState()
#EndRegion End tabs

#Region GUI Message Loop

While 1
    $idMsg = GUIGetMsg()
    Switch $idMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Divider1
            Resize()
        Case $Divider2
            Resize()
    EndSwitch
WEnd
#EndRegion GUI Message Loop

#Region Functions
Func Resize()
    GUISetCursor(13, 1, $hGui)
    $siz = WinGetClientSize($hGui)
    Do
        $arr = GUIGetCursorInfo($hGui)
        $pos = MouseGetPos(0)
        Select
            Case $pos < 100
                $pos = 100
            Case $pos > $siz[0] - 100
                $pos = $siz[0] - 100
        EndSelect
        If $pos <> $DividerOffset Then
            $DividerOffset = $pos
            GUICtrlSetPos($ListView1, -1, -1, $DividerOffset - 5)
            GUICtrlSetPos($ListView2, $DividerOffset + 5, -1, $siz[0] - $DividerOffset - 10)
            GUICtrlSetPos($ListView3, -1, -1, $DividerOffset - 5)
            GUICtrlSetPos($ListView4, $DividerOffset + 5, -1, $siz[0] - $DividerOffset - 10)
        EndIf
    Until Not $arr[2]
    GUICtrlSetPos($Divider1, $DividerOffset)
    GUICtrlSetPos($Divider2, $DividerOffset)
    GUISetCursor(-1, 0, $hGui)
EndFunc


#EndRegion functions
Link to comment
Share on other sites

  • Moderators

JakeKenmode,

When I need to resize non-native controls (which is what child GUIs essentially are) I often create a native label which can automatically resize and then resize the control to match the label once the resizing is finished - this thread shows an example with ListViews. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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