Get and Set Z order for MDI forms in VB5

Get and Set Z order for MDI forms in VB5

Post by Gerd Thy » Fri, 08 Oct 1999 04:00:00



Dear all,

For my project I'm writing functions to save and arrange a default
workspace: The position of the forms in the program are stored (save
workspace) and restored (arrange workspace) on demand. What left, top, width
and height is concerned this is of course easy but I wonder if it's possible
to retrieve the Z order of the forms ... I tried Zorder but as far as I
understand this function only sets the order....

Thanks


 
 
 

Get and Set Z order for MDI forms in VB5

Post by Bill McCarth » Fri, 08 Oct 1999 04:00:00


You could probably use win api calls to get the first child window, then the
next child window etc


> Dear all,

> For my project I'm writing functions to save and arrange a default
> workspace: The position of the forms in the program are stored (save
> workspace) and restored (arrange workspace) on demand. What left, top,
width
> and height is concerned this is of course easy but I wonder if it's
possible
> to retrieve the Z order of the forms ... I tried Zorder but as far as I
> understand this function only sets the order....

> Thanks




 
 
 

Get and Set Z order for MDI forms in VB5

Post by Douglas Marquard » Fri, 08 Oct 1999 04:00:00


Hi Gerd:

Quote:>For my project I'm writing functions to save and arrange a default
>workspace: The position of the forms in the program are stored (save
>workspace) and restored (arrange workspace) on demand. What left, top,
width
>and height is concerned this is of course easy but I wonder if it's
possible
>to retrieve the Z order of the forms

Personally, I would only concern myself with knowing what form to *show*
when I load the workspace -- the form the was the ActiveForm would be that
one.  The rest of the forms should not really matter as long as they are
loaded and placed where they last were located, etc.

Doug.

 
 
 

Get and Set Z order for MDI forms in VB5

Post by Stephen Smit » Fri, 08 Oct 1999 04:00:00




> Dear all,
> For my project I'm writing functions to save and arrange a default
> workspace: The position of the forms in the program are stored (save
> workspace) and restored (arrange workspace) on demand. What left, top, width
> and height is concerned this is of course easy but I wonder if it's possible
> to retrieve the Z order of the forms ... I tried Zorder but as far as I
> understand this function only sets the order....
> Thanks


Hi Gerd,
I've done exactly this in my MDI app. Here's a snippet...
Steve.

NOTE: 'Windows' is my own collection of child forms, which contains
only savable windows; The MDI has other child forms which are not
savable; you could use the Forms collection instead, and simplify the code...

    ' sets NewZOrders() = an array of pointers to the Windows
collection, with Topmost first

    ' NOTES:
    ' This assumes that an MDIForm is present, and that 1+ savable
children are visible.
    ' A child is moved to the end of the Windows' win list when
hidden (if it remains loaded),
    '   hence invisible children appear at the end of the list, with
the most-recently-hidden at the end.

        ' extract hWnd of all wins in the collection (for speed
within the loop)
        ReDim WinHWnds(1 To WinCount)
        For i = 1 To WinCount
            WinHWnds(i) = Windows(i).hWnd
        Next

        ' set ChildHWnd = top-level MDI child
        ' (this assumes that MDI.ActiveForm exists)
        If TypeOf Forms(0) Is MDIForm Then
            ' (this is normally the case)
            ChildHWnd = Forms(0).ActiveForm.hWnd
        Else
            ' (unusual case - must search for the MDIForm)
            For Each FRM In Forms
                If TypeOf FRM Is MDIForm Then Exit For
            Next
            ChildHWnd = FRM.ActiveForm.hWnd
        End If

        ' find each Window in the collection, from the top down
        ' (the Windows win list will usually have these windows at
the top, and the Windows collection
        '   will normally be in the correct order, so this loop is
usually very quickly completed)
        ZOrderNum = 0
        WinMinIndex = 1
        WinMaxIndex = WinCount
        ReDim NewZOrders(1 To WinCount)
        Do While ChildHWnd <> 0 And ZOrderNum < WinCount

            ' if child is in the Windows collection, store the NewZOrders
            For i = WinMinIndex To WinMaxIndex
                If WinHWnds(i) = ChildHWnd Then
                    ZOrderNum = ZOrderNum + 1
                    NewZOrders(ZOrderNum) = i
                    If i = WinMinIndex Then WinMinIndex = i + 1 '
(speed up future inner loops)
                    If i = WinMaxIndex Then WinMaxIndex = i - 1
                    Exit For
                End If
            Next

            ChildHWnd = GetNextWindow(ChildHWnd, GW_HWNDNEXT)
        Loop
        If ZOrderNum < WinCount Then Stop ' (debug error: not all
wins in the collection have been found)
        Redim Preserve NewZOrders(1 To ZOrderNum)