Minimize and Restore windows

Edit: There has been a lot of views but no response. I think the way I wrote this could have been confusing so I am trying again.

Working on Windows 7.
The platform I am using is Windows 7.
I cannot get all the windows of my program to minimize and restore properly. What am I doing wrong?

I would like my program to minimize all open windows when I click the minimize button on the main window and restore all windows when the main program is double clicked in the task bar. When I close the program, all windows are closed using the following in the close event of the main window:

This works to close all windows.
Sub Close()
For i as Integer = WindowCount - 1 DownTo 0
Dim w as Window = Window(i)
If w <> nil then
w.Close
End if
Next
End Sub

I assumed that doing similar in the minimize and restore events of the main window would work like I wanted, but it does not. Doing these will minimize and restore most of the windows, but not all. It leaves a window or two hanging around on minimize and doesn’t restore all windows.

But these do not work to minimize and restore windows.
Sub Minimize()
For i as Integer = WindowCount-1 DownTo 0
Dim w as Window = Window(i)
If w <> nil then
w.Minimize
End if
Next
End Sub

Sub Restore()
For i as Integer = WindowCount-1 DownTo 0
Dim w as Window = Window(i)
If w <> nil then
w.Restore
End if
Next
End Sub

How do I minimize and restore all windows from the main program window?

I edited this because I realized that the first line “Working on Windows 7” may have been interpreted as I got the code working on Windows 7 rather than the platform I am using is Windows 7. It may have also been unclear what the question was since the question appeared as the last line of the original post.

Do all your windows have minimize buttons? I don’t think a window will minimize without one. Instead of minimizing, what if you hide the other windows?

for i = 0 to windowcount-1
   if window(i) <> me then window(i).hide
next