Solved

Child Window Order

Posted on 2000-04-27
6
194 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now