Unit1.~cpp
上传用户:doudou6666
上传日期:2022-05-28
资源大小:363k
文件大小:2k
源码类别:

视频捕捉/采集

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. #include "vfw.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.         : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::Button1Click(TObject *Sender)
  17. {
  18.   char szDeviceName[80];
  19.   char szDeviceVersion[80];
  20.   for (int wIndex=0;wIndex<10;wIndex++)
  21.   {
  22.     if (capGetDriverDescription(wIndex,szDeviceName,sizeof(szDeviceName),szDeviceVersion,sizeof(szDeviceVersion)))
  23.         {
  24.             Camera->Items->Add(szDeviceName);
  25.         }
  26.     }
  27.     if(Camera->Items->Count>0)
  28.         Camera->ItemIndex=0;
  29.     else
  30.     {
  31.         ShowMessage("There is no camera!");
  32.         Close();
  33.     }
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TForm1::Button2Click(TObject *Sender)
  37. {
  38. HWND hWndC=capCreateCaptureWindow((LPSTR)"My Capture Window",WS_CHILD | WS_VISIBLE,0,0,160,120,(HWND)Panel2->Handle,Camera->ItemIndex+1);
  39.   //连接设备:
  40.   capDriverConnect(hWndC,0);
  41.   capPreviewRate(hWndC,50); // rate, in milliseconds
  42.   capPreview(hWndC,TRUE); // starts preview
  43.   //获取视频驱动相关性能
  44.   CAPDRIVERCAPS     CapDrvCaps;
  45.   capDriverGetCaps(hWndC,&CapDrvCaps,sizeof(CAPDRIVERCAPS));
  46.   //获取捕获窗口状态
  47.   CAPSTATUS      CapStatus ;
  48.   capGetStatus(hWndC,&CapStatus,sizeof(CAPSTATUS));
  49.   SetWindowPos(hWndC,NULL,0,0,CapStatus.uiImageWidth,CapStatus.uiImageHeight,SWP_NOZORDER | SWP_NOMOVE);
  50. //文章出处:DIY部落(http://www.diybl.com/course/3_program/c++/cppsl/20071128/87976.html#)
  51. }
  52. //---------------------------------------------------------------------------