main.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "main.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "DSPack"
  8. #pragma resource "*.dfm"
  9. TMainForm *MainForm;
  10. TSysDevEnum *SysDev;
  11. //---------------------------------------------------------------------------
  12. __fastcall TMainForm::TMainForm(TComponent* Owner)
  13. : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TMainForm::FormCreate(TObject *Sender)
  18. {
  19. SysDev = new TSysDevEnum(CLSID_VideoInputDeviceCategory);
  20. if (SysDev->CountFilters > 0) {
  21. int i;
  22. TMenuItem *Device;
  23. for(i = 0; i < SysDev->CountFilters; i++) {
  24. Device = new TMenuItem(Devices);
  25. Device->Caption = SysDev->Filters[i].FriendlyName;
  26. Device->Tag = i;
  27. Device->OnClick = DevicesClick;
  28. Devices->Add(Device);
  29. }
  30. };
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TMainForm::DevicesClick(TObject *Sender)
  34. {
  35. FilterGraph->ClearGraph();
  36. FilterGraph->Active = false;
  37. Filter->BaseFilter->Moniker = SysDev->GetMoniker(((TMenuItem *)Sender)->Tag);
  38. FilterGraph->Active = true;
  39. ICaptureGraphBuilder2 *Graph = NULL;
  40. IBaseFilter *SourceFilter = NULL;
  41. IBaseFilter *VideoFilter = NULL;
  42. CheckDSError(FilterGraph->QueryInterface(IID_ICaptureGraphBuilder2, &Graph));
  43. CheckDSError(VideoWindow->QueryInterface(IID_IBaseFilter, &VideoFilter));
  44. CheckDSError(Filter->QueryInterface(IID_IBaseFilter, &SourceFilter));
  45. Graph->RenderStream(&PIN_CATEGORY_PREVIEW, NULL, SourceFilter, NULL, VideoFilter);
  46. FilterGraph->Play();
  47. Graph->Release();
  48. VideoFilter->Release();
  49. SourceFilter->Release();
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TMainForm::FormDestroy(TObject *Sender)
  53. {
  54. delete SysDev;
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
  58. {
  59. FilterGraph->Active = false;
  60. }
  61. //---------------------------------------------------------------------------