Jump to content

Metrogui_udf child window inheritance questions


i2i8
 Share

Recommended Posts

Opt("GUIOnEventMode", 1)
#include "sUDF\MetroGUI_UDF.au3"
#include "sUDF\_GUIDisable.au3"
#include <Array.au3>

_Metro_EnableHighDPIScaling()
_SetTheme("DarkMidnightBlue")

WndMain()

While 1
    Sleep(5)
WEnd

;#FUNCTION# ==================================================================================================================================
Func WndMain()
    
    Global $wMain               = 1280
    Global $hMain               = 768
    Global $hWndMain            = _Metro_CreateGUI("Main", $wMain, $hMain, -1, -1, True)
    Global $aWinGetPos_Main     = WinGetPos($hWndMain)
    GUISetState()
    ChildForm()
    Global $WndMain_Control = _Metro_AddControlButtons(True, False, True, False, True)

    Global $GUI_CLOSE_BUTTON        = $WndMain_Control[0]
    Global $GUI_MAXIMIZE_BUTTON     = $WndMain_Control[1]
    Global $GUI_RESTORE_BUTTON      = $WndMain_Control[2]
    Global $GUI_MINIMIZE_BUTTON     = $WndMain_Control[3]
    Global $GUI_FULLSCREEN_BUTTON   = $WndMain_Control[4]
    Global $GUI_FSRestore_BUTTON    = $WndMain_Control[5]
    Global $GUI_MENU_BUTTON         = $WndMain_Control[6]

    GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIEvent_WndMain")
    GUICtrlSetOnEvent($GUI_CLOSE_BUTTON, "_GUIEvent_WndMain")
    GUICtrlSetOnEvent($GUI_MAXIMIZE_BUTTON, "_GUIEvent_WndMain")
    GUICtrlSetOnEvent($GUI_MINIMIZE_BUTTON, "_GUIEvent_WndMain")
    GUICtrlSetOnEvent($GUI_RESTORE_BUTTON, "_GUIEvent_WndMain")
    GUICtrlSetOnEvent($GUI_MENU_BUTTON, "_GUIEvent_WndMain")

EndFunc     ;==>MainForm

Func ChildForm()
    _ArrayDisplay($aWinGetPos_Main, "")
    ;error: aWinGetPos_Main(): undefined function.
    ;Global $hChildForm = GUICreate("",  $aWinGetPos_Main[2], $aWinGetPos_Main[3], aWinGetPos_Main[0], aWinGetPos_Main[1], $WS_POPUP, $WS_EX_MDICHILD, $hWndMain)
    Global $hChildForm  = GUICreate("",  800, 600, 100, 50, $WS_POPUP, $WS_EX_MDICHILD, $hWndMain)
    GUISetState()

EndFunc     ;==>ChildForm


Func _GUIEvent_WndMain()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON
            _Metro_GUIDelete($hWndMain) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
            Exit
        Case $GUI_MAXIMIZE_BUTTON
            GUISetState(@SW_MAXIMIZE, $hWndMain)
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE, $hWndMain)
        Case $GUI_RESTORE_BUTTON
            GUISetState(@SW_RESTORE, $hWndMain)
        Case $GUI_MENU_BUTTON
            ;Create an Array containing menu button names
            Local $MenuButtonsArray[5] = ["General", "Settings", "About", "Contact", "Exit"]
            ; Open the metro Menu. See decleration of $MenuButtonsArray above.
            Local $MenuSelect = _Metro_MenuStart($hWndMain, 150, $MenuButtonsArray)
            Switch $MenuSelect ;Above function returns the index number of the selected button from the provided buttons array.
                Case "0"
                    ChildForm()
                Case "1"
                    ConsoleWrite("Returned 1 = Settings button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = About button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Contact button clicked." & @CRLF)
                Case "4"
                    ConsoleWrite("Returned 4 = Exit button clicked." & @CRLF)
                    _Metro_GUIDelete($hWndMain)
                    Exit
            EndSwitch
    EndSwitch
EndFunc     ;==>_GUIEvent_WndMain

As shown in the above code, I want to use separate Menu bars for childForm and mainForm respectively. In the current situation, the Menu bar for mainForm (Menu, Minimize, Close, etc.) has been moved to childForm. Please help me. Thank you very much...

The effect of the above code implementation is as follows:

1.jpg.25bb93e5a6f5e16bc853bcc37ceb753e.jpg

The effect I want to achieve is as follows:

2.jpg.267943bf7f97b874ab6a8297cba881ed.jpg

PS:

MetroGUI UDF v5.1

Edited by i2i8
Link to comment
Share on other sites

Concerning the error, a couple of $ are missing (line below intentionally pasted to bold both $ signs)

Global $hChildForm  = GUICreate("",  $aWinGetPos_Main[2], $aWinGetPos_Main[3], $aWinGetPos_Main[0], $aWinGetPos_Main[1], $WS_POPUP, $WS_EX_MDICHILD, $hWndMain)

Edited by pixelsearch
Link to comment
Share on other sites

On 2/20/2021 at 4:52 AM, i2i8 said:

In the current situation, the Menu bar for mainForm (Menu, Minimize, Close, etc.) has been moved to childForm. Please help me. Thank you very much...

Just move your ChildForm() line at the very end of Func WndMain()
Because the way it is placed now, all buttons are created in the child form, not in the main GUI !

After that, it should be easy for you to add a close button in the child form (as you already did in the main GUI). Also the example found in the zip file contains a function to create a 2nd GUI

Good luck

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