A Window List Right On The
Window Menu

When you select the WindowList option for a menu item on the Window menu of a MDI application you will get a sub menu with the list of open windows.  If you do not want this you can get a list right on the Window menu like in a professional application by following these steps.

Create a top level menu called mnuWindow with a caption of Window and the following sub menu items on the MDI parent form








Arrange Icons





For the menu choice titled mnuWindowList enter 0 in the Index: field to make it a menu array.

For the Click events of mnuWindowCascade, mnuWindowTile and mnuWindowArrange enter the standard VB commands for tiling, cascading and arranging windows.

For the Click event of mnuWindowList which should have Index As Integer for an argument enter

'define variables
Dim F As Form

'loop through all open forms
For Each F In Forms
    'check each form to see if it is the selected form
    If mnuWindowList(Index).Caption = F.Caption Then
    End If
Next F

This will make selecting one of the choices on the list give the focus to the form whose captions is on the picked choice.

Your Window menu’s choices will now respond appropriately to a user selections, but at run time you will find no Windows listed below the separator bar.  Further if your program does not open more than one child form at startup you will be able to make choices that have no meaning.

To solve these problems create the following subroutine in the MDI parent form

Sub SetMenuDefaults()
'define variables
Dim Counter As Integer

'intialize variables
Counter = 0

'set enabled property for menus and menu selections to allow for
‘functions that cannot be carried out at the current time
mnuWindowCascade.Enabled = False
mnuWindowTile.Enabled = False
mnuWindowArrange.Enabled = False
mnuWindowSeperator.Visible = False
Do Until Counter = mnuWindowList.Count
      mnuWindowList(Counter).Visible = False
      Counter = Counter + 1
End Sub

and add modWindowListFunctions.bas to your program.  After adding the bas the only edit you need to make to it is to change all occurrences of frmStartup to the name of your applications MDI parent form.

After that all that’s left is calls to the newly added code.  In the Load event for the MDI parent form enter

Call SetMenuDefaults

For all child forms enter Call ResetWindowList(Me, "add") in the Activate event and and Call ResetWindowList(Me, "remove") in the Deactivate event.

For all child forms enter Call WindowListAddItem(Me) in the Load event and

If UnloadMode = 0 Or UnloadMode = 1 Then
   Call WindowListRemoveItem(Me)
End If

in the QueryUnload event.

Lila Godel's Web Site
Brought To You By Hamilton Services, Inc.

Contact Me









Programs By Me


Visual Basic

Visual Basic