Solved

Child Window Order

Posted on 2000-04-27
6
199 Views
Last Modified: 2008-03-06
I can save and restore child window size, position and state OK but how can I save the order of the windows? In other words how can I know that window B is on top of window A and window C is on the bottom?
0
Comment
Question by:Neal Hartman
  • 2
  • 2
  • 2
6 Comments
 

Expert Comment

by:scibberme
ID: 2756306
I believe that the windows are layered on top of each other one in the order that they are loaded. You could store the place that the window was loaded, such as 1st, 2nd etc.
0
 
LVL 1

Author Comment

by:Neal Hartman
ID: 2756374
I need to store the position when the app is ended.
0
 

Accepted Solution

by:
scibberme earned 50 total points
ID: 2756704
In that case, you would probably want to add code that would update the values the forms got as the get focus and are shuffled around. Giving focus to a form moves it to the top layer. You could treat this like it was freshly opened and give it the next highest value. When your program ends, take all of these values and store them with the rest of the window's attributes.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Neal Hartman
ID: 2757005
I guess thats on way to do it. I thought there would be an API or something I could do with zorder.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2757044
Here is another way to do it.  In the QueryUnload event, look for the ActiveForm (the one with ZOrder 0).  Then unload that form, which will bring the next window into focus. Keep looping until all forms have been unloaded.

Option Explicit

Private Sub MDIForm_Load()
    Form1.Show
    Form2.Show
    Form3.Show
End Sub

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Dim frm As Form
    Dim i As Long
    'Search the forms collection for the ActiveForm
    For i = 0 To Forms.Count - 1
        Set frm = Me.ActiveForm
        If Not frm Is Nothing Then
            'This is the current top form
            Debug.Print frm.Name
            Unload frm
            Set frm = Nothing
        End If
    Next
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2757111
If your app is not MDI, you can use this:

Option Explicit

Private Sub Form_Load()
    Form2.Show
    Form3.Show
End Sub

'Your Startup (main) form code
Private Sub Form_Unload(Cancel As Integer)
    Dim frm As Form
    Dim i As Long
    'Search the forms collection for the ActiveForm
    For i = 0 To Forms.Count - 1
        Set frm = Screen.ActiveForm
        If Not frm Is Nothing Then
            Debug.Print frm.Name
            frm.Visible = False
        End If
    Next
    'Unload all forms
    For Each frm In Forms
        If Not frm Is Me Then
            Unload frm
            Set frm = Nothing
        End If
    Next
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question