Hi all:
when we resize the MDI parent form, we want to resize the MDI child form also, but how can we know which child form is visible at that time?
Thanks
Printable View
Hi all:
when we resize the MDI parent form, we want to resize the MDI child form also, but how can we know which child form is visible at that time?
Thanks
You probably have to loop thru all of the child MDIs and see if the .visible property is true.
If ChildForm1.Visible=True Then MsgBox "this child window is visible"
Or something to that effect.
-lp
I like complicated APIs sometimes, for they are cleaner in the job:).
:) APICode:'NOTE: Option Compare Text is not needed, but since I thought it was lonely, I brought it up.
Option Explicit
Option Compare Text
Option Base 1
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" _
(ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Sub MDIForm_Click()
Dim strs() As String, vis() As Boolean, hwd() As Long
Dim hwndw As Long, lt As Long, hwdold As Long
Dim ctc As Long
ReDim strs(ctc) As String
ReDim vis(ctc) As Boolean
ReDim hwd(ctc) As Long
hwdold = vbNull
SupP:
hwndw = FindWindowEx(Me.hwnd, hwdold, vbNull, vbNull)
If hwndw = vbNull Then GoTo SubP
lt = GetWindowTextLength(hwndw)
ctc = ctc + 1
ReDim strs(ctc) As String
ReDim vis(ctc) As Boolean
ReDim hwd(ctc) As Long
GetWindowText Me.hwnd, strs(ctc), ln
vis(ctc) = IsWindowVisible(hwndw)
hwd(ctc) = hwndw
hwdold = hwndw
GoTo SupP
SubP:
End Sub
You could also use the Forms collection to do the resize.
Add code simular to this in the Resize event of the MDI form.
Best regardsCode:Private Sub MDIForm_Resize()
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name Then
If frm.MDIChild = True Then
'do the resizing here
frm.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End If
End If
Next
End Sub