Jump to content

Child GUI Examples


Skysnake
 Share

Recommended Posts

ShowChildGuis.png.93a1a9bc8b2b78cef80cae05ee398940.pngI don't often have occasion to use Child GUIs.  I find the multitude of options confusing.

The example below I made for my own purposes, to have a visual guide to what the various Style and Extended Style options lead to.

Comments are much appreciated.  This can be extended with many more examples and comments and why certain Styles are to preferred or avoided.  Where certain types of Child GUIs are most suitable etc.

 

The code is very basic.  It is intended to show GUI Styles, not much else.

;~ ********************************************************************
;~  Author: Skysnake
;~
;~  Title:  Demo various Child Gui options
;~  Updated: 2019.01.03
;~
;~  Function:   A demo script, demonstrates various style & Extended
;~              style options for Child GUIs
;~  Comments, ideas and suggestions very welcome :)
;~
;~ ********************************************************************
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>

ShowChildGuis()

Func ShowChildGuis()

    Local $guiParent = GUICreate("The Parent GUI", 1200, 700, 0, 0) ;WHLT

    $idFilemenu = GUICtrlCreateMenu(" &Menu")

    $ButtonCancel = GUICtrlCreateButton("&Close", 0, 0, 80, 25)
    GUICtrlSetTip($ButtonCancel, "Click to close all")

    $ButtonShowChildGui = GUICtrlCreateButton("&Show", 0, 25, 80, 25)
    GUICtrlSetTip($ButtonShowChildGui, "Click to show a child GUI")

;~  #comments-start --- Toggle this and same code below to show context menu for parent or child
    Local $idContextmenu = GUICtrlCreateContextMenu()

    Local $idNewsubmenu = GUICtrlCreateMenu("This is a Context Menu", $idContextmenu)
    Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)

    Local $idContextButton = GUICtrlCreateButton("Context", 0, 50, 80, 25)
    GUICtrlSetTip($idContextButton, "Right Click to see Context Menu")
    Local $idButtoncontext = GUICtrlCreateContextMenu($idContextButton)
    Local $idMenuAbout = GUICtrlCreateMenuItem("This is a Context Menu", $idButtoncontext)

    Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
    Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
    GUICtrlCreateMenuItem("", $idContextmenu) ; separator

    Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
;~  #comments-end   --- Toggle this and same code below to show context menu for parent or child



    Local $DefaultChildGui = GUICreate("Default child gui", 300, 100, 300, 300, Default, Default, $guiParent) ;;;WHLT
    GUICtrlCreateLabel("Default attributes" & @CRLF & "Cannot move; cannot resize", 0, 0, 500, 200)
    GUICtrlSetBkColor(-1, $COLOR_aqua)

    $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($DefaultChildGui), $GWL_STYLE)
    $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($DefaultChildGui), $GWL_EXSTYLE)
    GUISetStyle(BitOR($iStyle, $WS_VISIBLE), $iExStyle, $DefaultChildGui)



    Local $gChildGuiwithMenu = GUICreate("A child gui with menu", 300, 100, 50, 100, $WS_VISIBLE, BitOR($WS_EX_WINDOWEDGE, $WS_EX_MDICHILD, $WS_THICKFRAME), $guiParent) ;;;WHLT
    GUICtrlCreateLabel("Menu" & @CRLF & "Can move; cannot resize", 0, 0, 500, 200)
    GUICtrlSetBkColor(-1, $COLOR_skyblue)

    $idFilemenu = GUICtrlCreateMenu(" &File ")
    Local $idFileMenuItem = GUICtrlCreateMenuItem("An item for the File menu ", $idFilemenu)
    GUICtrlCreateMenuItem("", $idFilemenu) ; create a separator line

    ; use same dimensions for GUI and its Label
    Local $iSizeWide = 300, $iSizeHi = 100
    GUICreate("A child gui", $iSizeWide, $iSizeHi, 100, 200, $WS_VISIBLE, BitOR($WS_EX_WINDOWEDGE, $WS_EX_TOPMOST, $WS_EX_MDICHILD, $WS_THICKFRAME), $guiParent) ;;;WHLT
    GUICtrlCreateLabel("Can move; cannot resize" & @CRLF & "Always on top", 0, 0, $iSizeWide, $iSizeHi)
    GUICtrlSetBkColor(-1, $COLOR_red)


    GUICreate("Child Gui Resizable", 300, 100, 200, 50, BitOR($WS_POPUP, $WS_SIZEBOX, $WS_CLIPCHILDREN, $WS_VISIBLE), $WS_EX_MDICHILD, $guiParent) ;;;WHLT
    GUICtrlCreateLabel("Popup Cannot move; can resize" & @CRLF & "Background", 0, 0, 500, 200) ; $WS_CHILD,
    GUICtrlSetBkColor(-1, $COLOR_blue)
    ; toggle the line below :)
    ;$idBackgroundmenu = GUICtrlCreateMenu(" &Menu ") ; give it a menu

    GUICreate("Child GUI, caption, resize", 300, 100, 300, 100, BitOR($WS_VISIBLE, $WS_POPUP, $WS_CAPTION), BitOR($WS_EX_TOOLWINDOW, $WS_EX_MDICHILD, $WS_EX_ACCEPTFILES), $guiParent)
    GUICtrlCreateLabel("Popup With Caption: Can move; cannot resize", 0, 0, 500, 200)
    GUICtrlSetBkColor(-1, $COLOR_yellow)

    GUICreate("Child GUI, abc", 300, 100, 400, 150, BitOR($WS_POPUP, $WS_VISIBLE, 0), $WS_EX_MDICHILD, $guiParent)
    GUICtrlCreateLabel("Popup Cannot move; cannot resize", 0, 0, 500, 200)
    GUICtrlSetBkColor(-1, $COLOR_green)


    ; Child GUI below has a control ............................. .............................................
    Local $gChildWithControls = GUICreate("Child GUI with Buttons", 400, 400, 500, 200, BitOR($WS_CAPTION, $WS_CHILD), -1, $guiParent)
    GUISetFont(14, $gChildWithControls)
    Local $cLabel = GUICtrlCreateLabel("Can move; cannot resize", 0, 0, 400, 50)
    GUICtrlSetBkColor($cLabel, $COLOR_white)

    Local $idChild_ButtonOkay = GUICtrlCreateButton("Okay", 0, 50, 80, 30)
    Local $idChild_ButtonHide = GUICtrlCreateButton("Hide", 0, 80, 80, 30)
    GUICtrlSetTip($idChild_ButtonHide, "Click to hide this child GUI")

;~  #comments-start --- Toggle this and same code below to show context menu for parent or child
;~  Local $idContextmenu = GUICtrlCreateContextMenu()

;~  Local $idNewsubmenu = GUICtrlCreateMenu("This is a Context Menu", $idContextmenu)
;~  Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)

;~  Local $idContextButton = GUICtrlCreateButton("Context", 0, 110, 80, 30)
;~  GUICtrlSetTip($idContextButton, "Right Click to see Context Menu")
;~  Local $idButtoncontext = GUICtrlCreateContextMenu($idContextButton)
;~  Local $idMenuAbout = GUICtrlCreateMenuItem("This is a Context Menu", $idButtoncontext)

;~  Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
;~  Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
;~  GUICtrlCreateMenuItem("", $idContextmenu) ; separator

;~  Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)

;~  #comments-end   --- Toggle this and same code below to show context menu for parent or child

    GUISetState(@SW_HIDE, $gChildWithControls)
    ;..........................................................................................................



    Local $gToolbar = GUICreate("A floating Tool Window", 300, 50, 100, 25, $WS_VISIBLE, $WS_EX_TOOLWINDOW, $guiParent)
    GUICtrlCreateLabel("A floating toolbar", 0, 0, 500, 200) ; this does not show :)
    GUICtrlSetBkColor(-1, $COLOR_lime)

;~  $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($gToolbar), $GWL_STYLE)
;~  $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($gToolbar), $GWL_EXSTYLE) ; BitOR($WS_EX_TOOLWINDOW, $WS_EX_MDICHILD)
;~  GUISetStyle(BitOR($iStyle, $WS_VISIBLE), $iExStyle, $gToolbar)

    $idToolmenu = GUICtrlCreateMenu(" &Tool ")
    Local $idToolMenuItem = GUICtrlCreateMenuItem("An item for the Tool menu ", $idToolmenu)
    Local $idToolMenuItemsecond = GUICtrlCreateMenuItem("A second item for the Tool menu ", $idToolmenu)
    GUICtrlCreateMenuItem("", $idToolmenu) ; create a separator line

    $idPrintmenu = GUICtrlCreateMenu(" &Print ")
    Local $idToolMenuItemPrint = GUICtrlCreateMenuItem("A Print item for the Toolbar print menu ", $idPrintmenu)
    GUICtrlCreateMenuItem("", $idPrintmenu) ; create a separator line


    #Region --- After GUI BEFORE loop starts
    GUISetState(@SW_SHOW, $guiParent)
    #EndRegion --- After GUI BEFORE loop starts


    While 1
        ;Local $nMsg = GUIGetMsg()
        Switch GUIGetMsg() ; $nMsg
            Case $GUI_EVENT_CLOSE, $ButtonCancel
                GUIDelete($guiParent)
                ExitLoop
            Case $idContextButton
                MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'Right Click to see the Contect Menu')
            Case $ButtonShowChildGui
                GUISetState(@SW_ENABLE, $gChildWithControls)
                GUISetState(@SW_SHOW, $gChildWithControls)
            Case $idChild_ButtonHide ; <<<<<<<<<<<<<<< Child Gui Control Actioned in  main loop
                ConsoleWrite("Yup, you clicked it" & @CRLF)
                GUISetState(@SW_HIDE, $gChildWithControls)
            Case $idChild_ButtonOkay ; <<<<<<<<<<<<<<< Child Gui Control Actioned in  main loop
                ConsoleWrite("Yup, you clicked it" & @CRLF)
                MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'Okay')
        EndSwitch
    WEnd
    GUIDelete()

EndFunc   ;==>ShowChildGuis

 

 

Edited by Skysnake
Improved examples

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

I hope you don't mind my asking, but I have a question regarding your use of "&text".

I've never looked into how individual characters are underlined ... in menus, for example.  But after some searching, I found a rather obscure parameter in the help file for _WinAPI_DrawText:  "$DT_PREFIXONLY - Draws only an underline at the position of the character following the ampersand (&) prefix character."

Is the underline effect what you intended? If so, is there a simpler case for "&" use that I'm missing?

I'm asking because there are no underlined characters in your posted example or in my testing. Plus, removing the &'s doesn't seem to change anything.

 

Link to comment
Share on other sites

@qwert, thx for the comment.

The & makes it possible to access the menu items using the keyboard. Click the Toolbar and press ALT+T or ALT+P on the keyboard.  This allows you to access the menu items using the keyboard.  It works as is.  I see no reason to remove this.

As for your help file reference, I do not know what that does.  Perhaps it only draws the line without making the keyboard shortcut available? 

:)

 

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

2 hours ago, Skysnake said:

The & makes it possible to access the menu items using the keyboard.

Thanks for your reply. I now see that _GUICtrlMenu_InsertMenuItem in the help file has plenty of examples of use ... but, strangely, no mention of exactly what & denotes. Oh, well. Now I know.

Link to comment
Share on other sites

  • 4 months later...

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

×
×
  • Create New...