Option Explicit
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetTopWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDFIRST = 0
Private Const WM_CLOSE = &H10
Private mlHwnd As Long
Private WithEvents NetMeetingObject As NetMeeting
Private Sub Form_Load()
' Resize Picturebox to be the
' same as the Video Screen
ScaleMode = vbPixels
Picture1.Width = 177
Picture1.Height = 145
Picture1.ScaleMode = vbPixels
' Create a new NetMeeting Object
Set NetMeetingObject = New NetMeeting
' Undock a copy of the interface
NetMeetingObject.UnDock
' Wait for the Window to become available
mlHwnd = WaitForWindowCaption("NetMeeting - Not in a Call")
' If the Window was found..
If mlHwnd Then
' Place the Interface within the Picturebox on this Form
Call SetParent(mlHwnd, Picture1.hwnd)
' Reposition the Interface so only the Video Window is Visible
Call MoveWindow(mlHwnd, -12, -87, Picture1.ScaleWidth, Picture1.ScaleHeight, True)
Else
' Release the Object
Set NetMeetingObject = Nothing
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Make sure to cancel a call if in one.
If cmdClose.Enabled Then cmdClose_Click
' Release the Object
Set NetMeetingObject = Nothing
' If the Window was being Managed, Close it
If mlHwnd <> 0 Then
Call SendMessage(mlHwnd, WM_CLOSE, 0, ByVal 0&)
mlHwnd = 0
End If
End Sub
Private Sub cmdOpen_Click()
' Connect to some other Client
NetMeetingObject.CallTo "0.0.0.0"
End Sub
Private Sub cmdClose_Click()
' If there's a NetMeeting Object..
If Not NetMeetingObject Is Nothing Then
' If in a Call..
If NetMeetingObject.IsInConference Then
' Close the Call
NetMeetingObject.LeaveConference
End If
End If
End Sub
Private Sub NetMeetingObject_ConferenceStarted()
Debug.Print "Call Initiated"
cmdOpen.Enabled = False
cmdClose.Enabled = True
End Sub
Private Sub NetMeetingObject_ConferenceEnded()
Debug.Print "End of Call"
cmdOpen.Enabled = True
cmdClose.Enabled = False
End Sub
Private Function WaitForWindowCaption(ByVal sCaption As String) As Long
Dim lhWnd As Long
Dim sText As String
Dim tTimer As Single
' Wait for a Window with the specified
' Caption to be loaded.
' (could have used Window Enumeration, but
' This allows the code to be in a Form's
' code module.)
tTimer = Timer
Do
If lhWnd = 0 Then
lhWnd = GetTopWindow(0)
Else
lhWnd = GetNextWindow(lhWnd, GW_HWNDNEXT)
End If
sText = Space(260)
sText = Left(sText, GetWindowText(lhWnd, ByVal sText, 260))
Loop While StrComp(Left(sText, Len(sCaption)), sCaption, vbTextCompare) <> 0 And ((Timer - tTimer) < 10)
WaitForWindowCaption = IIf(StrComp(Left(sText, Len(sCaption)), sCaption, vbTextCompare) = 0, lhWnd, 0)
End Function