Jump to content
Sign in to follow this  
LurchMan

Child Window Question

Recommended Posts

LurchMan

Hello Everyone -

I'm trying to figure out a way so that I can have a parent GUI with a child GUI that cannot go outside the bounds of the parent GUI weather it be maximized or not. I have attempted to do this with quite a bit of math and AdlibRegister but I feel as though there is a better way to accomplish this.

Any help would be appreciated. Thank you for your time.


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
Melba23

LurchMan,

Like this perhaps? :)

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

Global $ahChild[1][2] = [[0, False]], $SC_MOVE = 0xF010

$hGUI = 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 $hGUI ; Main GUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $mChild
                    $hChild = _CreateMDIChild($hGUI)
            EndSwitch
        Case Else
            $hChild = _CheckMDIChildren($aMsg)
    EndSwitch
WEnd

Func _CreateMDIChild($hParent)
    ; Create child
    Local $hChild = GUICreate("Child " & $ahChild[0][0] + 1, 300, 300, 10, 0, BitOR($GUI_SS_DEFAULT_GUI , $WS_MAXIMIZEBOX, $WS_SIZEBOX))
    ; Set parent
    _WinAPI_SetParent($hChild, $hParent)
    ; Increase counter
    $ahChild[0][0] += 1
    ; Increase array size
    ReDim $ahChild[$ahChild[0][0] + 1][2]
    ; Set values
    $ahChild[$ahChild[0][0]][0] = $hChild
    $ahChild[$ahChild[0][0]][1] = False
    ; Show child
    GUISetState()
    Return $hChild
EndFunc   ;==>CreateChild

Func _CheckMDIChildren($aMsg)

    Local $fRet = False

    For $i = 1 To $ahChild[0][0]
        If $aMsg[1] = $ahChild[$i][0] Then
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($ahChild[$i][0])
                    $ahChild[$i][1] = False
                Case $GUI_EVENT_MAXIMIZE
                    $ahChild[$i][1] = True
                    $ahChild[0][1] = True
                Case $GUI_EVENT_RESTORE
                    $ahChild[$i][1] = False
                    $ahChild[0][1] = False
            EndSwitch
            $fRet = True
        EndIf
    Next
    Return $fRet
EndFunc

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

    If $ahChild[0][1] = True Then
        For $i = 1 To $ahChild[0][0]
            If $ahChild[$i][1] Then
                If $hWnd = $ahChild[$i][0] Then
                    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
                    ExitLoop
                EndIf
            EndIf
        Next
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>On_WM_SYSCOMMAND

M23

Edited by Melba23
Amended code slightly - see below!

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
LurchMan

Absolutely perfect Melba, Thank you!


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
Melba23

LurchMan,

Just a little something I had laying around. :whistle:

Glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

AdmiralAlkex,

Open and maximize a child window and then try to move the child with the mouse. If the GUIRegisterMsg code is running, you cannot - without it, you can. ;)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
LurchMan

I've been fiddling with this for a little while now and I was wondering if I am going to have to build a huge select case statement for each child window or if I can use GuiCtrlOnEvent for each menu item and how I would accomplish this. I apologize for not having any example code but I couldn't get it to work.


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
Melba23

LurchMan,

Do you mean you want it to work in OnEvent mode?

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

Opt("GUIOnEventMode", 1)

Global $ahChild[1][2] = [[0, False]], $SC_MOVE = 0xF010

Global $hGUI = GUICreate("Parent Window", 633, 447, 192, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlCreateLabel("", 0, 0, 0, 0)
$mMain = GUICtrlCreateMenu("New")
$mChild = GUICtrlCreateMenuItem("Child", $mMain)
GUICtrlSetOnEvent(-1, "_CreateMDIChild")
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")

While 1
    Sleep(10)
WEnd

Func _CreateMDIChild()
    ; Create child
    Local $hChild = GUICreate("Child " & $ahChild[0][0] + 1, 300, 300, 10, 0, BitOR($GUI_SS_DEFAULT_GUI , $WS_MAXIMIZEBOX, $WS_SIZEBOX))
    GUISetOnEvent($GUI_EVENT_CLOSE,    "_CheckMDIChildren_Close")
    GUISetOnEvent($GUI_EVENT_MAXIMIZE,    "_CheckMDIChildren_Maximize")
    GUISetOnEvent($GUI_EVENT_RESTORE,    "_CheckMDIChildren_Restore")
    ; Set parent
    _WinAPI_SetParent($hChild, $hGUI)
    ; Increase counter
    $ahChild[0][0] += 1
    ; Increase array size
    ReDim $ahChild[$ahChild[0][0] + 1][2]
    ; Set values
    $ahChild[$ahChild[0][0]][0] = $hChild
    $ahChild[$ahChild[0][0]][1] = False
    ; Show child
    GUISetState()
EndFunc   ;==>CreateChild

Func _CheckMDIChildren_Close()
    For $i = 1 To $ahChild[0][0]
        If @GUI_WINHANDLE = $ahChild[$i][0] Then
            GUIDelete($ahChild[$i][0])
            $ahChild[$i][1] = False
            ExitLoop
        EndIf
    Next
EndFunc

Func _CheckMDIChildren_Maximize()
    For $i = 1 To $ahChild[0][0]
        If @GUI_WINHANDLE = $ahChild[$i][0] Then
            $ahChild[$i][1] = True
            $ahChild[0][1] = True
            ExitLoop
        EndIf
    Next
EndFunc

Func _CheckMDIChildren_Restore()
    For $i = 1 To $ahChild[0][0]
        If @GUI_WINHANDLE = $ahChild[$i][0] Then
            $ahChild[$i][1] = False
            $ahChild[0][1] = False
            ExitLoop
        EndIf
    Next
EndFunc

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

    If $ahChild[0][1] = True Then
        For $i = 1 To $ahChild[0][0]
            If $ahChild[$i][1] Then
                If $hWnd = $ahChild[$i][0] Then
                    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
                    ExitLoop
                EndIf
            EndIf
        Next
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>On_WM_SYSCOMMAND

Func _Exit()
    Exit
EndFunc

Every time I code in OnEvent mode I reinforce how much I hate it. ;)

M23

Edited by Melba23
And again!

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
LurchMan

LurchMan,

Do you mean you want it to work in OnEvent mode?

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

Opt("GUIOnEventMode", 1)

Global $ahChild[1][2] = [[0, False]], $SC_MOVE = 0xF010

Global $hGUI = GUICreate("Parent Window", 633, 447, 192, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlCreateLabel("", 0, 0, 0, 0)
$mMain = GUICtrlCreateMenu("New")
$mChild = GUICtrlCreateMenuItem("Child", $mMain)
GUICtrlSetOnEvent(-1, "_CreateMDIChild")
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")

While 1
Sleep(10)
WEnd

Func _CreateMDIChild()
; Create child
Local $hChild = GUICreate("Child " & $ahChild[0][0] + 1, 300, 300, 10, 0, BitOR($GUI_SS_DEFAULT_GUI , $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetOnEvent($GUI_EVENT_CLOSE, "_CheckMDIChildren_Close")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_CheckMDIChildren_Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "_CheckMDIChildren_Restore")
; Set parent
_WinAPI_SetParent($hChild, $hGUI)
; Increase counter
$ahChild[0][0] += 1
; Increase array size
ReDim $ahChild[$ahChild[0][0] + 1][2]
; Set values
$ahChild[$ahChild[0][0]][0] = $hChild
$ahChild[$ahChild[0][1]][1] = False
; Show child
GUISetState()
EndFunc ;==>CreateChild

Func _CheckMDIChildren_Close()
For $i = 1 To $ahChild[0][0]
If @GUI_WINHANDLE = $ahChild[$i][0] Then
GUIDelete($ahChild[$i][0])
$ahChild[$i][1] = False
ExitLoop
EndIf
Next
EndFunc

Func _CheckMDIChildren_Maximize()
For $i = 1 To $ahChild[0][0]
If @GUI_WINHANDLE = $ahChild[$i][0] Then
$ahChild[$i][1] = True
$ahChild[0][1] = True
ExitLoop
EndIf
Next
EndFunc

Func _CheckMDIChildren_Restore()
For $i = 1 To $ahChild[0][0]
If @GUI_WINHANDLE = $ahChild[$i][0] Then
$ahChild[$i][1] = False
$ahChild[0][1] = False
ExitLoop
EndIf
Next
EndFunc

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

If $ahChild[0][1] = True Then
For $i = 1 To $ahChild[0][0]
If $ahChild[$i][1] Then
If $hWnd = $ahChild[$i][0] Then
If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
ExitLoop
EndIf
EndIf
Next
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>On_WM_SYSCOMMAND

Func _Exit()
Exit
EndFunc

Every time I code in OnEvent mode I reinforce how much I hate it. ;)

M23

Yes, exactly. Thank you M23!

Is there an advantage to not using OnEvent Mode?


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
Melba23

LurchMan,

Both modes have place, but personally I find the inability to pass parameters to functions in OnEvent very restrictive - although martin wrote a UDF to get round this some time ago. I also find it very annoying to have to write so many small functions to do simple things - like exiting the script. :(

However, I tend to use TrayOnEventMode whenever I have a tray menu as I normally do not need parameters for those functions and it allows me to action the event immediately. :)

Each to their own I suppose - although if you read the Interrupting a running function tutorial in the Wiki you will see one case where OnEvent mode is very useful - the third example is the one. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
LurchMan

@M23

I think I found an issue with your array within this, unless I'm not thinking about it correctly which is very possible, but wouldn't this be correct:

; Set values
$ahChild[$ahChild[0][0]][0] = $hChild
$ahChild[$ahChild[0][0]][1] = False

Rather than:

; Set values
$ahChild[$ahChild[0][0]][0] = $hChild
$ahChild[$ahChild[0][1]][1] = False
Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
Melba23

LurchMan,

Oops! Quite right - sorry about that. :>

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
LurchMan

Not a problem. Just want to make sure I wasn't going crazy :)


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
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
Sign in to follow this  

×