Jump to content

Child Guis


Recommended Posts

Hello There

I am trying to make a multiple form program, but i have no idea that how can i take start,

this is my first attempt & i am facing 2 basic problems, please see the images

1: Focus Problem

http://img24.imageshack.us/img24/8113/prob1nl.jpg

2: Child windows Maximum State Problem

http://img199.imageshack.us/img199/5769/prob2k.jpg

http://img199.imageshack.us/img199/2553/prob21.jpg

http://img200.imageshack.us/img200/2255/prob22.jpg

Here is my code

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>
Global $hMian,$hChild[1],$tChild=1

$hMain = GUICreate("Parent Window", 633, 447, 192, 200)
GUICtrlCreateLabel("",0,0,0,0)
$mMain = GUICtrlCreateMenu("New")
$mChild = GUICtrlCreateMenuItem("Child", $mMain)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $mChild
            CreateChild()
    EndSwitch
WEnd

Func CreateChild()
    $Child = GUICreate("Child "&$tChild,300,300,10,0, BitOR($WS_CAPTION, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_POPUP, $WS_SYSMENU))
    GUISetState()
    _WinAPI_SetParent($Child,$hMain)
    Add($hChild,$Child)
EndFunc

Func Add(ByRef $Array,$V)
    If $Array[0] = "" Then
        $Array[0] = $V
    Else
        $p = UBound($Array)
        ReDim $Array[$p+1]
        $Array[$p] = $V
    EndIf
    $tChild +=1
EndFunc

Thanks in Advance

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

  • Moderators

Digisoul,

Do not be impatient - please only bump your posts after 24 hrs. :idea:

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually - like now! :(

1: Focus Problem. This question was asked here about a year ago and there was no solution. As far as I know Windows will only allow one window to have focus at any one time. I can only imagine that the application you show is a custom-built one which does not follow the normal Window API rules. :)

2: Child windows Maximum State Problem. Better news - some of this we can solve! :)

- (a) No move when maximized. We need to intercept the SC_MOVE command when the Child is maximized. Here is a rough proof-of-concept script:

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

Global $hMian, $hChild[1], $tChild = 1, $SC_MOVE = 0xF010, $fChild_Max = False

$hMain = GUICreate("Parent Window", 633, 447, 192, 200)
GUICtrlCreateLabel("", 0, 0, 0, 0)
$mMain = GUICtrlCreateMenu("New")
$mChild = GUICtrlCreateMenuItem("Child", $mMain)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hMain ; Main GUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $mChild
                    CreateChild()
            EndSwitch
        Case $hChild[0]
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild[0])
                Case $GUI_EVENT_MAXIMIZE
                    $fChild_Max = True
                Case $GUI_EVENT_RESTORE
                    $fChild_Max = False
            EndSwitch
    EndSwitch
WEnd

Func CreateChild()
    $Child = GUICreate("Child " & $tChild, 300, 300, 10, 0, BitOR($WS_CAPTION, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_POPUP, $WS_SYSMENU))
    GUISetState()
    _WinAPI_SetParent($Child, $hMain)
    Add($hChild, $Child)
EndFunc   ;==>CreateChild

Func Add(ByRef $Array, $V)
    If $Array[0] = "" Then
        $Array[0] = $V
    Else
        $p = UBound($Array)
        ReDim $Array[$p + 1]
        $Array[$p] = $V
    EndIf
    $tChild += 1
EndFunc   ;==>Add

Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)

    If $hWnd = $hChild[0] Then
        If $fChild_Max Then
            If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

You can see how we need to set a flag when the child is maximized, so that we can determine when SC_MOVE messages need to be blocked within the WM_SYSCOMMAND procedure. Obviously this would need to be a bit more complex if you wanted to have more than one child - you would need to do an _ArraySearch of $hChild both within the GUIGetMsg loop and the WM_SYSCOMMAND procedure - but that would not be too diffcult to code. :)

- Cover parent menu bar. Another clue that the app you show does not follow the normal rules. I recently posted a workaround which gave a hideable menu bar - you might be able to modify this to do what you want. :( Edit: see below!

I hope this gets you back on track. :)

M23

Edit: Here is a version with a menu which hides when you maximize the child:

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

Global $hMain, $hChild, $SC_MOVE = 0xF010, $fChild_Max = False

; Create main GUI
$hMain = GUICreate("Parent Window", 633, 447, 192, 200)
GUISetState(@SW_SHOW)

; Create Menu GUI
Global $hMenu_Win = GUICreate("", 633, 20, -1, -1, $WS_POPUP, $WS_EX_MDICHILD, $hMain)

; Create menu
Global $mFile_Menu = GUICtrlCreateMenu("&New")
Global $hChild_Menu_Item = GUICtrlCreateMenuItem("&Child", $mFile_Menu)
GUICtrlCreateMenuItem("", $mFile_Menu)
Global $hExit_Menu_Item = GUICtrlCreateMenuItem("&Exit", $mFile_Menu)
Global $mHelp_Menu = GUICtrlCreateMenu("&?")
Global $hAbout_Menu_Item = GUICtrlCreateMenuItem("&About", $mHelp_Menu)

; Move to correct position
Local $aWin_Pos = WinGetPos($hMain)
Local $iBorder = _WinAPI_GetSystemMetrics(8) ; Border width
Local $iBar = _WinAPI_GetSystemMetrics(4) ; Title bar height
WinMove($hMenu_Win, "", $aWin_Pos[0] + $iBorder, $aWin_Pos[1] + $iBorder + $iBar)

; Show menu
GUISetState(@SW_SHOW, $hMenu_Win)

GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hMain ; Main GUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $hMenu_Win
            _WinAPI_SetFocus($hMain)
            Switch $aMsg[0]
                Case $hExit_Menu_Item
                    Exit
                Case $hChild_Menu_Item
                    CreateChild()
                    GUICtrlSetState($hChild_Menu_Item, $GUI_DISABLE)
                Case $hAbout_Menu_Item
                    MsgBox(0, "Hello", "This is a better version of the script!")
            EndSwitch
        Case $hChild
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild)
                    GUICtrlSetState($hChild_Menu_Item, $GUI_ENABLE)
                Case $GUI_EVENT_MAXIMIZE
                    $fChild_Max = True
                    _Menu_State()
                Case $GUI_EVENT_RESTORE
                    $fChild_Max = False
                    _Menu_State()
            EndSwitch
    EndSwitch

WEnd

Func CreateChild()
    $hChild = GUICreate("Child", 300, 300, 10, 20, BitOR($WS_CAPTION, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_POPUP, $WS_SYSMENU))
    GUISetState()
    _WinAPI_SetParent($hChild, $hMain)
EndFunc   ;==>CreateChild

Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)

    If $hWnd = $hChild Then
        If $fChild_Max Then
            If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

Func _Menu_State()
    If $fChild_Max Then
        GUISetState(@SW_HIDE, $hMenu_Win)
    Else
        GUISetState(@SW_SHOW, $hMenu_Win)
    EndIf
EndFunc
Edited by Melba23

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