home *** CD-ROM | disk | FTP | other *** search
Wrap
// NetCap.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "NetCap.h" #include "Connect.h" #define TIMER_ID 2 #define TIMER_TIMEOUT 600 // seconds #define QUEUE_MAX 100 // Kb #define CONNECTION_SERVER 0 #define CONNECTION_CLIENT 1 #define PREVIEW_RATE (float)4.0 #define STATUS_NONE 0x0000 #define STATUS_SERVER 0x0001 #define STATUS_CAPTURE 0x0002 #define STATUS_SOUND_PLAY 0x0004 #define STATUS_SOUND_SEND 0x0008 #define STATUS_EVENT 0x1000 #define TESTEVENT(x) if ((x & STATUS_EVENT) == 0) return #define ERROR_SOUND_FORMAT "Bad Sound Format" #define UNKNOWN_HOST_IP "???.???.???.???" ///////////////////////////////////////////////////////////////////////////// // CNetCapApp BEGIN_MESSAGE_MAP(CNetCapApp, CWinApp) //{{AFX_MSG_MAP(CNetCapApp) //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNetCapApp construction CNetCapApp::CNetCapApp() { } ///////////////////////////////////////////////////////////////////////////// // The one and only CNetCapApp object CNetCapApp theApp; ///////////////////////////////////////////////////////////////////////////// // CNetCapApp initialization BOOL CNetCapApp::InitInstance() { AfxEnableControlContainer(); #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CNetCapDlg dlg; m_pMainWnd = &dlg; dlg.DoModal(); return FALSE; } ///////////////////////////////////////////////////////////////////////////// // CNetCapDlg dialog CNetCapDlg::CNetCapDlg(CWnd* pParent /*=NULL*/) : CDialog(CNetCapDlg::IDD, pParent) { //{{AFX_DATA_INIT(CNetCapDlg) //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_nStatus = STATUS_NONE; } void CNetCapDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNetCapDlg) DDX_Control(pDX, IDC_SEND_SOUND, m_SendSound); DDX_Control(pDX, IDC_SEND_BITMAP, m_SendBitmap); DDX_Control(pDX, IDC_PLAY_SOUND, m_PlaySound); DDX_Control(pDX, IDC_BYTES_IN, m_BytesIn); DDX_Control(pDX, IDC_BYTES_OUT, m_BytesOut); DDX_Control(pDX, IDC_BYTES_SPEED, m_BytesSpeed); DDX_Control(pDX, IDC_IMAGES_IN, m_ImagesIn); DDX_Control(pDX, IDC_IMAGES_SPEED, m_ImagesSpeed); DDX_Control(pDX, IDC_IMAGES_OUT, m_ImagesOut); DDX_Control(pDX, IDC_TIME, m_Time); DDX_Control(pDX, IDC_MESSAGE, m_Message); DDX_Control(pDX, IDC_VIDEO_SOURCE, m_VideoSource); DDX_Control(pDX, IDC_VIDEO_FORMAT, m_VideoFormat); DDX_Control(pDX, IDC_VIDEO_COMPRESSION, m_VideoCompression); DDX_Control(pDX, IDC_AUDIO_FORMAT, m_AudioFormat); DDX_Control(pDX, IDC_NODE, m_Node); DDX_Control(pDX, IDC_COMPUTER, m_Computer); DDX_Control(pDX, IDC_DISCONNECT, m_Disconnect); DDX_Control(pDX, IDC_SERVER, m_Server); DDX_Control(pDX, IDC_CONNECT, m_Connect); DDX_Control(pDX, IDC_LEADCAP, m_LeadCap); DDX_Control(pDX, IDC_LEADNET, m_LeadNet); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CNetCapDlg, CDialog) //{{AFX_MSG_MAP(CNetCapDlg) ON_BN_CLICKED(IDC_CONNECT, OnConnect) ON_BN_CLICKED(IDC_SERVER, OnServer) ON_BN_CLICKED(IDC_DISCONNECT, OnDisconnect) ON_NOTIFY(TVN_SELCHANGED, IDC_NODE, OnSelchangedNode) ON_BN_CLICKED(IDC_DISCONNECT_ALL, OnDisconnectAll) ON_WM_CLOSE() ON_BN_CLICKED(IDC_AUDIO_FORMAT, OnAudioFormat) ON_BN_CLICKED(IDC_VIDEO_COMPRESSION, OnVideoCompression) ON_BN_CLICKED(IDC_VIDEO_FORMAT, OnVideoFormat) ON_BN_CLICKED(IDC_VIDEO_SOURCE, OnVideoSource) ON_BN_CLICKED(IDC_SEND_SOUND, OnSendSound) ON_BN_CLICKED(IDC_PLAY_SOUND, OnPlaySound) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNetCapDlg message handlers BOOL CNetCapDlg::OnInitDialog() { CDialog::OnInitDialog(); SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE); UNLOCKSUPPORT(m_LeadNet); UNLOCKSUPPORT(m_LeadCap); m_nWaveFormatTag = -1; m_nWaveChannels = -1; m_nWaveSamplesPerSec = -1; m_nWaveAvgBytesPerSec = -1; m_nWaveBlockAlign = -1; m_nWaveBitsPerSample = -1; m_nWaveExtraSize = -1; m_SendSound.SetCheck(TRUE); m_SendBitmap.SetCheck(TRUE); m_PlaySound.SetCheck(TRUE); m_hServerNode = m_Node.InsertItem("", TVI_ROOT, TVI_LAST); m_Node.SetItemState(m_hServerNode, TVIS_BOLD | TVIS_EXPANDED, TVIS_BOLD | TVIS_EXPANDED); m_Node.SetItemData(m_hServerNode, 0); m_Node.SelectItem(m_hServerNode); m_hClientNode = m_Node.InsertItem("", TVI_ROOT, TVI_LAST); m_Node.SetItemState(m_hClientNode, TVIS_BOLD | TVIS_EXPANDED, TVIS_BOLD | TVIS_EXPANDED); m_Node.SetItemData(m_hClientNode, 0); m_Node.RedrawWindow(); CountConnections(); SetDlgItemText(IDC_COMPUTER, "207.238.49.190"); m_Computer.RedrawWindow(); m_LeadNet.SetEnableMethodErrors(FALSE); m_LeadCap.SetEnableMethodErrors(FALSE); m_LeadCap.SetAutoResizeControl(FALSE); m_LeadCap.SetCapAudioFormat(CAP_AUDIO_RECORD, FILE_WAV_1M08); m_LeadCap.SetCapCaptureAudio(TRUE); m_nStatus |= STATUS_EVENT; OnServer(); OpenCapture(); m_LeadCap.SetCapDisplayMode(DISPLAY_PREVIEW); m_LeadCap.SetCapPreviewRate(PREVIEW_RATE); m_LeadCap.SetCapFramesPerSec(PREVIEW_RATE); OpenSoundSend(); m_LeadCap.SetEnableCaptureEvents(TRUE); SetTimer(TIMER_ID, 1000, NULL); m_LeadNet.ShowWindow(SW_HIDE); return TRUE; // return TRUE unless you set the focus to a control } void CNetCapDlg::OnClose() { KillTimer(TIMER_ID); m_nStatus &= ~STATUS_EVENT; m_LeadCap.SetCapCaptureAudio(FALSE); m_LeadCap.SetEnableCaptureEvents(FALSE); CloseSoundPlay(); CloseSoundSend(); CloseCapture(); OnDisconnectAll(); DeleteAllConnections(); CDialog::OnClose(); } BEGIN_EVENTSINK_MAP(CNetCapDlg, CDialog) //{{AFX_EVENTSINK_MAP(CNetCapDlg) ON_EVENT(CNetCapDlg, IDC_LEADNET, 1 /* InetReceiveBitmap */, OnInetReceiveBitmap, VTS_I2 VTS_I4) ON_EVENT(CNetCapDlg, IDC_LEADNET, 2 /* InetReceiveData */, OnInetReceiveData, VTS_I2 VTS_VARIANT VTS_I4 VTS_I2) ON_EVENT(CNetCapDlg, IDC_LEADNET, 3 /* InetConnected */, OnInetConnected, VTS_I2) ON_EVENT(CNetCapDlg, IDC_LEADNET, 4 /* InetDisconnected */, OnInetDisconnected, VTS_I2) ON_EVENT(CNetCapDlg, IDC_LEADNET, 5 /* InetAccept */, OnInetAccept, VTS_I2) ON_EVENT(CNetCapDlg, IDC_LEADNET, 6 /* InetError */, OnInetError, VTS_I2 VTS_I2 VTS_I2) ON_EVENT(CNetCapDlg, IDC_LEADNET, 7 /* InetReceiveStart */, OnInetReceiveStart, VTS_I2 VTS_I4) ON_EVENT(CNetCapDlg, IDC_LEADNET, 8 /* InetReceiving */, OnInetReceiving, VTS_I2 VTS_I4) ON_EVENT(CNetCapDlg, IDC_LEADNET, 9 /* InetDataSent */, OnInetDataSent, VTS_I2 VTS_I4) ON_EVENT(CNetCapDlg, IDC_LEADNET, 10 /* InetSending */, OnInetSending, VTS_I2 VTS_I4) ON_EVENT(CNetCapDlg, IDC_LEADNET, 11 /* InetReceiveSound */, OnInetReceiveSound, VTS_I2 VTS_I2 VTS_I2 VTS_I4 VTS_I4 VTS_I2 VTS_I2 VTS_I2 VTS_VARIANT VTS_VARIANT VTS_I4) ON_EVENT(CNetCapDlg, IDC_LEADCAP, 1 /* CapDriver */, OnCapDriver, VTS_I2 VTS_BSTR) ON_EVENT(CNetCapDlg, IDC_LEADCAP, 3 /* CapVideoData */, OnCapVideoData, VTS_I4 VTS_I4) ON_EVENT(CNetCapDlg, IDC_LEADCAP, 4 /* CapAudioData */, OnCapAudioData, VTS_VARIANT VTS_I4 VTS_I2) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() ///////////////////////////////////////////////////////////////////////////// void CNetCapDlg::ExpandTree(HTREEITEM hItem) { HTREEITEM hChild; while (hItem != NULL) { if (m_Node.ItemHasChildren(hItem) == TRUE) { m_Node.Expand(hItem, TVE_EXPAND); hChild = m_Node.GetChildItem(hItem); ExpandTree(hChild); } hItem = m_Node.GetNextSiblingItem(hItem); } } void CNetCapDlg::GetHostIP(short nComputer, char *szHostIP) { int nResult; BSTR bstrText; CString strText; nResult = m_LeadNet.InetGetHostName(nComputer, HOST_NAME_IP, &bstrText); if (nResult == S_OK) { strText = bstrText; strcpy(szHostIP, (LPCTSTR)strText); ::SysFreeString(bstrText); } else { strcpy(szHostIP, UNKNOWN_HOST_IP); } } void CNetCapDlg::GetHostName(short nComputer, char *szHostName) { int nResult; BSTR bstrText; CString strText; nResult = m_LeadNet.InetGetHostName(nComputer, HOST_NAME_DESCRP, &bstrText); if (nResult == S_OK) { strText = bstrText; strText.TrimRight(); strcpy(szHostName, (LPCTSTR)strText); ::SysFreeString(bstrText); } else { strcpy(szHostName, ""); } } void CNetCapDlg::AppendConnection(short nComputer, int nMode) { char szHostName[256], szHostIP[20], szText[256]; int f = 0; HTREEITEM hRoot, hChild; CConnection *pConnection; GetHostName(nComputer, szHostName); GetHostIP(nComputer, szHostIP); sprintf(szText, "%-15s \"%s\"", szHostIP, szHostName); if (nMode == CONNECTION_CLIENT) { hRoot = m_hClientNode; } else { hRoot = m_hServerNode; } hChild = m_Node.GetChildItem(hRoot); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer)) { f = 1; break; } hChild = m_Node.GetNextSiblingItem(hChild); } if (f == 0) { pConnection = (CConnection *)new CConnection; pConnection->m_nComputer = nComputer; pConnection->m_pOwner = this; strcpy(pConnection->m_szHostIP, szHostIP); strcpy(pConnection->m_szHostName, szHostName); hChild = m_Node.InsertItem(szText, hRoot, TVI_LAST); m_Node.SetItemState(hChild, TVIS_EXPANDED, TVIS_EXPANDED); m_Node.SetItemData(hChild, (DWORD)pConnection); pConnection->Create(IDD_CONNECTION_DIALOG, this); pConnection->SetWindowText(szText); } m_Node.RedrawWindow(); CountConnections(); } void CNetCapDlg::DeleteConnection(short nComputer) { HTREEITEM hChild; CConnection *pConnection; hChild = m_Node.GetChildItem(m_hServerNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer)) { pConnection->DestroyWindow(); delete pConnection; m_Node.DeleteItem(hChild); break; } hChild = m_Node.GetNextSiblingItem(hChild); } hChild = m_Node.GetChildItem(m_hClientNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer)) { pConnection->DestroyWindow(); delete pConnection; m_Node.DeleteItem(hChild); break; } hChild = m_Node.GetNextSiblingItem(hChild); } m_Node.RedrawWindow(); CountConnections(); } void CNetCapDlg::DeleteAllConnections() { HTREEITEM hChild; CConnection *pConnection; hChild = m_Node.GetChildItem(m_hServerNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if (pConnection != NULL) { pConnection->DestroyWindow(); delete pConnection; m_Node.DeleteItem(hChild); hChild = m_Node.GetChildItem(m_hServerNode); } else { hChild = m_Node.GetNextSiblingItem(hChild); } } hChild = m_Node.GetChildItem(m_hClientNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if (pConnection != NULL) { pConnection->DestroyWindow(); delete pConnection; m_Node.DeleteItem(hChild); hChild = m_Node.GetChildItem(m_hClientNode); } else { hChild = m_Node.GetNextSiblingItem(hChild); } } m_Node.RedrawWindow(); CountConnections(); } int CNetCapDlg::GetServerConnections() { int nCount=0; HTREEITEM hChild; hChild = m_Node.GetChildItem(m_hServerNode); while (hChild != NULL) { nCount++; hChild = m_Node.GetNextSiblingItem(hChild); } return nCount; } int CNetCapDlg::GetClientConnections() { int nCount=0; HTREEITEM hChild; hChild = m_Node.GetChildItem(m_hClientNode); while (hChild != NULL) { nCount++; hChild = m_Node.GetNextSiblingItem(hChild); } return nCount; } void CNetCapDlg::CountConnections() { char szText[80]; sprintf(szText, "Servers: %d", GetServerConnections()); m_Node.SetItemText(m_hServerNode, szText); sprintf(szText, "Clients: %d", GetClientConnections()); m_Node.SetItemText(m_hClientNode, szText); } CConnection *CNetCapDlg::FindConnection(short nComputer) { HTREEITEM hChild; CConnection *pConnection; hChild = m_Node.GetChildItem(m_hServerNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer)) { return pConnection; } hChild = m_Node.GetNextSiblingItem(hChild); } hChild = m_Node.GetChildItem(m_hClientNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer)) { return pConnection; } hChild = m_Node.GetNextSiblingItem(hChild); } return NULL; } short CNetCapDlg::FindConnectionIP(short nComputer) { char szHostIP[20]; HTREEITEM hChild; CConnection *pConnection; GetHostIP(nComputer, szHostIP); hChild = m_Node.GetChildItem(m_hServerNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if ((pConnection != NULL) && (strcmp(pConnection->m_szHostIP, szHostIP) == 0)) { return TRUE; } hChild = m_Node.GetNextSiblingItem(hChild); } hChild = m_Node.GetChildItem(m_hClientNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if ((pConnection != NULL) && (strcmp(pConnection->m_szHostIP, szHostIP) == 0)) { return TRUE; } hChild = m_Node.GetNextSiblingItem(hChild); } return FALSE; } CConnection *CNetCapDlg::GetCurrentConnection() { HTREEITEM hChild; CConnection *pConnection=NULL; hChild = m_Node.GetSelectedItem(); if (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); } return pConnection; } void CNetCapDlg::ShowCurrentConnection() { char szText[256]; unsigned long nTime; CConnection *pConnection; pConnection = GetCurrentConnection(); if (pConnection == NULL) { SetDlgItemText(IDC_BYTES_SPEED, ""); m_BytesSpeed.RedrawWindow(); SetDlgItemText(IDC_IMAGES_SPEED, ""); m_ImagesSpeed.RedrawWindow(); SetDlgItemText(IDC_IMAGES_IN, ""); m_ImagesIn.RedrawWindow(); SetDlgItemText(IDC_BYTES_IN, ""); m_BytesIn.RedrawWindow(); SetDlgItemText(IDC_IMAGES_OUT, ""); m_ImagesOut.RedrawWindow(); SetDlgItemText(IDC_BYTES_OUT, ""); m_BytesOut.RedrawWindow(); SetDlgItemText(IDC_TIME, ""); m_Time.RedrawWindow(); return; } else { nTime = labs(GetTickCount() - pConnection->m_nTime); sprintf(szText, "%.2f", ((double)(pConnection->m_nBytesIn + pConnection->m_nBytesOut) / 1024.0) / ((double)nTime / 1000.0)); SetDlgItemText(IDC_BYTES_SPEED, szText); m_BytesSpeed.RedrawWindow(); sprintf(szText, "%.2f", (double)(pConnection->m_nImagesIn + pConnection->m_nImagesOut) / ((double)nTime / 1000.0)); SetDlgItemText(IDC_IMAGES_SPEED, szText); m_ImagesSpeed.RedrawWindow(); sprintf(szText, "%ld", pConnection->m_nImagesIn); SetDlgItemText(IDC_IMAGES_IN, szText); m_ImagesIn.RedrawWindow(); sprintf(szText, "%ld", pConnection->m_nBytesIn / 1024); SetDlgItemText(IDC_BYTES_IN, szText); m_BytesIn.RedrawWindow(); sprintf(szText, "%ld", pConnection->m_nImagesOut); SetDlgItemText(IDC_IMAGES_OUT, szText); m_ImagesOut.RedrawWindow(); sprintf(szText, "%ld", pConnection->m_nBytesOut / 1024); SetDlgItemText(IDC_BYTES_OUT, szText); m_BytesOut.RedrawWindow(); nTime /= 1000; sprintf(szText, "%02ld:%02ld:%02ld", nTime / 3600, (nTime % 3600) / 60, (nTime % 3600) % 60); SetDlgItemText(IDC_TIME, szText); m_Time.RedrawWindow(); } } void CNetCapDlg::DisplayMessage(short iComputer, char *szMessage) { char szText[256]; char szHostIP[20]; SYSTEMTIME Time; TESTEVENT(m_nStatus); GetHostIP(iComputer, szHostIP); if (strlen(szHostIP) + strlen(szMessage) + 16 > sizeof(szText)) { return; } GetLocalTime(&Time); sprintf(szText, "%02ld:%02ld:%02ld <%s>: %s", Time.wHour, Time.wMinute, Time.wSecond, szHostIP, szMessage); SetDlgItemText(IDC_MESSAGE, szText); m_Message.RedrawWindow(); } ///////////////////////////////////////////////////////////////////////////// void CNetCapDlg::OnConnect() { CString strText; GetDlgItemText(IDC_COMPUTER, strText); m_LeadNet.InetConnect(strText, 1000); } void CNetCapDlg::Disconnect(short iComputer) { int i; for (i = 0; i < m_LeadNet.GetSendListNum(); i++) { if (m_LeadNet.GetSendList(i) == iComputer) { m_LeadNet.SetSendList(i, 0); break; } } DeleteConnection(iComputer); m_LeadNet.InetDisconnect(iComputer); } void CNetCapDlg::OnDisconnect() { CConnection *pConnection; pConnection = GetCurrentConnection(); if (pConnection != NULL) { Disconnect(pConnection->m_nComputer); } } void CNetCapDlg::OnDisconnectAll() { HTREEITEM hChild; CConnection *pConnection; hChild = m_Node.GetChildItem(m_hServerNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if (pConnection != NULL) { Disconnect(pConnection->m_nComputer); hChild = m_Node.GetChildItem(m_hServerNode); } else { hChild = m_Node.GetNextSiblingItem(hChild); } } hChild = m_Node.GetChildItem(m_hClientNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if (pConnection != NULL) { Disconnect(pConnection->m_nComputer); hChild = m_Node.GetChildItem(m_hClientNode); } else { hChild = m_Node.GetNextSiblingItem(hChild); } } } void CNetCapDlg::OnSelchangedNode(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW*)pNMHDR; CConnection *pConnection; TESTEVENT(m_nStatus); pConnection = GetCurrentConnection(); if (pConnection == NULL) { m_Disconnect.EnableWindow(FALSE); } else { m_Disconnect.EnableWindow(TRUE); SetDlgItemText(IDC_COMPUTER, pConnection->m_szHostIP); m_Computer.RedrawWindow(); } ShowCurrentConnection(); *pResult = 0; } void CNetCapDlg::OnServer() { int nResult; if ((m_nStatus & STATUS_SERVER) == 0) { nResult = m_LeadNet.InetServerInit(&m_nServer, 1000); if (nResult == S_OK) { m_Server.SetWindowText("Close Server"); m_nStatus |= STATUS_SERVER; } } else { OnDisconnectAll(); nResult = m_LeadNet.InetServerClose(m_nServer); if (nResult == S_OK) { m_Server.SetWindowText("Init Server"); m_nStatus &= ~STATUS_SERVER; } } } ///////////////////////////////////////////////////////////////////////////// void CNetCapDlg::OnInetReceiveBitmap(short iComputer, long hBitmap) { CConnection *pConnection; TESTEVENT(m_nStatus); pConnection = FindConnection(iComputer); if (pConnection != NULL) { CRect rcWindow, rcClient, rcLead; int nWidth, nHeight, nDeltaWidth, nDeltaHeight; pConnection->m_Lead.SetBitmap(hBitmap); rcLead = CRect(0, 0, (int)pConnection->m_Lead.GetBitmapWidth(), (int)pConnection->m_Lead.GetBitmapHeight()); pConnection->GetWindowRect(rcWindow); pConnection->GetClientRect(rcClient); nDeltaWidth = rcWindow.Width() - rcClient.Width(); nDeltaHeight = rcWindow.Height() - rcClient.Height(); nWidth = rcLead.Width() + nDeltaWidth; nHeight = rcLead.Height() + nDeltaHeight; if ((nWidth != rcClient.Width()) || (nHeight != rcClient.Height())) { pConnection->MoveWindow(rcWindow.TopLeft().x, rcWindow.TopLeft().y, nWidth, nHeight, TRUE); } pConnection->m_Lead.RedrawWindow(); pConnection->m_nImagesIn++; } } void CNetCapDlg::OnInetReceiveData(short iComputer, const VARIANT FAR& pData, long lSize, short iType) { TESTEVENT(m_nStatus); if (iType == IDATA_USER2) { DisplayMessage(iComputer, (char far *)((V_ARRAY(&pData))->pvData)); } } void CNetCapDlg::OnInetConnected(short iComputer) { TESTEVENT(m_nStatus); m_LeadNet.SetSendList(m_LeadNet.GetSendListNum(), iComputer); AppendConnection(iComputer, CONNECTION_SERVER); } void CNetCapDlg::OnInetDisconnected(short iComputer) { TESTEVENT(m_nStatus); DeleteConnection(iComputer); } void CNetCapDlg::OnInetAccept(short iServer) { short iComputer; int nResult; TESTEVENT(m_nStatus); nResult = m_LeadNet.InetAcceptConnect(iServer, &iComputer); if (nResult == S_OK) { m_LeadNet.SetSendList(m_LeadNet.GetSendListNum(), iComputer); AppendConnection(iComputer, CONNECTION_CLIENT); } } void CNetCapDlg::OnInetError(short iComputer, short iMessage, short iError) { char szText[80]; TESTEVENT(m_nStatus); sprintf(szText, "Error %d (%d)", iError, iMessage); DisplayMessage(iComputer, szText); if (iError == ERROR_CONNECT_RESET) { Disconnect(iComputer); } } void CNetCapDlg::OnInetReceiveStart(short iComputer, long lSize) { CConnection *pConnection; TESTEVENT(m_nStatus); pConnection = FindConnection(iComputer); if (pConnection != NULL) { pConnection->m_nBytesIn += lSize; pConnection->m_nTimeout = GetTickCount(); } } void CNetCapDlg::OnInetReceiving(short iComputer, long lSize) { TESTEVENT(m_nStatus); } void CNetCapDlg::OnInetDataSent(short iComputer, long lSize) { CConnection *pConnection; TESTEVENT(m_nStatus); pConnection = FindConnection(iComputer); if (pConnection != NULL) { pConnection->m_nBytesOut += lSize; pConnection->m_nTimeout = GetTickCount(); } } void CNetCapDlg::OnInetSending(short iComputer, long lSize) { TESTEVENT(m_nStatus); } void CNetCapDlg::OnInetReceiveSound(short iComputer, short iFormatTag, short nChannels, long lSamplesPerSec, long lAvgBytesPerSec, short iBlockAlign, short iBitsPerSample, short iExtraDataSize, const VARIANT FAR& pExtraData, const VARIANT FAR& pData, long lDataSize) { int nResult; VARIANT var; SAFEARRAY FAR *psa; SAFEARRAYBOUND rgsabound[1]; TESTEVENT(m_nStatus); if (m_PlaySound.GetCheck() == FALSE) { CloseSoundPlay(); return; } if (m_nStatus & STATUS_SOUND_PLAY) { if ((m_LeadCap.GetCapWaveFormatTag(CAP_AUDIO_FEED) != iFormatTag) || (m_LeadCap.GetCapWaveChannels(CAP_AUDIO_FEED) != nChannels) || (m_LeadCap.GetCapWaveSamplesPerSec(CAP_AUDIO_FEED) != lSamplesPerSec) || (m_LeadCap.GetCapWaveAvgBytesPerSec(CAP_AUDIO_FEED) != lAvgBytesPerSec) || (m_LeadCap.GetCapWaveBlockAlign(CAP_AUDIO_FEED) != iBlockAlign) || (m_LeadCap.GetCapWaveBitsPerSample(CAP_AUDIO_FEED) != iBitsPerSample) || (m_LeadCap.GetCapWaveExtraSize(CAP_AUDIO_FEED) != iExtraDataSize)) { CloseSoundPlay(); } } if ((m_nStatus & STATUS_SOUND_PLAY) == 0) { if ((m_nWaveFormatTag != iFormatTag) || (m_nWaveChannels != nChannels) || (m_nWaveSamplesPerSec != lSamplesPerSec) || (m_nWaveAvgBytesPerSec != lAvgBytesPerSec) || (m_nWaveBlockAlign != iBlockAlign) || (m_nWaveBitsPerSample != iBitsPerSample) || (m_nWaveExtraSize != iExtraDataSize)) { m_LeadCap.SetCapWaveFormatTag(CAP_AUDIO_FEED, iFormatTag); m_LeadCap.SetCapWaveChannels(CAP_AUDIO_FEED, nChannels); m_LeadCap.SetCapWaveSamplesPerSec(CAP_AUDIO_FEED, lSamplesPerSec); m_LeadCap.SetCapWaveAvgBytesPerSec(CAP_AUDIO_FEED, lAvgBytesPerSec); m_LeadCap.SetCapWaveBlockAlign(CAP_AUDIO_FEED, iBlockAlign); m_LeadCap.SetCapWaveBitsPerSample(CAP_AUDIO_FEED, iBitsPerSample); m_LeadCap.SetCapWaveExtraSize(CAP_AUDIO_FEED, iExtraDataSize); m_LeadCap.SetCapWaveExtraData(CAP_AUDIO_FEED, pExtraData); m_nWaveFormatTag = iFormatTag; m_nWaveChannels = nChannels; m_nWaveSamplesPerSec = lSamplesPerSec; m_nWaveAvgBytesPerSec = lAvgBytesPerSec; m_nWaveBlockAlign = iBlockAlign; m_nWaveBitsPerSample = iBitsPerSample; m_nWaveExtraSize = iExtraDataSize; nResult = m_LeadCap.CapStartFeedSound("", -1, 0, CAP_FEED_PLAYDATA, &m_hSound); if (nResult == S_OK) { m_nStatus |= STATUS_SOUND_PLAY; } else if (nResult == ERROR_WAVE_FORMAT) { DisplayMessage(iComputer, ERROR_SOUND_FORMAT); VariantInit(&var); rgsabound[0].lLbound = 0; rgsabound[0].cElements = strlen(ERROR_SOUND_FORMAT) + 1; psa = SafeArrayCreate(VT_UI1, 1, rgsabound); if (psa != NULL) { SafeArrayLock(psa); strcpy((char far *)psa->pvData, ERROR_SOUND_FORMAT); SafeArrayUnlock(psa); V_VT(&var) = (VT_ARRAY | VT_UI1); V_ARRAY(&var) = psa; m_LeadNet.InetSendData(&var, strlen(ERROR_SOUND_FORMAT) + 1, IDATA_USER2); SafeArrayDestroy(psa); } VariantClear(&var); } else { m_nWaveFormatTag = -1; m_nWaveChannels = -1; m_nWaveSamplesPerSec = -1; m_nWaveAvgBytesPerSec = -1; m_nWaveBlockAlign = -1; m_nWaveBitsPerSample = -1; m_nWaveExtraSize = -1; } } } else { m_LeadCap.CapFeedSound(m_hSound, (VARIANT *)&pData, lDataSize); } } ///////////////////////////////////////////////////////////////////////////// void CNetCapDlg::OnAudioFormat() { CloseSoundSend(); m_LeadCap.CapDisplayDialog(DLG_AUDFORMAT, CAP_AUDIO_RECORD, CAP_AUDIO_CHOOSE_OUTPUT); if (m_SendSound.GetCheck()) { OpenSoundSend(); } } void CNetCapDlg::OnVideoFormat() { m_LeadCap.CapDisplayDialog(DLG_VIDFORMAT, 0, 0); } void CNetCapDlg::OnVideoCompression() { m_LeadCap.CapDisplayDialog(DLG_VIDCOMP, 0, 0); } void CNetCapDlg::OnVideoSource() { m_LeadCap.CapDisplayDialog(DLG_VIDSOURCE, 0, 0); } void CNetCapDlg::TestQueue() { int i, nComputer; long nSize; for (i = 0; i < m_LeadNet.GetSendListNum(); i++) { nComputer = m_LeadNet.GetSendList(i); nSize = m_LeadNet.GetInetQueueSize(nComputer) / 1024; if (nSize > QUEUE_MAX) { m_LeadNet.InetClearQueue(nComputer); } } } void CNetCapDlg::OnCapVideoData(long hDib, long lTime) { HTREEITEM hChild; CConnection *pConnection; TESTEVENT(m_nStatus); if (m_SendBitmap.GetCheck() == FALSE) { return; } hChild = m_Node.GetChildItem(m_hServerNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if (pConnection != NULL) { pConnection->m_nImagesOut++; } hChild = m_Node.GetNextSiblingItem(hChild); } hChild = m_Node.GetChildItem(m_hClientNode); while (hChild != NULL) { pConnection = (CConnection *)m_Node.GetItemData(hChild); if (pConnection != NULL) { pConnection->m_nImagesOut++; } hChild = m_Node.GetNextSiblingItem(hChild); } m_LeadNet.InetSendDIB(hDib, FILE_CMP, 24, -5); } void CNetCapDlg::OnCapAudioData(const VARIANT FAR& pData, long lBytesRecorded, short iIndex) { VARIANT var; TESTEVENT(m_nStatus); if (iIndex != CAP_AUDIO_RECORD) { return; } if (m_SendSound.GetCheck() == FALSE) { return; } TestQueue(); var = m_LeadCap.GetCapWaveExtraData(CAP_AUDIO_RECORD); m_LeadNet.InetSendSound(m_LeadCap.GetCapWaveFormatTag(CAP_AUDIO_RECORD), m_LeadCap.GetCapWaveChannels(CAP_AUDIO_RECORD), m_LeadCap.GetCapWaveSamplesPerSec(CAP_AUDIO_RECORD), m_LeadCap.GetCapWaveAvgBytesPerSec(CAP_AUDIO_RECORD), m_LeadCap.GetCapWaveBlockAlign(CAP_AUDIO_RECORD), m_LeadCap.GetCapWaveBitsPerSample(CAP_AUDIO_RECORD), (short)m_LeadCap.GetCapWaveExtraSize(CAP_AUDIO_RECORD), &var, (VARIANT *)&pData, lBytesRecorded); VariantClear(&var); } void CNetCapDlg::OnCapDriver(short iDriver, LPCTSTR pszName) { int nResult; if (m_nStatus & STATUS_CAPTURE) { return; } nResult = m_LeadCap.CapConnect(iDriver); if (nResult == S_OK) { m_nStatus |= STATUS_CAPTURE; } } void CNetCapDlg::OnSendSound() { if (m_SendSound.GetCheck()) { OpenSoundSend(); } else { CloseSoundSend(); } } void CNetCapDlg::OnPlaySound() { if (m_PlaySound.GetCheck() == FALSE) { CloseSoundPlay(); } } void CNetCapDlg::OpenSoundSend() { int nResult; if (m_nStatus & STATUS_SOUND_SEND) { return; } TestQueue(); nResult = m_LeadCap.CapOpenRecord(-1, 0, m_LeadCap.GetCapWaveAvgBytesPerSec(CAP_AUDIO_RECORD)); if (nResult == S_OK) { m_LeadCap.CapStartRecord(); m_nStatus |= STATUS_SOUND_SEND; } } void CNetCapDlg::CloseSoundSend() { if ((m_nStatus & STATUS_SOUND_SEND) == 0) { return; } m_LeadCap.CapStopRecord(); m_LeadCap.CapCloseRecord(); m_nStatus &= ~STATUS_SOUND_SEND; } void CNetCapDlg::CloseSoundPlay() { if ((m_nStatus & STATUS_SOUND_PLAY) == 0) { return; } m_LeadCap.CapStopFeedSound(m_hSound, FALSE); m_nStatus &= ~STATUS_SOUND_PLAY; } void CNetCapDlg::OpenCapture() { m_LeadCap.CapEnumDrivers(); } void CNetCapDlg::CloseCapture() { if ((m_nStatus & STATUS_CAPTURE) == 0) { return; } m_LeadCap.CapDisconnect(); m_nStatus &= ~STATUS_CAPTURE; } void CNetCapDlg::OnTimer(UINT nIDEvent) { int i; CConnection *pConnection; for (i = 0; i < m_LeadNet.GetSendListNum(); i++) { pConnection = FindConnection(m_LeadNet.GetSendList(i)); if (pConnection != NULL) { if (labs(pConnection->m_nTimeout - GetTickCount()) / 1000 > TIMER_TIMEOUT) { DeleteConnection(pConnection->m_nComputer); i = -1; } } } ShowCurrentConnection(); CDialog::OnTimer(nIDEvent); }