Jump to content

Gui Tabs


Sushi
 Share

Go to solution Solved by mpower,

Recommended Posts

Hi, I am having some trouble working around creating inputs within smaller windows in different tabs.

Basically, I want to press a button on one tab and create inputs on the second and third tab. My trouble is having the label and inputs display correctly on the child windows within these tabs. Without the child windows, I can just use GUISwitch() to manage tabs and create inputs. Is there a function or method used to correctly switch the handle to the child windows?

I am posting the code for reference of what I am trying to do.

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <guiconstants.au3>

;Set a HotKey
HotKeySet("{ESC}", "Quit")

Main()

Func Main()

    ;Create a GUI
    Global $handleGUI = GUICreate("", 800, 600)

    ;Create label
    GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))

    ;Create tab
    Global $Tab = GUICtrlCreateTab(5, 5, 790, 550)

    ;Create Tab item 1 and set color
    Global $Tab1 = GUICtrlCreateTabItem ("Tab1")
    Global $Button = GUICtrlCreateButton("Button", 350, 250, 85, 25)
        GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)


    ;Create Tab item 2 and set color
    Global $Tab2 = GUICtrlCreateTabItem ("Tab2")
    GUICtrlCreateLabel("", 15, 95)
        GUICtrlCreateTabItem("")

    ;Create Tab item 3 and set color
    Global $Tab3 = GUICtrlCreateTabItem ("Tab3")
    GUICtrlCreateTabItem("")

    ;Create small window in Tab 3
    Global $Window = GUICreate("", 780, 520, 9, 30, $WS_POPUP, BitOR($WS_EX_CLIENTEDGE, $WS_EX_MDICHILD), $handleGUI)
    GUISetBkColor(0xF5F5F5) ; Just to show the GUI clearly
    GUISetState(@SW_SHOW, $Window)
    GUICtrlCreateTabItem ("")

    ;Create small window in Tab 2
    GUISwitch($handleGUI, $Tab2)
    Global $Window1 = GUICreate("", 780, 520, 9, 30, $WS_POPUP, BitOR($WS_EX_CLIENTEDGE, $WS_EX_MDICHILD), $handleGUI)
    GUISetBkColor(0xF5F5F5) ; Just to show the GUI clearly
    GUISetState(@SW_HIDE, $Window1)
    GUICtrlCreateTabItem("")

    ; Loop until the user exits
    While 1
        If GUICtrlRead($Tab) = 0 Then
            GUISetState(@SW_HIDE, $Window)
            GUISetState(@SW_HIDE, $Window1)
        EndIf

        If GUICtrlRead($Tab) = 1 Then
            GUISetState(@SW_HIDE, $Window)
            GUISetState(@SW_SHOW, $Window1)


        EndIf

        If GUICtrlRead($Tab) = 2 Then
            GUISetState(@SW_SHOW, $Window)
            GUISetState(@SW_HIDE, $Window1)
        EndIf

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $Button
                ;Create Inputs
                GUICtrlDelete($Button)
                CreateInputTab2()
                CreateInputTab3()
        EndSwitch

    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($handleGUI)

EndFunc   ;==>Main

Func Quit()
    Exit
EndFunc


Func CreateInputTab2()
    GUISwitch($handleGUI, $Tab2)
    GUICtrlCreateLabel("Input 2 :", 150, 150)
    GuiCtrlCreateInput("", 200, 150)
EndFunc

Func CreateInputTab3()
    GUISwitch($handleGUI, $Tab3)
    GUICtrlCreateLabel("Input 3 :", 150, 150)
    GuiCtrlCreateInput("", 200, 150)
EndFunc
Link to comment
Share on other sites

  • Moderators

Sushi,

This seems to work as you wish: :)

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <guiconstants.au3>

;Set a HotKey
HotKeySet("{ESC}", "Quit")

Main()

Func Main()

    ;Create a GUI
    Global $handleGUI = GUICreate("", 800, 600)

    ;Create label
    GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))

    ;Create tab
    Global $Tab = GUICtrlCreateTab(5, 5, 790, 550)

    ;Create Tab item 1 and set color
    Global $Tab1 = GUICtrlCreateTabItem ("Tab1")
    Global $Button = GUICtrlCreateButton("Button", 350, 250, 85, 25)

    ;Create Tab item 2 and set color
    Global $Tab2 = GUICtrlCreateTabItem ("Tab2")
    GUICtrlCreateLabel("", 15, 95)

    ;Create Tab item 3 and set color
    Global $Tab3 = GUICtrlCreateTabItem ("Tab3")

    GUICtrlCreateTabItem("") ; Only needed once

    ;Create small window in Tab 3
    Global $Window = GUICreate("Tab 3 GUI", 780, 520, 9, 30, $WS_POPUP, BitOR($WS_EX_CLIENTEDGE, $WS_EX_MDICHILD), $handleGUI)
    GUISetBkColor(0xFF0000) ; Just to show the GUI clearly
    GUISetState(@SW_HIDE, $Window)

    ;Create small window in Tab 2
    GUISwitch($handleGUI, $Tab2)
    Global $Window1 = GUICreate("Tab 2 GUI", 780, 520, 9, 30, $WS_POPUP, BitOR($WS_EX_CLIENTEDGE, $WS_EX_MDICHILD), $handleGUI)
    GUISetBkColor(0x00FF00) ; Just to show the GUI clearly
    GUISetState(@SW_HIDE, $Window1)

    GUISetState(@SW_SHOW, $handleGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $Button
                ;Create Inputs
                GUICtrlDelete($Button)
                CreateInputTab2()
                CreateInputTab3()

            Case $Tab
                Switch GUICtrlRead($Tab)
                    Case 0
                        GUISetState(@SW_HIDE, $Window)
                        GUISetState(@SW_HIDE, $Window1)
                    Case 1
                        GUISetState(@SW_HIDE, $Window)
                        GUISetState(@SW_SHOW, $Window1)
                    Case 2
                        GUISetState(@SW_SHOW, $Window)
                        GUISetState(@SW_HIDE, $Window1)
                EndSwitch

        EndSwitch

    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($handleGUI)

EndFunc   ;==>Main

Func Quit()
    Exit
EndFunc


Func CreateInputTab2()
    ; Switch to the child GUI
    GUISwitch($Window1)
    ; Create controls
    GUICtrlCreateLabel("Input 2 :", 150, 150)
    GuiCtrlCreateInput("", 200, 150)
    ; Switch back
    GUISwitch($handleGUI)
EndFunc

Func CreateInputTab3()
    GUISwitch($Window)
    GUICtrlCreateLabel("Input 3 :", 150, 150)
    GuiCtrlCreateInput("", 200, 150)
    GUISwitch($handleGUI)
EndFunc
Please ask if you have any questions. :)

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

  • Solution

I would use @SW_SHOWNOACTIVATE for a more elegant approach when switching tabs, otherwise the main GUI loses focus.

Case $Tab
                Switch GUICtrlRead($Tab)
                    Case 0
                        GUISetState(@SW_HIDE, $Window)
                        GUISetState(@SW_HIDE, $Window1)
                    Case 1
                        GUISetState(@SW_HIDE, $Window)
                        GUISetState(@SW_SHOWNOACTIVATE, $Window1)
                    Case 2
                        GUISetState(@SW_SHOWNOACTIVATE, $Window)
                        GUISetState(@SW_HIDE, $Window1)
                EndSwitch

I would also probably look into resolving the issues of clicking on the child gui resulting in loss of focus.

For ideas on how to tackle the focus issue see here: /?do=embed' frameborder='0' data-embedContent>>

 

Final solution:

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <guiconstants.au3>

;Set a HotKey
HotKeySet("{ESC}", "Quit")

Main()

Func Main()

    ;Create a GUI
    Global $handleGUI = GUICreate("", 800, 600)

    ;Create label
    GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))

    ;Create tab
    Global $Tab = GUICtrlCreateTab(5, 5, 790, 550)

    ;Create Tab item 1 and set color
    Global $Tab1 = GUICtrlCreateTabItem ("Tab1")
    Global $Button = GUICtrlCreateButton("Button", 350, 250, 85, 25)

    ;Create Tab item 2 and set color
    Global $Tab2 = GUICtrlCreateTabItem ("Tab2")
    GUICtrlCreateLabel("", 15, 95)

    ;Create Tab item 3 and set color
    Global $Tab3 = GUICtrlCreateTabItem ("Tab3")

    GUICtrlCreateTabItem("") ; Only needed once

    ;Create small window in Tab 3
    Global $Window = GUICreate("Tab 3 GUI", 780, 520, 9, 30, $WS_POPUP, BitOR($WS_EX_CLIENTEDGE, $WS_EX_MDICHILD), $handleGUI)
    GUISetBkColor(0xFF0000) ; Just to show the GUI clearly
    GUISetState(@SW_HIDE, $Window)

    ;Create small window in Tab 2
    GUISwitch($handleGUI, $Tab2)
    Global $Window1 = GUICreate("Tab 2 GUI", 780, 520, 9, 30, $WS_POPUP, BitOR($WS_EX_CLIENTEDGE, $WS_EX_MDICHILD), $handleGUI)
    GUISetBkColor(0x00FF00) ; Just to show the GUI clearly
    GUISetState(@SW_HIDE, $Window1)

    GUISetState(@SW_SHOW, $handleGUI)
    GUIRegisterMsg( $WM_NCACTIVATE, "WM_NCACTIVATE" )

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $Button
                ;Create Inputs
                GUICtrlDelete($Button)
                CreateInputTab2()
                CreateInputTab3()

            Case $Tab
                Switch GUICtrlRead($Tab)
                    Case 0
                        GUISetState(@SW_HIDE, $Window)
                        GUISetState(@SW_HIDE, $Window1)
                    Case 1
                        GUISetState(@SW_HIDE, $Window)
                        GUISetState(@SW_SHOWNOACTIVATE, $Window1)
                    Case 2
                        GUISetState(@SW_SHOWNOACTIVATE, $Window)
                        GUISetState(@SW_HIDE, $Window1)
                EndSwitch

        EndSwitch

    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($handleGUI)

EndFunc   ;==>Main

Func Quit()
    Exit
EndFunc



; Prevent child windows in making GUI title bar dimmed
Func WM_NCACTIVATE( $hWnd, $iMsg, $wParam )
  If $hWnd = $handleGUI Then
    If Not $wParam Then Return 1
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc

Func CreateInputTab2()
    ; Switch to the child GUI
    GUISwitch($Window1)
    ; Create controls
    GUICtrlCreateLabel("Input 2 :", 150, 150)
    GuiCtrlCreateInput("", 200, 150)
    ; Switch back
    GUISwitch($handleGUI)
EndFunc

Func CreateInputTab3()
    GUISwitch($Window)
    GUICtrlCreateLabel("Input 3 :", 150, 150)
    GuiCtrlCreateInput("", 200, 150)
    GUISwitch($handleGUI)
EndFunc
Edited by mpower
Link to comment
Share on other sites

Thank you guys so much! I didn't even realize I was losing focus on my main GUI.

To better understand Func WM_NCACTIVATE( $hWnd, $iMsg, $wParam ), I have read over the MSDN and still am a bit confused. From what I am understanding, windows sends a WM_NCACTIVATE message every time a window handle parameter is changed? I am having trouble seeing where all of the arguments are coming from.

Link to comment
Share on other sites

Sushi,

They way I understand is that the WM_NCACTIVATE message is sent any time the non-client area (i.e. title bar, title icon etc) needs to change state - to become active or not active (in simpler terms, to gain or lose focus). Usually this happens when you click a control in a client area or the client area itself. So by intercepting the message we can prevent the child GUI from becoming active even though we're clicking on the client area/controls within client area.

Hope this helps :)

Cheers!

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