Code:
Private Sub Command1_Click()
Dim f As Form2
Set f = New Form2
'f.Show 1
ShowWindow f.hwnd, 5
WaitFormToClose f.hwnd
Debug.Print "Form Cloesed OK" & "," & Now
End Sub
Code:
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" ( _
lpMsg As Msg, _
ByVal hwnd As Long, _
ByVal wMsgFilterMin As Long, _
ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32" ( _
lpMsg As Msg) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" ( _
lpMsg As Msg) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hwnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Sub WaitFormToClose(ByVal FormHwnd As Long)
Dim mCount As Long
Dim wMsg As Msg
Do While Not GetMessage(wMsg, FormHwnd, 0&, 0&)
'GetMessage=1 it's right,-1 form is closed
Call TranslateMessage(wMsg)
Call DispatchMessage(wMsg)
mCount = mCount + 1
Loop
Debug.Print "Message Count=" & mCount
End Sub