StrataFrame Forum

How to hide child forms when main form minimizes

http://forum.strataframe.net/Topic12900.aspx

By Marcel Heitlager - 12/4/2007

Hi guys,

Can't figure this one out.  I'm running a vfp app in .net app using DartSock.  The VFP forms show in the desktop (but not in toolbar) instead of the .net MDI form, so I can show them in seperate monitors if I need to.

The only problem is (and I noticed this too when I use only .net forms), when I minimize the parent form, the children don't minimize along with it.

How could I override the wndProc sub of the .net form, so I can capture the minimize/maximize button click on the main form?  I can't figure out which value in m tells me the form has minimized. I know that once I can capture that, I can hadle the child forms through API calls.

Thanks.

Marcel

By Marcel Heitlager - 12/4/2007

Hey guess what?  I think I figured it out after laying off it for a while and going back to it. BigGrin  Any added suggestions? I haven't tried giving focus back to the form that had focus before minimizing.

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)[code]

Dim lsValue As String = ""
Dim lnValue As Integer

Const WM_SIZE As Integer = &H5
Const SIZE_MINIMIZED As Integer = 1
Const SIZE_MAXIMIZED As Integer = 2
Const SW_RESTORE As Integer = 9
Const SW_HIDE As Integer = 0

Select Case m.Msg

    Case WM_SIZE

        If m.WParam.ToInt32 = SIZE_MAXIMIZED Then
             If Me._OpenedWindows.Count > 0 Then
                    For Each lsValue In Me._OpenedWindows.Values
                           lnValue =
CInt(lsValue)
                           ShowWindow(lnValue, SW_RESTORE)
                   
Next
             
End If
        
ElseIf m.WParam.ToInt32 = SIZE_MINIMIZED Then
            
If Me._OpenedWindows.Count > 0 Then
                    
For Each lsValue In Me._OpenedWindows.Values
                            
lnValue = CInt(lsValue)
                            ShowWindow(lnValue, SW_HIDE)
                     
Next
            
End If
       
End If
End Select

MyBase.WndProc(m)

End Sub

By StrataFrame Team - 12/6/2007

No, looks pretty good to me.  However, the only thing you might want to change is the location of the MyBase.WndProc() call... if you ever want to override what the window is doing for the WndProc, then you don't want to call MyBase.  So, if you don't want the window to process the maximize call, then don't call WndProc. 

It's not necessarily wrong, just something to think about in the future if you ever don't want to process the base class code, and in this case, I think you did it right.