home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / video / captest / dialogs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  25.5 KB  |  631 lines

  1. /****************************************************************************
  2.  *
  3.  *   dialogs.c: Code for dialog procs of CapTest Sample Program
  4.  *
  5.  *   Microsoft Video for Windows Capture Class Test Program
  6.  *
  7.  ***************************************************************************/
  8. /**************************************************************************
  9.  *
  10.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13.  *  PURPOSE.
  14.  *
  15.  *  Copyright (C) 1992 - 1997 Microsoft Corporation.  All Rights Reserved.
  16.  *
  17.  **************************************************************************/
  18.  
  19. #define INC_OLE2
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #include <commdlg.h>
  23. #include <vfw.h>
  24. #include <mmreg.h>
  25. #include <io.h>
  26. #include <fcntl.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <memory.h>
  30. #include <dos.h>
  31.  
  32. #include "captest.h"
  33.  
  34. static long GetFreeDiskSpace(WORD) ;
  35. static int  CountMCIDevices(WORD) ;
  36.  
  37. //
  38. // AboutProc: About Dialog Box Procedure
  39. //
  40. int FAR PASCAL AboutProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam)
  41. {
  42.     switch (Message) {
  43.         case WM_INITDIALOG :
  44.              return TRUE ;
  45.  
  46.         case WM_COMMAND :
  47.             switch (wParam) {
  48.                 case IDOK :
  49.                     EndDialog(hDlg, TRUE) ;
  50.                     return TRUE ;
  51.  
  52.                 case IDCANCEL :
  53.                     EndDialog(hDlg, FALSE) ;
  54.                     return TRUE ;
  55.             }
  56.             break ;
  57.     }
  58.  
  59.     return FALSE ;
  60. }
  61.  
  62.  
  63. //
  64. // AudioFormatProc: Audio Format Setting Dialog Box Procedure
  65. //
  66. int FAR PASCAL AudioFormatProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam)
  67. {
  68.     static int                nChannels ;
  69.     static WORD               wSample ;
  70.     static DWORD              dwFrequency ;
  71.  
  72.     switch (Message) {
  73.         case WM_INITDIALOG :
  74.             nChannels = IDD_ChannelIDs + glpwfex->nChannels ;
  75.             CheckRadioButton(hDlg, IDD_ChannelMono, IDD_ChannelStereo, nChannels) ;
  76.             wSample = IDD_SampleIDs + glpwfex->wBitsPerSample / 8 ;
  77.             CheckRadioButton(hDlg, IDD_Sample8Bit, IDD_Sample16Bit, wSample) ;
  78.             dwFrequency = IDD_FreqIDs + glpwfex->nSamplesPerSec / 11025 ;
  79.             CheckRadioButton(hDlg, IDD_Freq11kHz, IDD_Freq44kHz, (WORD)dwFrequency) ;
  80.             return TRUE ;
  81.  
  82.         case WM_COMMAND :
  83.             switch (wParam) {
  84.                 case IDOK :
  85.                     if (IsDlgButtonChecked(hDlg, IDD_ChannelMono))
  86.                         nChannels = 1 ;
  87.                     else
  88.                         if (IsDlgButtonChecked(hDlg, IDD_ChannelStereo))
  89.                             nChannels = 2 ;
  90.                         else {
  91.                             MessageBeep(MB_ICONEXCLAMATION) ;
  92.                             return FALSE ;
  93.                         }
  94.  
  95.                     if (IsDlgButtonChecked(hDlg, IDD_Sample8Bit))
  96.                         wSample = 8 ;
  97.                     else
  98.                         if (IsDlgButtonChecked(hDlg, IDD_Sample16Bit))
  99.                             wSample = 16 ;
  100.                         else {
  101.                             MessageBeep(MB_ICONEXCLAMATION) ;
  102.                             return FALSE ;
  103.                         }
  104.  
  105.                     if (IsDlgButtonChecked(hDlg, IDD_Freq11kHz))
  106.                         dwFrequency = 11025 ;
  107.                     else
  108.                         if (IsDlgButtonChecked(hDlg, IDD_Freq22kHz))
  109.                             dwFrequency = 22050 ;
  110.                         else
  111.                             if (IsDlgButtonChecked(hDlg, IDD_Freq44kHz))
  112.                                 dwFrequency = 44100 ;
  113.                             else {
  114.                                 MessageBeep(MB_ICONEXCLAMATION) ;
  115.                                 return FALSE ;
  116.                             }
  117.  
  118.                     // All the entries verfied OK -- save them now
  119.                     glpwfex->nChannels = nChannels ;
  120.                     glpwfex->wBitsPerSample = wSample ;
  121.                     glpwfex->nSamplesPerSec = dwFrequency ;
  122.                     glpwfex->nBlockAlign =  glpwfex->nChannels * (glpwfex->wBitsPerSample / 8) ;
  123.                     glpwfex->nAvgBytesPerSec = (long) glpwfex->nSamplesPerSec *
  124.                                                       glpwfex->nBlockAlign ;
  125.                     glpwfex->cbSize = 0 ;
  126.                     glpwfex->wFormatTag = WAVE_FORMAT_PCM ;
  127.                     EndDialog(hDlg, TRUE) ;
  128.                     return TRUE ;
  129.  
  130.                 case IDCANCEL :
  131.                     EndDialog(hDlg, FALSE) ;
  132.                     return TRUE ;
  133.             }
  134.             break ;
  135.     }
  136.  
  137.     return FALSE ;
  138. }
  139.  
  140.  
  141. //
  142. // GetFreeDiskSpaceInKB: Function to Measure Available Disk Space
  143. //
  144. static long GetFreeDiskSpaceInKB(LPTSTR pFile)
  145. {
  146.     DWORD dwFreeClusters, dwBytesPerSector, dwSectorsPerCluster, dwClusters;
  147.     char RootName[MAX_PATH];
  148.     LPSTR ptmp;    //required arg
  149.  
  150.     // need to find path for root directory on drive containing
  151.     // this file.
  152.  
  153.     GetFullPathName(pFile, sizeof(RootName)/sizeof(RootName[0]), RootName, &ptmp);
  154.  
  155.     // truncate this to the name of the root directory (god how tedious)
  156.     if ((RootName[0] == TEXT('\\')) && (RootName[1] == TEXT('\\'))) {
  157.  
  158.         // path begins with  \\server\share\path so skip the first
  159.         // three backslashes
  160.         ptmp = &RootName[2];
  161.         while (*ptmp && (*ptmp != TEXT('\\'))) {
  162.             ptmp++;
  163.         }
  164.         if (*ptmp) {
  165.             // advance past the third backslash
  166.             ptmp++;
  167.         }
  168.     } else {
  169.         // path must be drv:\path
  170.         ptmp = RootName;
  171.     }
  172.  
  173.     // find next backslash and put a null after it
  174.     while (*ptmp && (*ptmp != TEXT('\\'))) {
  175.         ptmp++;
  176.     }
  177.     // found a backslash ?
  178.     if (*ptmp) {
  179.         // skip it and insert null
  180.         ptmp++;
  181.         *ptmp = TEXT('\0');
  182.     }
  183.  
  184.  
  185.  
  186.     if (!GetDiskFreeSpace(RootName,
  187.         &dwSectorsPerCluster,
  188.         &dwBytesPerSector,
  189.         &dwFreeClusters,
  190.         &dwClusters)) {
  191.         MessageBox(NULL, TEXT("Can't measure free disk space."), TEXT("Error"),
  192.                 MB_OK | MB_ICONINFORMATION);
  193.         return (-1);
  194.     }
  195.     return(MulDiv (dwSectorsPerCluster * dwBytesPerSector,
  196.            dwFreeClusters,
  197.            1024));
  198. }
  199.  
  200.  
  201.  
  202. //
  203. // AllocCapFileProc: Capture file Space Allocation Dialog Box Procedure
  204. //
  205. int FAR PASCAL AllocCapFileProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam)
  206. {
  207.     static int      nFreeMBs = 0 ;
  208.  
  209.     switch (Message) {
  210.         case WM_INITDIALOG :
  211.         {
  212.             long             lFileSize = 0 ;
  213.             long             lFreeSpaceInKB ;
  214.             TCHAR         achCapFile[_MAX_PATH] ;
  215.             HANDLE           hFile;
  216.  
  217.             // Get current capture file name and measure its size
  218.             capFileGetCaptureFile(ghWndCap, achCapFile, sizeof(achCapFile) / sizeof(TCHAR)) ;
  219.             hFile = CreateFile(
  220.                             achCapFile,
  221.                             GENERIC_READ,
  222.                             0,
  223.                             NULL,
  224.                             OPEN_EXISTING,
  225.                             FILE_ATTRIBUTE_NORMAL,
  226.                             NULL);
  227.             if (hFile != INVALID_HANDLE_VALUE) {
  228.                 if ((lFileSize = GetFileSize(hFile, NULL)) == -1) {
  229.                     MessageBox(NULL, TEXT("Couldn't find size of current capture file"),
  230.                             TEXT("ERROR"),
  231.                             MB_OK | MB_ICONEXCLAMATION);
  232.                     lFileSize = 0;
  233.                 }
  234.                 CloseHandle(hFile);
  235.             }
  236.  
  237.             // Get free disk space and add current capture file size to that.
  238.             // Convert the available space to MBs.
  239.             if ((lFreeSpaceInKB = GetFreeDiskSpaceInKB(achCapFile)) != -1L) {
  240.                 lFreeSpaceInKB += lFileSize / 1024 ;
  241.                 nFreeMBs = lFreeSpaceInKB / 1024 ;
  242.                 SetDlgItemInt(hDlg, IDD_SetCapFileFree, nFreeMBs, TRUE) ;
  243.             } else {
  244.  
  245.                 EnableWindow(GetDlgItem(hDlg, IDD_SetCapFileFree), FALSE);
  246.  
  247.             }
  248.  
  249.             gwCapFileSize = (WORD) (lFileSize / ONEMEG);
  250.  
  251.             SetDlgItemInt(hDlg, IDD_SetCapFileSize, gwCapFileSize, TRUE) ;
  252.             return TRUE ;
  253.         }
  254.  
  255.         case WM_COMMAND :
  256.             switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  257.                 case IDOK :
  258.                 {
  259.                     int         iCapFileSize ;
  260.  
  261.                     iCapFileSize = (int) GetDlgItemInt(hDlg, IDD_SetCapFileSize, NULL, TRUE) ;
  262.                     if (iCapFileSize <= 0 || iCapFileSize > nFreeMBs) {
  263.                         // You are asking for more than we have !! Sorry, ...
  264.                         SetDlgItemInt(hDlg, IDD_SetCapFileSize, iCapFileSize, TRUE) ;
  265.                         SetFocus(GetDlgItem(hDlg, IDD_SetCapFileSize)) ;
  266.                         MessageBeep(MB_ICONEXCLAMATION) ;
  267.                         return FALSE ;
  268.                     }
  269.                     gwCapFileSize = iCapFileSize ;
  270.  
  271.                     EndDialog(hDlg, TRUE) ;
  272.                     return TRUE ;
  273.                 }
  274.  
  275.                 case IDCANCEL :
  276.                     EndDialog(hDlg, FALSE) ;
  277.                     return TRUE ;
  278.  
  279.                 case IDD_SetCapFileSize:
  280.                 {
  281.                     long l;
  282.                     BOOL bchanged;
  283.                     char achBuffer[21];
  284.  
  285.                     // check that entered size is a valid number
  286.                     GetDlgItemText(hDlg, IDD_SetCapFileSize, achBuffer, sizeof(achBuffer));
  287.                     l = atol(achBuffer);
  288.                     bchanged = FALSE;
  289.                     if (l < 1) {
  290.                         l = 1;
  291.                         bchanged = TRUE;
  292.                     } else if (l > nFreeMBs) {
  293.                         l = nFreeMBs;
  294.                         bchanged = TRUE;
  295.                     } else {
  296.                         // make sure there are no non-digit chars
  297.                         // atol() will ignore trailing non-digit characters
  298.                         int c = 0;
  299.                         while (achBuffer[c]) {
  300.                             if (IsCharAlpha(achBuffer[c]) ||
  301.                                 !IsCharAlphaNumeric(achBuffer[c])) {
  302.  
  303.                                 // string contains non-digit chars - reset
  304.                                 l = 1;
  305.                                 bchanged = TRUE;
  306.                                 break;
  307.                             }
  308.                             c++;
  309.                         }
  310.                     }
  311.                     if (bchanged) {
  312.                         wsprintf(achBuffer, "%ld", l);
  313.                         SetDlgItemText(hDlg, IDD_SetCapFileSize, achBuffer);
  314.                     }
  315.                     break;
  316.                 }
  317.             }
  318.             break ;
  319.     }
  320.  
  321.     return FALSE ;
  322.  
  323. }
  324.  
  325. //
  326. // MakePaletteProc: Palette Details Dialog Box Procedure
  327. //
  328. BOOL CALLBACK MakePaletteProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam)
  329. {
  330.     switch (Message) {
  331.         case WM_INITDIALOG :
  332.             SetDlgItemInt(hDlg, IDD_MakePalColors, gwPalColors, FALSE) ;
  333.             SetDlgItemInt(hDlg, IDD_MakePalFrames, gwPalFrames, FALSE) ;
  334.             return TRUE ;
  335.  
  336.         case WM_COMMAND :
  337.             switch (wParam) {
  338.                 case IDOK :
  339.                 {
  340.                     int         iColors ;
  341.                     int         iFrames ;
  342.  
  343.                     iColors = (int) GetDlgItemInt(hDlg, IDD_MakePalColors, NULL, TRUE) ;
  344.                     if (! (iColors > 0 && iColors <= 236 || iColors == 256)) {
  345.                         // invalid number of palette colors
  346.                         SetDlgItemInt(hDlg, IDD_MakePalColors, iColors, TRUE) ;
  347.                         SetFocus(GetDlgItem(hDlg, IDD_MakePalColors)) ;
  348.                         MessageBeep(MB_ICONEXCLAMATION) ;
  349.                         return FALSE ;
  350.                     }
  351.                     iFrames = (int) GetDlgItemInt(hDlg, IDD_MakePalFrames, NULL, TRUE) ;
  352.                     if (iFrames <= 0 || iFrames > 10000) {
  353.                         // no frame or way t-o-o many frames !!!
  354.                         SetDlgItemInt(hDlg, IDD_MakePalFrames, iFrames, TRUE) ;
  355.                         SetFocus(GetDlgItem(hDlg, IDD_MakePalFrames)) ;
  356.                         MessageBeep(MB_ICONEXCLAMATION) ;
  357.                         return FALSE ;
  358.                     }
  359.                     gwPalColors = iColors ;
  360.                     gwPalFrames = iFrames ;
  361.  
  362.                     EndDialog(hDlg, TRUE) ;
  363.                     return TRUE ;
  364.                 }
  365.  
  366.                 case IDCANCEL :
  367.                     EndDialog(hDlg, FALSE) ;
  368.                     return TRUE ;
  369.             }
  370.             break ;
  371.     }
  372.  
  373.     return FALSE ;
  374.  
  375. }
  376.  
  377.  
  378. //
  379. // CountMCIDevices: Function to Find the Number of MCI Devices of a Type
  380. //
  381. static int CountMCIDevices(WORD wType)
  382. {
  383.     int               nTotal = 0 ;
  384.     DWORD             dwCount ;
  385.     MCI_SYSINFO_PARMS mciSIP ;
  386.  
  387.     mciSIP.dwCallback = 0 ;
  388.     mciSIP.lpstrReturn = (LPTSTR)(LPVOID) &dwCount ;
  389.     mciSIP.dwRetSize = sizeof(DWORD) ;
  390.     mciSIP.wDeviceType = wType ;
  391.  
  392.     // Use an MCI command to get the info
  393.     if (! mciSendCommand(0, MCI_SYSINFO, MCI_SYSINFO_QUANTITY,
  394.                          (DWORD)(LPVOID) &mciSIP))
  395.         nTotal = (int) *((LPDWORD) mciSIP.lpstrReturn) ;
  396.  
  397.     return nTotal ;
  398. }
  399.  
  400.  
  401. //
  402. // CapSetUpProc: Capture SetUp Details Dialog Box Procedure
  403. //
  404. int FAR PASCAL CapSetUpProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam)
  405. {
  406.     BOOL            fValue ;
  407.     static TCHAR     achBuffer[21] ;
  408.  
  409.     switch (Message) {
  410.         case WM_INITDIALOG :
  411.         {
  412.             WORD        wValue ;
  413.  
  414.             // Convert from MicroSecPerFrame to FPS -- that's easier !!
  415.             wValue = (int) (1E+6 / gCapParms.dwRequestMicroSecPerFrame + 0.5) ;
  416.             SetDlgItemInt(hDlg, IDD_FrameRateData, wValue, FALSE) ;
  417.             if (gCapParms.fAbortLeftMouse)
  418.                 wValue = IDD_AbortLeftFlag ;
  419.             else
  420.                 if (gCapParms.fAbortRightMouse)
  421.                     wValue = IDD_AbortRightFlag ;
  422.                 else
  423.                     wValue = 0 ;  // none of the mouse-buttons !!!
  424.             CheckRadioButton(hDlg, IDD_AbortLeftFlag, IDD_AbortRightFlag, wValue) ;
  425.  
  426.             if (gCapParms.vKeyAbort == VK_ESCAPE)
  427.                 wValue = IDD_AbortEscFlag ;
  428.             else
  429.                 if (gCapParms.vKeyAbort == VK_SPACE)
  430.                     wValue = IDD_AbortSpaceFlag ;
  431.                 else
  432.                     if (gCapParms.vKeyAbort == VK_F8)
  433.                         wValue = IDD_AbortF8Flag ;
  434.                     else
  435.                         wValue = 0 ;  // none of the keys !!!
  436.             CheckRadioButton(hDlg, IDD_AbortEscFlag, IDD_AbortF8Flag, wValue) ;
  437.  
  438.             // If time limit isn't anabled, disable the time data part
  439.             CheckDlgButton(hDlg, IDD_TimeLimitFlag, (fValue = gCapParms.fLimitEnabled)) ;
  440.             EnableWindow(GetDlgItem(hDlg, IDD_SecondsText), fValue) ;
  441.             EnableWindow(GetDlgItem(hDlg, IDD_SecondsData), fValue) ;
  442.             if (fValue)
  443.                 SetDlgItemInt(hDlg, IDD_SecondsData, gCapParms.wTimeLimit, FALSE) ;
  444.             EnableWindow(GetDlgItem(hDlg, IDD_CapAudioFlag), gCapStatus.fAudioHardware) ;
  445.             CheckDlgButton(hDlg, IDD_CapAudioFlag, gCapParms.fCaptureAudio) ;
  446.             CheckDlgButton(hDlg, IDD_UseDOSMemFlag, gCapParms.fUsingDOSMemory) ;
  447.             CheckDlgButton(hDlg, IDD_CaptureOKFlag, gCapParms.fMakeUserHitOKToCapture) ;
  448.  
  449.             // Find out how many MCI devices can source video
  450.             if (CountMCIDevices(MCI_DEVTYPE_VCR) +
  451.                 CountMCIDevices(MCI_DEVTYPE_VIDEODISC) == 0)
  452.                 // if no VCRs or Videodiscs, disable the controls
  453.                 fValue = FALSE ;
  454.             else
  455.                 fValue = TRUE ;
  456.  
  457.             // If no MCI device or MCI Control not enabled, disable MCI
  458.             // device name, start and stop time, step capture etc
  459.             EnableWindow(GetDlgItem(hDlg, IDD_MCIControlFlag), fValue) ;
  460.             CheckDlgButton(hDlg, IDD_MCIControlFlag,
  461.                            (fValue &= gCapParms.fMCIControl)) ;
  462.             EnableWindow(GetDlgItem(hDlg, IDD_MCIDeviceText), fValue) ;
  463.             EnableWindow(GetDlgItem(hDlg, IDD_MCIDeviceData), fValue) ;
  464.             SetDlgItemText(hDlg, IDD_MCIDeviceData, (LPTSTR)gachMCIDeviceName) ;
  465.             EnableWindow(GetDlgItem(hDlg, IDD_MCIStartText), fValue) ;
  466.             EnableWindow(GetDlgItem(hDlg, IDD_MCIStartData), fValue) ;
  467.             EnableWindow(GetDlgItem(hDlg, IDD_MCIStopText), fValue) ;
  468.             EnableWindow(GetDlgItem(hDlg, IDD_MCIStopData), fValue) ;
  469.             if (fValue) {
  470.                 wsprintf((LPTSTR)achBuffer, TEXT("%lu"), gCapParms.dwMCIStartTime) ;
  471.                 SetDlgItemText(hDlg, IDD_MCIStartData, (LPTSTR)achBuffer) ;
  472.                 wsprintf((LPTSTR)achBuffer, TEXT("%lu"), gCapParms.dwMCIStopTime) ;
  473.                 SetDlgItemText(hDlg, IDD_MCIStopData, (LPTSTR)achBuffer) ;
  474.             }
  475.             EnableWindow(GetDlgItem(hDlg, IDD_MCIStepCapFlag), fValue) ;
  476.             CheckDlgButton(hDlg, IDD_MCIStepCapFlag, gCapParms.fStepMCIDevice) ;
  477.             SetDlgItemInt(hDlg, IDD_MaxDropData, gCapParms.wPercentDropForError, FALSE) ;
  478.             SetDlgItemInt(hDlg, IDD_VideoBuffData, gCapParms.wNumVideoRequested, FALSE) ;
  479.  
  480.             return TRUE ;
  481.         }
  482.  
  483.         case WM_COMMAND :
  484.             switch (wParam) {
  485.                 case IDD_TimeLimitFlag :
  486.                     // If this flag changes, en/dis-able time limit data part
  487.                     fValue = IsDlgButtonChecked(hDlg, IDD_TimeLimitFlag) ;
  488.                     EnableWindow(GetDlgItem(hDlg, IDD_SecondsText), fValue) ;
  489.                     EnableWindow(GetDlgItem(hDlg, IDD_SecondsData), fValue) ;
  490.                     return TRUE ;
  491.  
  492.                 case IDD_MCIControlFlag :
  493.                     // If this flag changes, en/dis-able MCI times data part
  494.                     fValue = IsDlgButtonChecked(hDlg, IDD_MCIControlFlag) ;
  495.                     EnableWindow(GetDlgItem(hDlg, IDD_MCIDeviceText), fValue) ;
  496.                     EnableWindow(GetDlgItem(hDlg, IDD_MCIDeviceData), fValue) ;
  497.                     EnableWindow(GetDlgItem(hDlg, IDD_MCIStartText), fValue) ;
  498.                     EnableWindow(GetDlgItem(hDlg, IDD_MCIStartData), fValue) ;
  499.                     EnableWindow(GetDlgItem(hDlg, IDD_MCIStopText), fValue) ;
  500.                     EnableWindow(GetDlgItem(hDlg, IDD_MCIStopData), fValue) ;
  501.                     EnableWindow(GetDlgItem(hDlg, IDD_MCIStepCapFlag), fValue) ;
  502.                     CheckDlgButton(hDlg, IDD_MCIStepCapFlag,
  503.                             gCapParms.fStepMCIDevice |
  504.                             IsDlgButtonChecked(hDlg, IDD_MCIStepCapFlag)) ;
  505.                     return TRUE ;
  506.  
  507.                 case IDOK :
  508.                 {
  509.                     int         iFrameRate ;
  510.                     int         iTimeLimit ;
  511.                     int         iMaxDropRate ;
  512.                     int         iVideoBuffers ;
  513.                     long        lMCIStart ;
  514.                     long        lMCIStop ;
  515.  
  516.                     if ((iFrameRate = (int) GetDlgItemInt(hDlg, IDD_FrameRateData, NULL,
  517.                                       TRUE)) <= 0 || iFrameRate >= 100) {
  518.                         // No frame at all or more than 100 FPS !!
  519.                         SetDlgItemInt(hDlg, IDD_FrameRateData, iFrameRate, TRUE) ;
  520.                         SetFocus(GetDlgItem(hDlg, IDD_FrameRateData)) ;
  521.                         MessageBeep(MB_ICONQUESTION) ;
  522.                         return FALSE ;
  523.                     }
  524.                     if (IsDlgButtonChecked(hDlg, IDD_TimeLimitFlag)) {
  525.                         if ((iTimeLimit = (int) GetDlgItemInt(hDlg, IDD_SecondsData, NULL,
  526.                                           TRUE)) <= 0 || iTimeLimit > 3600) {
  527.                             // No capture or more than 1 hour !!
  528.                             SetDlgItemInt(hDlg, IDD_SecondsData, iTimeLimit, TRUE) ;
  529.                             SetFocus(GetDlgItem(hDlg, IDD_SecondsData)) ;
  530.                             MessageBeep(MB_ICONQUESTION) ;
  531.                             return FALSE ;
  532.                         }
  533.                     }
  534.                     if (IsDlgButtonChecked(hDlg, IDD_MCIControlFlag)) {
  535.                         GetDlgItemText(hDlg, IDD_MCIStartData, (LPTSTR)achBuffer, 20) ;
  536. #ifdef UNICODE
  537.                         lMCIStart = wcstol(achBuffer, NULL, 10);
  538. #else
  539.                         lMCIStart = atol(achBuffer) ;
  540. #endif
  541.                         if (lMCIStart < 0 ||             // negative time !!!
  542.                             lMCIStart >= 2000000000L) {  // or too high !!!
  543.                             SetDlgItemText(hDlg, IDD_MCIStartData, achBuffer) ;
  544.                             SetFocus(GetDlgItem(hDlg, IDD_MCIStartData)) ;
  545.                             MessageBeep(MB_ICONQUESTION) ;
  546.                             return FALSE ;
  547.                         }
  548.                         GetDlgItemText(hDlg, IDD_MCIStopData, (LPTSTR)achBuffer, 20) ;
  549. #ifdef UNICODE
  550.                         lMCIStop = wcstol(achBuffer, NULL, 10);
  551. #else
  552.                         lMCIStop = atol(achBuffer) ;
  553. #endif
  554.                         if (lMCIStop < 0 ||            // negative time !!!
  555.                             lMCIStop >= 2000000000L || // or too high !!!
  556.                             lMCIStop < lMCIStart) {    // or Stop before Start !!!
  557.                             SetDlgItemText(hDlg, IDD_MCIStopData, achBuffer) ;
  558.                             SetFocus(GetDlgItem(hDlg, IDD_MCIStopData)) ;
  559.                             MessageBeep(MB_ICONQUESTION) ;
  560.                             return FALSE ;
  561.                         }
  562.                     }
  563.                     if ((iMaxDropRate = (int) GetDlgItemInt(hDlg, IDD_MaxDropData, NULL,
  564.                                             TRUE)) < 0 || iMaxDropRate >= 100) {
  565.                         // Negative drop limit or more than 100% !!
  566.                         SetDlgItemInt(hDlg, IDD_MaxDropData, iMaxDropRate, TRUE) ;
  567.                         SetFocus(GetDlgItem(hDlg, IDD_MaxDropData)) ;
  568.                         MessageBeep(0) ;
  569.                         return FALSE ;
  570.                     }
  571.                     if ((iVideoBuffers = (int) GetDlgItemInt(hDlg, IDD_VideoBuffData, NULL,
  572.                                              TRUE)) <= 0 || iVideoBuffers >= 32767) {
  573.                         // Can't capture with too many or without video buffers
  574.                         SetDlgItemInt(hDlg, IDD_VideoBuffData, iVideoBuffers, TRUE) ;
  575.                         SetFocus(GetDlgItem(hDlg, IDD_VideoBuffData)) ;
  576.                         MessageBeep(MB_ICONQUESTION) ;
  577.                         return FALSE ;
  578.                     }
  579.  
  580.                     // All the Cap params are correct. So set them now...
  581.                     gCapParms.dwRequestMicroSecPerFrame = (DWORD)(1E+6 / iFrameRate + 0.5) ;
  582.                     gCapParms.fLimitEnabled = IsDlgButtonChecked(hDlg, IDD_TimeLimitFlag) ;
  583.                     gCapParms.wTimeLimit = iTimeLimit ;
  584.                     if (gCapParms.fMCIControl =
  585.                             IsDlgButtonChecked(hDlg, IDD_MCIControlFlag)) {
  586.                         gCapParms.dwMCIStartTime = lMCIStart ;
  587.                         gCapParms.dwMCIStopTime  = lMCIStop ;
  588.                         GetDlgItemText(hDlg, IDD_MCIDeviceData, (LPTSTR)achBuffer, 20) ;
  589.                         lstrcpy(gachMCIDeviceName, achBuffer) ;
  590.                         capSetMCIDeviceName(ghWndCap, gachMCIDeviceName) ;
  591.                         gCapParms.fStepMCIDevice = IsDlgButtonChecked(hDlg, IDD_MCIStepCapFlag) ;
  592.                     }
  593.                     else {
  594.                         gCapParms.dwMCIStartTime = gCapParms.dwMCIStopTime = 0 ;
  595.                         gCapParms.fStepMCIDevice = FALSE ;
  596.                     }
  597.                     gCapParms.wPercentDropForError = iMaxDropRate ;
  598.                     gCapParms.wNumVideoRequested = iVideoBuffers ;
  599.                     gCapParms.fAbortLeftMouse = IsDlgButtonChecked(hDlg, IDD_AbortLeftFlag) ;
  600.                     gCapParms.fAbortRightMouse = IsDlgButtonChecked(hDlg, IDD_AbortRightFlag) ;
  601.                     if (IsDlgButtonChecked(hDlg, IDD_AbortEscFlag))
  602.                         gCapParms.vKeyAbort = VK_ESCAPE ;
  603.                     else
  604.                         if (IsDlgButtonChecked(hDlg, IDD_AbortSpaceFlag))
  605.                             gCapParms.vKeyAbort = VK_SPACE ;
  606.                         else
  607.                             if (IsDlgButtonChecked(hDlg, IDD_AbortF8Flag))
  608.                                 gCapParms.vKeyAbort = VK_F8 ;
  609.                             else
  610.                                 gCapParms.vKeyAbort = 0 ;
  611.                     gCapParms.fCaptureAudio =
  612.                                 IsDlgButtonChecked(hDlg, IDD_CapAudioFlag) ;
  613.                     gCapParms.fUsingDOSMemory =
  614.                                 IsDlgButtonChecked(hDlg, IDD_UseDOSMemFlag) ;
  615.                     gCapParms.fMakeUserHitOKToCapture =
  616.                                 IsDlgButtonChecked(hDlg, IDD_CaptureOKFlag) ;
  617.  
  618.                     EndDialog(hDlg, TRUE) ;
  619.                     return TRUE ;
  620.                 }
  621.  
  622.                 case IDCANCEL :
  623.                     EndDialog(hDlg, FALSE) ;
  624.                     return TRUE ;
  625.             }
  626.             break ;
  627.     }
  628.  
  629.     return FALSE ;
  630. }
  631.