home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / Netcap.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-15  |  32.0 KB  |  1,260 lines

  1. // NetCap.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "NetCap.h"
  6. #include "Connect.h"
  7.  
  8. #define TIMER_ID            2
  9. #define TIMER_TIMEOUT     600       // seconds
  10. #define QUEUE_MAX         100       // Kb
  11.  
  12. #define CONNECTION_SERVER 0
  13. #define CONNECTION_CLIENT 1
  14.  
  15. #define PREVIEW_RATE       (float)4.0
  16.  
  17. #define STATUS_NONE        0x0000
  18. #define STATUS_SERVER      0x0001
  19. #define STATUS_CAPTURE     0x0002
  20. #define STATUS_SOUND_PLAY  0x0004
  21. #define STATUS_SOUND_SEND  0x0008
  22. #define STATUS_EVENT       0x1000
  23.  
  24. #define TESTEVENT(x) if ((x & STATUS_EVENT) == 0) return
  25.  
  26. #define ERROR_SOUND_FORMAT "Bad Sound Format"
  27. #define UNKNOWN_HOST_IP    "???.???.???.???"
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CNetCapApp
  31.  
  32. BEGIN_MESSAGE_MAP(CNetCapApp, CWinApp)
  33.     //{{AFX_MSG_MAP(CNetCapApp)
  34.     //}}AFX_MSG
  35.     ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  36. END_MESSAGE_MAP()
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CNetCapApp construction
  40.  
  41. CNetCapApp::CNetCapApp()
  42. {
  43. }
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // The one and only CNetCapApp object
  47.  
  48. CNetCapApp theApp;
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CNetCapApp initialization
  52.  
  53. BOOL CNetCapApp::InitInstance()
  54. {
  55.     AfxEnableControlContainer();
  56.  
  57. #ifdef _AFXDLL
  58.     Enable3dControls();            // Call this when using MFC in a shared DLL
  59. #else
  60.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  61. #endif
  62.  
  63.     CNetCapDlg dlg;
  64.     m_pMainWnd = &dlg;
  65.     
  66.    dlg.DoModal();
  67.  
  68.    return FALSE;
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CNetCapDlg dialog
  73.  
  74. CNetCapDlg::CNetCapDlg(CWnd* pParent /*=NULL*/)
  75.     : CDialog(CNetCapDlg::IDD, pParent)
  76. {
  77.     //{{AFX_DATA_INIT(CNetCapDlg)
  78.     //}}AFX_DATA_INIT
  79.  
  80.    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  81.    m_nStatus = STATUS_NONE;
  82. }
  83.  
  84. void CNetCapDlg::DoDataExchange(CDataExchange* pDX)
  85. {
  86.     CDialog::DoDataExchange(pDX);
  87.     //{{AFX_DATA_MAP(CNetCapDlg)
  88.     DDX_Control(pDX, IDC_SEND_SOUND, m_SendSound);
  89.     DDX_Control(pDX, IDC_SEND_BITMAP, m_SendBitmap);
  90.     DDX_Control(pDX, IDC_PLAY_SOUND, m_PlaySound);
  91.     DDX_Control(pDX, IDC_BYTES_IN, m_BytesIn);
  92.     DDX_Control(pDX, IDC_BYTES_OUT, m_BytesOut);
  93.     DDX_Control(pDX, IDC_BYTES_SPEED, m_BytesSpeed);
  94.     DDX_Control(pDX, IDC_IMAGES_IN, m_ImagesIn);
  95.     DDX_Control(pDX, IDC_IMAGES_SPEED, m_ImagesSpeed);
  96.     DDX_Control(pDX, IDC_IMAGES_OUT, m_ImagesOut);
  97.     DDX_Control(pDX, IDC_TIME, m_Time);
  98.     DDX_Control(pDX, IDC_MESSAGE, m_Message);
  99.     DDX_Control(pDX, IDC_VIDEO_SOURCE, m_VideoSource);
  100.     DDX_Control(pDX, IDC_VIDEO_FORMAT, m_VideoFormat);
  101.     DDX_Control(pDX, IDC_VIDEO_COMPRESSION, m_VideoCompression);
  102.     DDX_Control(pDX, IDC_AUDIO_FORMAT, m_AudioFormat);
  103.     DDX_Control(pDX, IDC_NODE, m_Node);
  104.     DDX_Control(pDX, IDC_COMPUTER, m_Computer);
  105.     DDX_Control(pDX, IDC_DISCONNECT, m_Disconnect);
  106.     DDX_Control(pDX, IDC_SERVER, m_Server);
  107.     DDX_Control(pDX, IDC_CONNECT, m_Connect);
  108.     DDX_Control(pDX, IDC_LEADCAP, m_LeadCap);
  109.     DDX_Control(pDX, IDC_LEADNET, m_LeadNet);
  110.     //}}AFX_DATA_MAP
  111. }
  112.  
  113. BEGIN_MESSAGE_MAP(CNetCapDlg, CDialog)
  114.     //{{AFX_MSG_MAP(CNetCapDlg)
  115.     ON_BN_CLICKED(IDC_CONNECT, OnConnect)
  116.     ON_BN_CLICKED(IDC_SERVER, OnServer)
  117.     ON_BN_CLICKED(IDC_DISCONNECT, OnDisconnect)
  118.     ON_NOTIFY(TVN_SELCHANGED, IDC_NODE, OnSelchangedNode)
  119.     ON_BN_CLICKED(IDC_DISCONNECT_ALL, OnDisconnectAll)
  120.     ON_WM_CLOSE()
  121.     ON_BN_CLICKED(IDC_AUDIO_FORMAT, OnAudioFormat)
  122.     ON_BN_CLICKED(IDC_VIDEO_COMPRESSION, OnVideoCompression)
  123.     ON_BN_CLICKED(IDC_VIDEO_FORMAT, OnVideoFormat)
  124.     ON_BN_CLICKED(IDC_VIDEO_SOURCE, OnVideoSource)
  125.     ON_BN_CLICKED(IDC_SEND_SOUND, OnSendSound)
  126.     ON_BN_CLICKED(IDC_PLAY_SOUND, OnPlaySound)
  127.     ON_WM_TIMER()
  128.     //}}AFX_MSG_MAP
  129. END_MESSAGE_MAP()
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CNetCapDlg message handlers
  133.  
  134. BOOL CNetCapDlg::OnInitDialog()
  135. {
  136.     CDialog::OnInitDialog();
  137.  
  138.     SetIcon(m_hIcon, TRUE);    
  139.     SetIcon(m_hIcon, FALSE);
  140.  
  141.     UNLOCKSUPPORT(m_LeadNet);
  142.     UNLOCKSUPPORT(m_LeadCap);
  143.  
  144.    m_nWaveFormatTag      = -1;
  145.    m_nWaveChannels       = -1;
  146.    m_nWaveSamplesPerSec  = -1;
  147.    m_nWaveAvgBytesPerSec = -1;
  148.    m_nWaveBlockAlign     = -1;
  149.    m_nWaveBitsPerSample  = -1;
  150.    m_nWaveExtraSize      = -1;
  151.  
  152.    m_SendSound.SetCheck(TRUE);
  153.    m_SendBitmap.SetCheck(TRUE);
  154.    m_PlaySound.SetCheck(TRUE);
  155.  
  156.    m_hServerNode = m_Node.InsertItem("", TVI_ROOT, TVI_LAST);
  157.    m_Node.SetItemState(m_hServerNode, TVIS_BOLD | TVIS_EXPANDED, TVIS_BOLD | TVIS_EXPANDED);
  158.    m_Node.SetItemData(m_hServerNode, 0);
  159.    m_Node.SelectItem(m_hServerNode);
  160.    
  161.    m_hClientNode = m_Node.InsertItem("", TVI_ROOT, TVI_LAST);
  162.    m_Node.SetItemState(m_hClientNode, TVIS_BOLD | TVIS_EXPANDED, TVIS_BOLD | TVIS_EXPANDED);
  163.    m_Node.SetItemData(m_hClientNode, 0);
  164.  
  165.    m_Node.RedrawWindow();
  166.  
  167.    CountConnections();
  168.    
  169.    SetDlgItemText(IDC_COMPUTER, "207.238.49.190");
  170.    m_Computer.RedrawWindow();
  171.  
  172.    m_LeadNet.SetEnableMethodErrors(FALSE);
  173.  
  174.    m_LeadCap.SetEnableMethodErrors(FALSE);
  175.     m_LeadCap.SetAutoResizeControl(FALSE);
  176.     m_LeadCap.SetCapAudioFormat(CAP_AUDIO_RECORD, FILE_WAV_1M08);
  177.    m_LeadCap.SetCapCaptureAudio(TRUE);
  178.  
  179.    m_nStatus |= STATUS_EVENT;
  180.  
  181.    OnServer();
  182.    OpenCapture();
  183.  
  184.    m_LeadCap.SetCapDisplayMode(DISPLAY_PREVIEW);
  185.     m_LeadCap.SetCapPreviewRate(PREVIEW_RATE);
  186.     m_LeadCap.SetCapFramesPerSec(PREVIEW_RATE);
  187.    
  188.    OpenSoundSend();
  189.  
  190.     m_LeadCap.SetEnableCaptureEvents(TRUE);
  191.    
  192.    SetTimer(TIMER_ID, 1000, NULL);
  193.  
  194.    m_LeadNet.ShowWindow(SW_HIDE);
  195.  
  196.    return TRUE;  // return TRUE  unless you set the focus to a control
  197. }
  198.  
  199. void CNetCapDlg::OnClose() 
  200. {
  201.    KillTimer(TIMER_ID);
  202.    m_nStatus &= ~STATUS_EVENT;
  203.    m_LeadCap.SetCapCaptureAudio(FALSE);
  204.     m_LeadCap.SetEnableCaptureEvents(FALSE);
  205.  
  206.    CloseSoundPlay();
  207.    CloseSoundSend();
  208.    CloseCapture();
  209.    OnDisconnectAll();
  210.    DeleteAllConnections();
  211.  
  212.     CDialog::OnClose();
  213. }
  214.  
  215. BEGIN_EVENTSINK_MAP(CNetCapDlg, CDialog)
  216.     //{{AFX_EVENTSINK_MAP(CNetCapDlg)
  217.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 1 /* InetReceiveBitmap */, OnInetReceiveBitmap, VTS_I2 VTS_I4)
  218.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 2 /* InetReceiveData */, OnInetReceiveData, VTS_I2 VTS_VARIANT VTS_I4 VTS_I2)
  219.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 3 /* InetConnected */, OnInetConnected, VTS_I2)
  220.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 4 /* InetDisconnected */, OnInetDisconnected, VTS_I2)
  221.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 5 /* InetAccept */, OnInetAccept, VTS_I2)
  222.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 6 /* InetError */, OnInetError, VTS_I2 VTS_I2 VTS_I2)
  223.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 7 /* InetReceiveStart */, OnInetReceiveStart, VTS_I2 VTS_I4)
  224.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 8 /* InetReceiving */, OnInetReceiving, VTS_I2 VTS_I4)
  225.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 9 /* InetDataSent */, OnInetDataSent, VTS_I2 VTS_I4)
  226.     ON_EVENT(CNetCapDlg, IDC_LEADNET, 10 /* InetSending */, OnInetSending, VTS_I2 VTS_I4)
  227.     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)
  228.     ON_EVENT(CNetCapDlg, IDC_LEADCAP, 1 /* CapDriver */, OnCapDriver, VTS_I2 VTS_BSTR)
  229.     ON_EVENT(CNetCapDlg, IDC_LEADCAP, 3 /* CapVideoData */, OnCapVideoData, VTS_I4 VTS_I4)
  230.     ON_EVENT(CNetCapDlg, IDC_LEADCAP, 4 /* CapAudioData */, OnCapAudioData, VTS_VARIANT VTS_I4 VTS_I2)
  231.     //}}AFX_EVENTSINK_MAP
  232. END_EVENTSINK_MAP()
  233.  
  234. /////////////////////////////////////////////////////////////////////////////
  235.  
  236. void CNetCapDlg::ExpandTree(HTREEITEM hItem)
  237. {
  238.    HTREEITEM hChild;
  239.  
  240.    while (hItem != NULL)
  241.    {
  242.       if (m_Node.ItemHasChildren(hItem) == TRUE)
  243.       {
  244.          m_Node.Expand(hItem, TVE_EXPAND);
  245.          hChild = m_Node.GetChildItem(hItem);
  246.          ExpandTree(hChild);
  247.       }
  248.  
  249.       hItem = m_Node.GetNextSiblingItem(hItem);
  250.    }
  251. }
  252.  
  253. void CNetCapDlg::GetHostIP(short nComputer, char *szHostIP)
  254. {
  255.    int     nResult;
  256.    BSTR    bstrText;
  257.    CString strText;
  258.  
  259.      nResult = m_LeadNet.InetGetHostName(nComputer, HOST_NAME_IP, &bstrText);
  260.    if (nResult == S_OK)
  261.    {
  262.       strText = bstrText;
  263.       strcpy(szHostIP, (LPCTSTR)strText);
  264.       ::SysFreeString(bstrText);
  265.    }
  266.    else
  267.    {
  268.       strcpy(szHostIP, UNKNOWN_HOST_IP);
  269.    }
  270. }
  271.  
  272. void CNetCapDlg::GetHostName(short nComputer, char *szHostName)
  273. {
  274.    int     nResult;
  275.    BSTR    bstrText;
  276.    CString strText;
  277.  
  278.     nResult = m_LeadNet.InetGetHostName(nComputer, HOST_NAME_DESCRP, &bstrText);
  279.    if (nResult == S_OK)
  280.    {
  281.       strText = bstrText;
  282.       strText.TrimRight();
  283.       strcpy(szHostName, (LPCTSTR)strText);
  284.       ::SysFreeString(bstrText);
  285.    }
  286.    else
  287.    {
  288.       strcpy(szHostName, "");
  289.    }
  290. }
  291.  
  292. void CNetCapDlg::AppendConnection(short nComputer, int nMode)
  293. {
  294.    char         szHostName[256], szHostIP[20], szText[256];
  295.    int          f = 0;
  296.    HTREEITEM    hRoot, hChild;
  297.    CConnection *pConnection;
  298.  
  299.    GetHostName(nComputer, szHostName);
  300.    GetHostIP(nComputer, szHostIP);
  301.  
  302.    sprintf(szText, "%-15s \"%s\"", szHostIP, szHostName);
  303.  
  304.    if (nMode == CONNECTION_CLIENT)
  305.    {
  306.       hRoot = m_hClientNode;
  307.    }
  308.    else
  309.    {
  310.       hRoot = m_hServerNode;
  311.    }
  312.  
  313.    hChild = m_Node.GetChildItem(hRoot);
  314.  
  315.    while (hChild != NULL)
  316.    {
  317.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  318.  
  319.       if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer))
  320.       {
  321.          f = 1;
  322.          break;
  323.       }
  324.  
  325.       hChild = m_Node.GetNextSiblingItem(hChild);
  326.    }
  327.  
  328.    if (f == 0)
  329.    {
  330.       pConnection = (CConnection *)new CConnection;
  331.       pConnection->m_nComputer = nComputer;
  332.       pConnection->m_pOwner    = this;
  333.       strcpy(pConnection->m_szHostIP, szHostIP);
  334.       strcpy(pConnection->m_szHostName, szHostName);
  335.  
  336.       hChild = m_Node.InsertItem(szText, hRoot, TVI_LAST);
  337.       m_Node.SetItemState(hChild, TVIS_EXPANDED, TVIS_EXPANDED);
  338.       m_Node.SetItemData(hChild, (DWORD)pConnection);
  339.       pConnection->Create(IDD_CONNECTION_DIALOG, this);
  340.       pConnection->SetWindowText(szText);
  341.    }
  342.  
  343.    m_Node.RedrawWindow();
  344.    CountConnections();
  345. }
  346.  
  347. void CNetCapDlg::DeleteConnection(short nComputer)
  348. {
  349.    HTREEITEM    hChild;
  350.    CConnection *pConnection;
  351.  
  352.    hChild = m_Node.GetChildItem(m_hServerNode);
  353.  
  354.    while (hChild != NULL)
  355.    {
  356.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  357.  
  358.       if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer))
  359.       {
  360.          pConnection->DestroyWindow();
  361.          delete pConnection;
  362.          m_Node.DeleteItem(hChild);
  363.          break;
  364.       }
  365.  
  366.       hChild = m_Node.GetNextSiblingItem(hChild);
  367.    }
  368.  
  369.    hChild = m_Node.GetChildItem(m_hClientNode);
  370.  
  371.    while (hChild != NULL)
  372.    {
  373.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  374.  
  375.       if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer))
  376.       {
  377.          pConnection->DestroyWindow();
  378.          delete pConnection;
  379.          m_Node.DeleteItem(hChild);
  380.          break;
  381.       }
  382.  
  383.       hChild = m_Node.GetNextSiblingItem(hChild);
  384.    }
  385.  
  386.    m_Node.RedrawWindow();
  387.    CountConnections();
  388. }
  389.  
  390. void CNetCapDlg::DeleteAllConnections()
  391. {
  392.    HTREEITEM    hChild;
  393.    CConnection *pConnection;
  394.  
  395.    hChild = m_Node.GetChildItem(m_hServerNode);
  396.  
  397.    while (hChild != NULL)
  398.    {
  399.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  400.  
  401.       if (pConnection != NULL)
  402.       {
  403.          pConnection->DestroyWindow();
  404.          delete pConnection;
  405.          m_Node.DeleteItem(hChild);
  406.          hChild = m_Node.GetChildItem(m_hServerNode);
  407.       }
  408.       else
  409.       {
  410.          hChild = m_Node.GetNextSiblingItem(hChild);
  411.       }
  412.    }
  413.  
  414.    hChild = m_Node.GetChildItem(m_hClientNode);
  415.  
  416.    while (hChild != NULL)
  417.    {
  418.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  419.  
  420.       if (pConnection != NULL)
  421.       {
  422.          pConnection->DestroyWindow();
  423.          delete pConnection;
  424.          m_Node.DeleteItem(hChild);
  425.          hChild = m_Node.GetChildItem(m_hClientNode);
  426.       }
  427.       else
  428.       {
  429.          hChild = m_Node.GetNextSiblingItem(hChild);
  430.       }
  431.    }
  432.  
  433.    m_Node.RedrawWindow();
  434.    CountConnections();
  435. }
  436.  
  437. int CNetCapDlg::GetServerConnections()
  438. {
  439.    int       nCount=0;
  440.    HTREEITEM hChild;
  441.  
  442.    hChild = m_Node.GetChildItem(m_hServerNode);
  443.  
  444.    while (hChild != NULL)
  445.    {
  446.       nCount++;
  447.       hChild = m_Node.GetNextSiblingItem(hChild);
  448.    }
  449.  
  450.    return nCount;
  451. }
  452.  
  453. int CNetCapDlg::GetClientConnections()
  454. {
  455.    int       nCount=0;
  456.    HTREEITEM hChild;
  457.  
  458.    hChild = m_Node.GetChildItem(m_hClientNode);
  459.  
  460.    while (hChild != NULL)
  461.    {
  462.       nCount++;
  463.       hChild = m_Node.GetNextSiblingItem(hChild);
  464.    }
  465.  
  466.    return nCount;
  467. }
  468.  
  469. void CNetCapDlg::CountConnections()
  470. {
  471.    char szText[80];
  472.  
  473.    sprintf(szText, "Servers: %d", GetServerConnections());
  474.    m_Node.SetItemText(m_hServerNode, szText);
  475.  
  476.    sprintf(szText, "Clients: %d", GetClientConnections());
  477.    m_Node.SetItemText(m_hClientNode, szText);
  478. }
  479.  
  480. CConnection *CNetCapDlg::FindConnection(short nComputer)
  481. {
  482.    HTREEITEM    hChild;
  483.    CConnection *pConnection;
  484.  
  485.    hChild = m_Node.GetChildItem(m_hServerNode);
  486.  
  487.    while (hChild != NULL)
  488.    {
  489.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  490.  
  491.       if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer))
  492.       {
  493.          return pConnection;
  494.       }
  495.  
  496.       hChild = m_Node.GetNextSiblingItem(hChild);
  497.    }
  498.  
  499.    hChild = m_Node.GetChildItem(m_hClientNode);
  500.  
  501.    while (hChild != NULL)
  502.    {
  503.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  504.  
  505.       if ((pConnection != NULL) && (pConnection->m_nComputer == nComputer))
  506.       {
  507.          return pConnection;
  508.       }
  509.  
  510.       hChild = m_Node.GetNextSiblingItem(hChild);
  511.    }
  512.  
  513.    return NULL;
  514. }
  515.  
  516. short CNetCapDlg::FindConnectionIP(short nComputer)
  517. {
  518.    char         szHostIP[20];
  519.    HTREEITEM    hChild;
  520.    CConnection *pConnection;
  521.  
  522.    GetHostIP(nComputer, szHostIP);
  523.    
  524.    hChild = m_Node.GetChildItem(m_hServerNode);
  525.  
  526.    while (hChild != NULL)
  527.    {
  528.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  529.  
  530.       if ((pConnection != NULL) && (strcmp(pConnection->m_szHostIP, szHostIP) == 0))
  531.       {
  532.          return TRUE;
  533.       }
  534.  
  535.       hChild = m_Node.GetNextSiblingItem(hChild);
  536.    }
  537.  
  538.    hChild = m_Node.GetChildItem(m_hClientNode);
  539.  
  540.    while (hChild != NULL)
  541.    {
  542.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  543.  
  544.       if ((pConnection != NULL) && (strcmp(pConnection->m_szHostIP, szHostIP) == 0))
  545.       {
  546.          return TRUE;
  547.       }
  548.  
  549.       hChild = m_Node.GetNextSiblingItem(hChild);
  550.    }
  551.  
  552.    return FALSE;
  553. }
  554.  
  555. CConnection *CNetCapDlg::GetCurrentConnection()
  556. {
  557.    HTREEITEM    hChild;
  558.    CConnection *pConnection=NULL;
  559.  
  560.    hChild = m_Node.GetSelectedItem();
  561.    
  562.    if (hChild != NULL)
  563.    {
  564.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  565.    }
  566.  
  567.    return pConnection;
  568. }
  569.  
  570. void CNetCapDlg::ShowCurrentConnection() 
  571. {
  572.    char           szText[256];
  573.    unsigned long  nTime;
  574.    CConnection   *pConnection;
  575.  
  576.    pConnection = GetCurrentConnection();
  577.    if (pConnection == NULL)
  578.    {
  579.       SetDlgItemText(IDC_BYTES_SPEED, "");
  580.       m_BytesSpeed.RedrawWindow();
  581.  
  582.       SetDlgItemText(IDC_IMAGES_SPEED, "");
  583.       m_ImagesSpeed.RedrawWindow();
  584.  
  585.       SetDlgItemText(IDC_IMAGES_IN, "");
  586.       m_ImagesIn.RedrawWindow();
  587.  
  588.       SetDlgItemText(IDC_BYTES_IN, "");
  589.       m_BytesIn.RedrawWindow();
  590.  
  591.       SetDlgItemText(IDC_IMAGES_OUT, "");
  592.       m_ImagesOut.RedrawWindow();
  593.  
  594.       SetDlgItemText(IDC_BYTES_OUT, "");
  595.       m_BytesOut.RedrawWindow();
  596.  
  597.       SetDlgItemText(IDC_TIME, "");
  598.       m_Time.RedrawWindow();
  599.  
  600.       return;
  601.    }
  602.    else
  603.    {
  604.       nTime = labs(GetTickCount() - pConnection->m_nTime);
  605.  
  606.       sprintf(szText, "%.2f", ((double)(pConnection->m_nBytesIn + pConnection->m_nBytesOut) / 1024.0) / ((double)nTime / 1000.0));
  607.       SetDlgItemText(IDC_BYTES_SPEED, szText);
  608.       m_BytesSpeed.RedrawWindow();
  609.  
  610.       sprintf(szText, "%.2f", (double)(pConnection->m_nImagesIn + pConnection->m_nImagesOut) / ((double)nTime / 1000.0));
  611.       SetDlgItemText(IDC_IMAGES_SPEED, szText);
  612.       m_ImagesSpeed.RedrawWindow();
  613.  
  614.       sprintf(szText, "%ld", pConnection->m_nImagesIn);
  615.       SetDlgItemText(IDC_IMAGES_IN, szText);
  616.       m_ImagesIn.RedrawWindow();
  617.  
  618.       sprintf(szText, "%ld", pConnection->m_nBytesIn / 1024);
  619.       SetDlgItemText(IDC_BYTES_IN, szText);
  620.       m_BytesIn.RedrawWindow();
  621.  
  622.       sprintf(szText, "%ld", pConnection->m_nImagesOut);
  623.       SetDlgItemText(IDC_IMAGES_OUT, szText);
  624.       m_ImagesOut.RedrawWindow();
  625.  
  626.       sprintf(szText, "%ld", pConnection->m_nBytesOut / 1024);
  627.       SetDlgItemText(IDC_BYTES_OUT, szText);
  628.       m_BytesOut.RedrawWindow();
  629.  
  630.       nTime /= 1000;
  631.       sprintf(szText, "%02ld:%02ld:%02ld", nTime / 3600, (nTime % 3600) / 60, (nTime % 3600) % 60);
  632.       SetDlgItemText(IDC_TIME, szText);
  633.       m_Time.RedrawWindow();
  634.    }
  635. }
  636.  
  637. void CNetCapDlg::DisplayMessage(short iComputer, char *szMessage) 
  638. {
  639.    char       szText[256];
  640.    char       szHostIP[20];
  641.    SYSTEMTIME Time;
  642.  
  643.    TESTEVENT(m_nStatus);
  644.  
  645.    GetHostIP(iComputer, szHostIP);
  646.    
  647.    if (strlen(szHostIP) + strlen(szMessage) + 16 > sizeof(szText))
  648.    {
  649.       return;
  650.    }
  651.    
  652.    GetLocalTime(&Time);
  653.    sprintf(szText, "%02ld:%02ld:%02ld  <%s>:  %s", Time.wHour, Time.wMinute, Time.wSecond, szHostIP, szMessage);
  654.    SetDlgItemText(IDC_MESSAGE, szText);
  655.    m_Message.RedrawWindow();
  656. }
  657.  
  658. /////////////////////////////////////////////////////////////////////////////
  659.  
  660. void CNetCapDlg::OnConnect() 
  661. {
  662.    CString strText;
  663.  
  664.    GetDlgItemText(IDC_COMPUTER, strText);
  665.    m_LeadNet.InetConnect(strText, 1000);
  666. }
  667.  
  668. void CNetCapDlg::Disconnect(short iComputer)
  669. {
  670.    int i;
  671.  
  672.    for (i = 0; i < m_LeadNet.GetSendListNum(); i++)
  673.    {
  674.       if (m_LeadNet.GetSendList(i) == iComputer)
  675.       {
  676.          m_LeadNet.SetSendList(i, 0);
  677.          break;
  678.       }
  679.    }
  680.  
  681.    DeleteConnection(iComputer);
  682.  
  683.    m_LeadNet.InetDisconnect(iComputer);
  684. }
  685.  
  686. void CNetCapDlg::OnDisconnect() 
  687. {
  688.    CConnection *pConnection;
  689.  
  690.    pConnection = GetCurrentConnection();
  691.    
  692.    if (pConnection != NULL)
  693.    {
  694.       Disconnect(pConnection->m_nComputer);
  695.    }
  696. }
  697.  
  698. void CNetCapDlg::OnDisconnectAll() 
  699. {
  700.    HTREEITEM    hChild;
  701.    CConnection *pConnection;
  702.  
  703.    hChild = m_Node.GetChildItem(m_hServerNode);
  704.  
  705.    while (hChild != NULL)
  706.    {
  707.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  708.       
  709.       if (pConnection != NULL)
  710.       {
  711.          Disconnect(pConnection->m_nComputer);
  712.          hChild = m_Node.GetChildItem(m_hServerNode);
  713.       }
  714.       else
  715.       {
  716.          hChild = m_Node.GetNextSiblingItem(hChild);
  717.       }
  718.    }
  719.  
  720.    hChild = m_Node.GetChildItem(m_hClientNode);
  721.  
  722.    while (hChild != NULL)
  723.    {
  724.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  725.  
  726.       if (pConnection != NULL)
  727.       {
  728.          Disconnect(pConnection->m_nComputer);
  729.          hChild = m_Node.GetChildItem(m_hClientNode);
  730.       }
  731.       else
  732.       {
  733.          hChild = m_Node.GetNextSiblingItem(hChild);
  734.       }
  735.    }
  736. }
  737.  
  738. void CNetCapDlg::OnSelchangedNode(NMHDR* pNMHDR, LRESULT* pResult) 
  739. {
  740.     NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  741.    CConnection *pConnection;
  742.  
  743.    TESTEVENT(m_nStatus);
  744.  
  745.    pConnection = GetCurrentConnection();
  746.    if (pConnection == NULL)
  747.    {
  748.       m_Disconnect.EnableWindow(FALSE);
  749.    }
  750.    else
  751.    {
  752.       m_Disconnect.EnableWindow(TRUE);
  753.       SetDlgItemText(IDC_COMPUTER, pConnection->m_szHostIP);
  754.       m_Computer.RedrawWindow();
  755.    }
  756.     
  757.    ShowCurrentConnection();
  758.  
  759.     *pResult = 0;
  760. }
  761.  
  762. void CNetCapDlg::OnServer() 
  763. {
  764.    int nResult;
  765.  
  766.    if ((m_nStatus & STATUS_SERVER) == 0)
  767.    {
  768.        nResult = m_LeadNet.InetServerInit(&m_nServer, 1000);
  769.       if (nResult == S_OK)
  770.       {
  771.          m_Server.SetWindowText("Close Server");
  772.          m_nStatus |= STATUS_SERVER;
  773.       }
  774.    }
  775.    else
  776.    {
  777.       OnDisconnectAll();
  778.    
  779.       nResult = m_LeadNet.InetServerClose(m_nServer);
  780.       if (nResult == S_OK)
  781.       {
  782.          m_Server.SetWindowText("Init Server");
  783.          m_nStatus &= ~STATUS_SERVER;
  784.       }
  785.    }
  786. }
  787.  
  788. /////////////////////////////////////////////////////////////////////////////
  789.  
  790. void CNetCapDlg::OnInetReceiveBitmap(short iComputer, long hBitmap) 
  791. {
  792.    CConnection *pConnection;
  793.  
  794.    TESTEVENT(m_nStatus);
  795.  
  796.    pConnection = FindConnection(iComputer);
  797.    if (pConnection != NULL)
  798.    {
  799.       CRect rcWindow, rcClient, rcLead;
  800.       int   nWidth, nHeight, nDeltaWidth, nDeltaHeight;
  801.     
  802.       pConnection->m_Lead.SetBitmap(hBitmap);
  803.  
  804.       rcLead = CRect(0, 0, (int)pConnection->m_Lead.GetBitmapWidth(), (int)pConnection->m_Lead.GetBitmapHeight());
  805.       pConnection->GetWindowRect(rcWindow);
  806.       pConnection->GetClientRect(rcClient);
  807.       nDeltaWidth = rcWindow.Width() - rcClient.Width();
  808.       nDeltaHeight = rcWindow.Height() - rcClient.Height();
  809.       nWidth = rcLead.Width() + nDeltaWidth;
  810.       nHeight = rcLead.Height() + nDeltaHeight;
  811.    
  812.       if ((nWidth != rcClient.Width()) || (nHeight != rcClient.Height()))
  813.       {
  814.          pConnection->MoveWindow(rcWindow.TopLeft().x, rcWindow.TopLeft().y, nWidth, nHeight, TRUE);
  815.       }
  816.       
  817.       pConnection->m_Lead.RedrawWindow();
  818.  
  819.       pConnection->m_nImagesIn++;
  820.    }
  821. }
  822.  
  823. void CNetCapDlg::OnInetReceiveData(short iComputer, const VARIANT FAR& pData, long lSize, short iType) 
  824. {
  825.    TESTEVENT(m_nStatus);
  826.  
  827.    if (iType == IDATA_USER2)
  828.    {
  829.       DisplayMessage(iComputer, (char far *)((V_ARRAY(&pData))->pvData));
  830.    }
  831. }
  832.  
  833. void CNetCapDlg::OnInetConnected(short iComputer) 
  834. {
  835.    TESTEVENT(m_nStatus);
  836.  
  837.    m_LeadNet.SetSendList(m_LeadNet.GetSendListNum(), iComputer);
  838.  
  839.    AppendConnection(iComputer, CONNECTION_SERVER);
  840. }
  841.  
  842. void CNetCapDlg::OnInetDisconnected(short iComputer) 
  843. {
  844.    TESTEVENT(m_nStatus);
  845.  
  846.    DeleteConnection(iComputer);
  847. }
  848.  
  849. void CNetCapDlg::OnInetAccept(short iServer) 
  850. {
  851.    short iComputer;
  852.    int   nResult;
  853.  
  854.    TESTEVENT(m_nStatus);
  855.  
  856.    nResult = m_LeadNet.InetAcceptConnect(iServer, &iComputer);
  857.    if (nResult == S_OK)
  858.    {
  859.          m_LeadNet.SetSendList(m_LeadNet.GetSendListNum(), iComputer);
  860.       AppendConnection(iComputer, CONNECTION_CLIENT);
  861.    }
  862. }
  863.  
  864. void CNetCapDlg::OnInetError(short iComputer, short iMessage, short iError) 
  865. {
  866.    char szText[80];
  867.  
  868.    TESTEVENT(m_nStatus);
  869.  
  870.    sprintf(szText, "Error %d (%d)", iError, iMessage);
  871.  
  872.    DisplayMessage(iComputer, szText);
  873.  
  874.    if (iError == ERROR_CONNECT_RESET)
  875.    {
  876.       Disconnect(iComputer);
  877.    }
  878. }
  879.  
  880. void CNetCapDlg::OnInetReceiveStart(short iComputer, long lSize) 
  881. {
  882.    CConnection *pConnection;
  883.  
  884.    TESTEVENT(m_nStatus);
  885.  
  886.    pConnection = FindConnection(iComputer);
  887.    if (pConnection != NULL)
  888.    {
  889.       pConnection->m_nBytesIn += lSize;
  890.       pConnection->m_nTimeout  = GetTickCount();
  891.    }
  892. }
  893.  
  894. void CNetCapDlg::OnInetReceiving(short iComputer, long lSize) 
  895. {
  896.    TESTEVENT(m_nStatus);
  897. }
  898.  
  899. void CNetCapDlg::OnInetDataSent(short iComputer, long lSize) 
  900. {
  901.    CConnection *pConnection;
  902.  
  903.    TESTEVENT(m_nStatus);
  904.  
  905.    pConnection = FindConnection(iComputer);
  906.    if (pConnection != NULL)
  907.    {
  908.       pConnection->m_nBytesOut += lSize;
  909.       pConnection->m_nTimeout   = GetTickCount();
  910.    }
  911. }
  912.  
  913. void CNetCapDlg::OnInetSending(short iComputer, long lSize) 
  914. {
  915.    TESTEVENT(m_nStatus);
  916. }
  917.  
  918. 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) 
  919. {
  920.    int             nResult;
  921.    VARIANT         var;
  922.    SAFEARRAY FAR  *psa;
  923.    SAFEARRAYBOUND  rgsabound[1];
  924.  
  925.    TESTEVENT(m_nStatus);
  926.  
  927.    if (m_PlaySound.GetCheck() == FALSE)
  928.    {
  929.       CloseSoundPlay();
  930.       return;
  931.    }
  932.  
  933.    if (m_nStatus & STATUS_SOUND_PLAY)
  934.    {
  935.       if ((m_LeadCap.GetCapWaveFormatTag(CAP_AUDIO_FEED) != iFormatTag) ||
  936.           (m_LeadCap.GetCapWaveChannels(CAP_AUDIO_FEED) != nChannels) ||
  937.           (m_LeadCap.GetCapWaveSamplesPerSec(CAP_AUDIO_FEED) != lSamplesPerSec) ||
  938.           (m_LeadCap.GetCapWaveAvgBytesPerSec(CAP_AUDIO_FEED) != lAvgBytesPerSec) ||
  939.           (m_LeadCap.GetCapWaveBlockAlign(CAP_AUDIO_FEED) != iBlockAlign) ||
  940.           (m_LeadCap.GetCapWaveBitsPerSample(CAP_AUDIO_FEED) != iBitsPerSample) ||
  941.           (m_LeadCap.GetCapWaveExtraSize(CAP_AUDIO_FEED) != iExtraDataSize))
  942.       {
  943.          CloseSoundPlay();
  944.       }
  945.    }
  946.  
  947.    if ((m_nStatus & STATUS_SOUND_PLAY) == 0)
  948.    {
  949.       if ((m_nWaveFormatTag != iFormatTag) ||
  950.          (m_nWaveChannels != nChannels) ||
  951.          (m_nWaveSamplesPerSec != lSamplesPerSec) ||
  952.          (m_nWaveAvgBytesPerSec != lAvgBytesPerSec) ||
  953.          (m_nWaveBlockAlign != iBlockAlign) ||
  954.          (m_nWaveBitsPerSample != iBitsPerSample) ||
  955.          (m_nWaveExtraSize != iExtraDataSize))
  956.       {
  957.          m_LeadCap.SetCapWaveFormatTag(CAP_AUDIO_FEED, iFormatTag);
  958.          m_LeadCap.SetCapWaveChannels(CAP_AUDIO_FEED, nChannels);
  959.          m_LeadCap.SetCapWaveSamplesPerSec(CAP_AUDIO_FEED, lSamplesPerSec);
  960.          m_LeadCap.SetCapWaveAvgBytesPerSec(CAP_AUDIO_FEED, lAvgBytesPerSec);
  961.          m_LeadCap.SetCapWaveBlockAlign(CAP_AUDIO_FEED, iBlockAlign);
  962.          m_LeadCap.SetCapWaveBitsPerSample(CAP_AUDIO_FEED, iBitsPerSample);
  963.          m_LeadCap.SetCapWaveExtraSize(CAP_AUDIO_FEED, iExtraDataSize);
  964.          m_LeadCap.SetCapWaveExtraData(CAP_AUDIO_FEED, pExtraData);
  965.  
  966.          m_nWaveFormatTag      = iFormatTag;
  967.          m_nWaveChannels       = nChannels;
  968.          m_nWaveSamplesPerSec  = lSamplesPerSec;
  969.          m_nWaveAvgBytesPerSec = lAvgBytesPerSec;
  970.          m_nWaveBlockAlign     = iBlockAlign;
  971.          m_nWaveBitsPerSample  = iBitsPerSample;
  972.          m_nWaveExtraSize      = iExtraDataSize;
  973.  
  974.          nResult = m_LeadCap.CapStartFeedSound("", -1, 0, CAP_FEED_PLAYDATA, &m_hSound);
  975.          if (nResult == S_OK)
  976.          {
  977.             m_nStatus |= STATUS_SOUND_PLAY;
  978.          }
  979.          else
  980.          if (nResult == ERROR_WAVE_FORMAT)
  981.          {
  982.             DisplayMessage(iComputer, ERROR_SOUND_FORMAT);
  983.  
  984.             VariantInit(&var);
  985.             rgsabound[0].lLbound = 0;
  986.             rgsabound[0].cElements = strlen(ERROR_SOUND_FORMAT) + 1;
  987.             
  988.             psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
  989.             if (psa != NULL)
  990.             {
  991.                SafeArrayLock(psa);
  992.                strcpy((char far *)psa->pvData, ERROR_SOUND_FORMAT);
  993.                SafeArrayUnlock(psa);
  994.                V_VT(&var) = (VT_ARRAY | VT_UI1);
  995.                V_ARRAY(&var) = psa;
  996.                 m_LeadNet.InetSendData(&var, strlen(ERROR_SOUND_FORMAT) + 1, IDATA_USER2);
  997.                SafeArrayDestroy(psa);
  998.             }
  999.  
  1000.             VariantClear(&var);
  1001.          }
  1002.          else
  1003.          {
  1004.             m_nWaveFormatTag      = -1;
  1005.             m_nWaveChannels       = -1;
  1006.             m_nWaveSamplesPerSec  = -1;
  1007.             m_nWaveAvgBytesPerSec = -1;
  1008.             m_nWaveBlockAlign     = -1;
  1009.             m_nWaveBitsPerSample  = -1;
  1010.             m_nWaveExtraSize      = -1;
  1011.          }
  1012.       }
  1013.    }
  1014.    else
  1015.    {
  1016.       m_LeadCap.CapFeedSound(m_hSound, (VARIANT *)&pData, lDataSize);
  1017.    }
  1018. }
  1019.  
  1020. /////////////////////////////////////////////////////////////////////////////
  1021.  
  1022. void CNetCapDlg::OnAudioFormat() 
  1023. {
  1024.    CloseSoundSend();
  1025.  
  1026.    m_LeadCap.CapDisplayDialog(DLG_AUDFORMAT, CAP_AUDIO_RECORD, CAP_AUDIO_CHOOSE_OUTPUT);
  1027.  
  1028.    if (m_SendSound.GetCheck())
  1029.    {
  1030.       OpenSoundSend();
  1031.    }
  1032. }
  1033.  
  1034. void CNetCapDlg::OnVideoFormat() 
  1035. {
  1036.    m_LeadCap.CapDisplayDialog(DLG_VIDFORMAT, 0, 0);
  1037. }
  1038.  
  1039. void CNetCapDlg::OnVideoCompression() 
  1040. {
  1041.    m_LeadCap.CapDisplayDialog(DLG_VIDCOMP, 0, 0);
  1042. }
  1043.  
  1044. void CNetCapDlg::OnVideoSource() 
  1045. {
  1046.    m_LeadCap.CapDisplayDialog(DLG_VIDSOURCE, 0, 0);
  1047. }
  1048.  
  1049. void CNetCapDlg::TestQueue() 
  1050. {
  1051.    int  i, nComputer;
  1052.    long nSize;
  1053.  
  1054.    for (i = 0; i < m_LeadNet.GetSendListNum(); i++)
  1055.    {
  1056.       nComputer = m_LeadNet.GetSendList(i);
  1057.       nSize     = m_LeadNet.GetInetQueueSize(nComputer) / 1024;
  1058.  
  1059.       if (nSize > QUEUE_MAX)
  1060.       {
  1061.          m_LeadNet.InetClearQueue(nComputer);
  1062.       }
  1063.    }
  1064. }
  1065.  
  1066. void CNetCapDlg::OnCapVideoData(long hDib, long lTime) 
  1067. {
  1068.    HTREEITEM    hChild;
  1069.    CConnection *pConnection;
  1070.  
  1071.    TESTEVENT(m_nStatus);
  1072.  
  1073.    if (m_SendBitmap.GetCheck() == FALSE)
  1074.    {
  1075.       return;
  1076.    }
  1077.  
  1078.    hChild = m_Node.GetChildItem(m_hServerNode);
  1079.  
  1080.    while (hChild != NULL)
  1081.    {
  1082.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  1083.  
  1084.       if (pConnection != NULL)
  1085.       {
  1086.          pConnection->m_nImagesOut++;
  1087.       }
  1088.  
  1089.       hChild = m_Node.GetNextSiblingItem(hChild);
  1090.    }
  1091.  
  1092.    hChild = m_Node.GetChildItem(m_hClientNode);
  1093.  
  1094.    while (hChild != NULL)
  1095.    {
  1096.       pConnection = (CConnection *)m_Node.GetItemData(hChild);
  1097.  
  1098.       if (pConnection != NULL)
  1099.       {
  1100.          pConnection->m_nImagesOut++;
  1101.       }
  1102.  
  1103.       hChild = m_Node.GetNextSiblingItem(hChild);
  1104.    }
  1105.  
  1106.    m_LeadNet.InetSendDIB(hDib, FILE_CMP, 24, -5);
  1107. }
  1108.  
  1109. void CNetCapDlg::OnCapAudioData(const VARIANT FAR& pData, long lBytesRecorded, short iIndex) 
  1110. {
  1111.    VARIANT var;
  1112.  
  1113.    TESTEVENT(m_nStatus);
  1114.  
  1115.    if (iIndex != CAP_AUDIO_RECORD)
  1116.    {
  1117.       return;
  1118.    }
  1119.  
  1120.    if (m_SendSound.GetCheck() == FALSE)
  1121.    {
  1122.       return;
  1123.    }
  1124.  
  1125.    TestQueue();
  1126.  
  1127.    var = m_LeadCap.GetCapWaveExtraData(CAP_AUDIO_RECORD);
  1128.  
  1129.    m_LeadNet.InetSendSound(m_LeadCap.GetCapWaveFormatTag(CAP_AUDIO_RECORD),
  1130.                            m_LeadCap.GetCapWaveChannels(CAP_AUDIO_RECORD),
  1131.                            m_LeadCap.GetCapWaveSamplesPerSec(CAP_AUDIO_RECORD),
  1132.                            m_LeadCap.GetCapWaveAvgBytesPerSec(CAP_AUDIO_RECORD),
  1133.                            m_LeadCap.GetCapWaveBlockAlign(CAP_AUDIO_RECORD),
  1134.                            m_LeadCap.GetCapWaveBitsPerSample(CAP_AUDIO_RECORD),
  1135.                            (short)m_LeadCap.GetCapWaveExtraSize(CAP_AUDIO_RECORD),
  1136.                            &var,
  1137.                            (VARIANT *)&pData, 
  1138.                            lBytesRecorded);
  1139.  
  1140.    VariantClear(&var);
  1141. }
  1142.  
  1143. void CNetCapDlg::OnCapDriver(short iDriver, LPCTSTR pszName) 
  1144. {
  1145.    int nResult;
  1146.  
  1147.    if (m_nStatus & STATUS_CAPTURE)
  1148.    {
  1149.       return;
  1150.    }
  1151.  
  1152.    nResult = m_LeadCap.CapConnect(iDriver);
  1153.    if (nResult == S_OK)
  1154.    {
  1155.       m_nStatus |= STATUS_CAPTURE;
  1156.    }
  1157. }
  1158.  
  1159. void CNetCapDlg::OnSendSound() 
  1160. {
  1161.    if (m_SendSound.GetCheck())
  1162.    {
  1163.       OpenSoundSend();
  1164.    }
  1165.    else
  1166.    {
  1167.       CloseSoundSend();
  1168.    }
  1169. }
  1170.  
  1171. void CNetCapDlg::OnPlaySound() 
  1172. {
  1173.    if (m_PlaySound.GetCheck() == FALSE)
  1174.    {
  1175.       CloseSoundPlay();
  1176.    }
  1177. }
  1178.  
  1179. void CNetCapDlg::OpenSoundSend() 
  1180. {
  1181.    int nResult;
  1182.  
  1183.    if (m_nStatus & STATUS_SOUND_SEND)
  1184.    {
  1185.       return;
  1186.    }
  1187.  
  1188.    TestQueue();
  1189.  
  1190.    nResult = m_LeadCap.CapOpenRecord(-1, 0, m_LeadCap.GetCapWaveAvgBytesPerSec(CAP_AUDIO_RECORD));
  1191.    if (nResult == S_OK)
  1192.    {
  1193.        m_LeadCap.CapStartRecord();
  1194.       m_nStatus |= STATUS_SOUND_SEND;
  1195.    }
  1196. }
  1197.  
  1198. void CNetCapDlg::CloseSoundSend() 
  1199. {
  1200.    if ((m_nStatus & STATUS_SOUND_SEND) == 0)
  1201.    {
  1202.       return;
  1203.    }
  1204.  
  1205.    m_LeadCap.CapStopRecord();
  1206.     m_LeadCap.CapCloseRecord();
  1207.    m_nStatus &= ~STATUS_SOUND_SEND;
  1208. }
  1209.  
  1210. void CNetCapDlg::CloseSoundPlay() 
  1211. {
  1212.    if ((m_nStatus & STATUS_SOUND_PLAY) == 0)
  1213.    {
  1214.       return;
  1215.    }
  1216.  
  1217.    m_LeadCap.CapStopFeedSound(m_hSound, FALSE);
  1218.    m_nStatus &= ~STATUS_SOUND_PLAY;
  1219. }
  1220.  
  1221. void CNetCapDlg::OpenCapture() 
  1222. {
  1223.    m_LeadCap.CapEnumDrivers();
  1224. }
  1225.  
  1226. void CNetCapDlg::CloseCapture() 
  1227. {
  1228.    if ((m_nStatus & STATUS_CAPTURE) == 0)
  1229.    {
  1230.       return;
  1231.    }
  1232.  
  1233.    m_LeadCap.CapDisconnect();
  1234.    m_nStatus &= ~STATUS_CAPTURE;
  1235. }
  1236.  
  1237. void CNetCapDlg::OnTimer(UINT nIDEvent) 
  1238. {
  1239.    int          i;
  1240.    CConnection *pConnection;
  1241.    
  1242.    for (i = 0; i < m_LeadNet.GetSendListNum(); i++)
  1243.    {
  1244.       pConnection = FindConnection(m_LeadNet.GetSendList(i));
  1245.  
  1246.       if (pConnection != NULL)
  1247.       {
  1248.          if (labs(pConnection->m_nTimeout - GetTickCount()) / 1000 > TIMER_TIMEOUT)
  1249.          {
  1250.             DeleteConnection(pConnection->m_nComputer);
  1251.             i = -1;
  1252.          }
  1253.       }
  1254.    }
  1255.    
  1256.    ShowCurrentConnection();
  1257.  
  1258.     CDialog::OnTimer(nIDEvent);
  1259. }
  1260.