i work with 3 more form. 2 form has no border. when i click a button a form is show. when i minimize main form the other form still show. but i want when i minimized main form all from will minimize what was open.

Dani AI

Generated

Good question, . What you are seeing is normal: when you show a second borderless form modelessly, Windows treats it as a separate top-level window. It will not minimize with your main form, and when you restore, it can appear behind. Two tweaks fix this cleanly: (1) make the secondary form an owned window of the main form so it always stays on top of it and hides when the owner is minimized, and (2) in the main form’s Resize event, minimize any other open forms. Owned windows are guaranteed to stay above their owner and are hidden when the owner is minimized. (learn.microsoft.com)

In VB6 you can set ownership with the Win32 API. Call this when you show the child form:

' In a BAS module
Option Explicit
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_HWNDPARENT As Long = -8

Public Sub ShowOwned(ByVal Owner As Form, ByVal Owned As Form)
    Owned.Show
    SetWindowLong Owned.hWnd, GWL_HWNDPARENT, Owner.hWnd   ' set owner of top-level window
End Sub
' In FrmMain
Private Sub cmdShowItem_Click()
    ShowOwned Me, FrmItem
End Sub

Private Sub Form_Resize()
    Dim f As Form
    If Me.WindowState = vbMinimized Then
        For Each f In Forms
            If f.hWnd <> Me.hWnd Then f.WindowState = vbMinimized
        Next
    End If
End Sub

This avoids the runtime error 5 you hit after trying SetFocus, , because you are not forcing focus to a minimized window. The ownership call uses GWL_HWNDPARENT specifically to assign an owner to a top-level window. (learn.microsoft.com)

For : if you truly want to minimize every window on the desktop (not just your app), you can automate the shell:

Dim sh As Object
Set sh = CreateObject("Shell.Application")
sh.MinimizeAll

That has the same effect as Show Desktop. (learn.microsoft.com)

Recommended Answers

All 9 Replies

Hi,
Form has WindowState Property.
The values may be
vbNormal - 0 - (Default) Normal.
vbMinimized - 1 - Minimized (minimized to an icon)
vbMaximized - 2 - Maximized (enlarged to maximum size)

But Form does not have any particular Event occur when minimize and maximize.

Resize() event can be useful
To do
> Check whether the form is already minimized or not
> Change the State to Minimized

Ex

Private Sub Form_Resize()
   If Form1.WindowState = vbMinimized Then
      OtherForm.WindowState = vbMinimized
   End If
   If Form1.WindowState = vbNormal Then
      OtherForm.WindowState = vbNormal
   End If
End Sub

but when it normal then form1 appear. I want otherForm will appear. Now it appear in the back of Form1.

Hello abu tahir
'if you want to minimize other forms but form1 cannot minimize so
'try this:
'if you will use 3 or 4 forms see it

Private Sub Command1_Click()
Form2.WindowState = 1
Form3.WindowState = 1
Form4.WindowState = 1
End Sub

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

End Sub

' if show your all forms then you press command botton your all forms are minmized

not like this. supoose.... in FrmMain I click a button show FrmItem (another form). It was show. When I minmize FrmMain it was minimized with FrmItem. When I maximized FrmMain FrmItem not show in front. It show In back of FrmMain. I want it will show on front of FrmMain.

if me.windowstate=0 then
form2.windowstate=-1
form3.windowstate=1
end if

sorry mustafa it not work as my requeirment.

set focus to the form

frmItem.setfocus

it show a error massage:
run time error 5
Invalid proceduer call or argument.

i work a program that uses two pc and then connect them..
how can i minimize all the windows that i open ?
Example: someone was Surfing on the net and then he want to stop the time . i click the button so that all windows will be minimize, and only desktop currently shown.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.