123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
- // (“Fluent UI”)。该示例仅供参考,
- // 用以补充《Microsoft 基础类参考》和
- // MFC C++ 库软件随附的相关电子文档。
- // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
- // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
- // https://go.microsoft.com/fwlink/?LinkId=238214.
- //
- // 版权所有(C) Microsoft Corporation
- // 保留所有权利。
- // VideoCaptureView.h: CVideoCaptureView 类的接口
- //
- #pragma once
- #include "VideoCaptureDoc.h"
- #include "MemoryClient.h"
- typedef struct __CAPTURE_INFO__
- {
- // 是否是jpg;
- BOOL bIsJPG;
- // 持续时间;
- int nKeepTime;
- // 每秒抓取张数;
- int nCaputerCount;
- // 保存路径;
- TCHAR szSaveDir[MAX_PATH];
- // 文件名前缀;
- TCHAR szPrefix[64];
- // 是否自动命名;
- BOOL IsAutoName;
- // 是否单张截图;
- BOOL bSingle;
- }CaptureInfo, *pCaptureInfo;
- class CVideoCaptureView : public CView
- {
- protected: // 仅从序列化创建
- CVideoCaptureView() noexcept;
- DECLARE_DYNCREATE(CVideoCaptureView)
- // 特性
- public:
- CVideoCaptureDoc* GetDocument() const;
- // 操作
- public:
- // 重写
- public:
- virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
- virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
- protected:
- virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
- virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
- virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
- // 实现
- public:
- virtual ~CVideoCaptureView();
- #ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
- #endif
- public:
- // 设备句柄;
- PVOID m_hVideoDevice;
- // 是否有信号;
- BOOL m_bNoSignal;
- // 是否在录频;
- BOOL m_bIsRecord;
- // 录频格式;
- BOOL m_bIsMp4; // FALSE= AVI
- //////////////////////////////////////////////////////////////////////////
- // VIDEO PROPERTIES
- // 是否支持GPU;
- BOOL m_bSupportGPU;
- // 视频流宽度;
- ULONG m_nVideoWidth;
- // 视频流高度;
- ULONG m_nVideoHeight;
- BOOL m_bVideoIsInterleaved;
- double m_dVideoFrameRate;
- BOOL m_bVideoDeinterlaceEnable;
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// AUDIO PROPERTIES
- ULONG m_nAudioChannels;
- ULONG m_nAudioBitsPerSample;
- ULONG m_nAudioSampleFrequency;
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QUALITY PROPERTIES
- ULONG m_nSharpness;
- ULONG m_nSaturation;
- ULONG m_nHue;
- ULONG m_nConstrast;
- ULONG m_nBrightness;
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RECORD & FILE PROPERTIES
- // 截图路径;
- CString m_strSnapshotPath;
- //
- CString m_strFormatChangedOutput;
- // 垂直镜像;
- BOOL m_bVertically;
- // 水平镜像;
- BOOL m_bHoriontal;
- // 程序退出;
- BOOL m_bAppQuit;
- public:
- // 初始化设备;
- BOOL HwInitialize();
- // 释放设备;
- BOOL HwUninitialize();
- // 单次截图;
- void CaptureSingleImage(LPTSTR lpszFileName, BOOL bIsJPG = TRUE);
- // 单次截图并自动命名;
- std::string CaptureSingleImageAutoName(LPCTSTR lpszDir, BOOL bIsJPG = TRUE);
- // 连续截图;//默认持续1000ms;
- void CaptureMultiImage(LPCTSTR lpszDir, LPCTSTR lpszPrefix, BOOL bIsJPG, int nDurationTime = 1000);
- //////////////////////////////////////////////////////////////////////////
- // ->预览截图;
- CaptureInfo m_CaptureInfo;
- BOOL m_bCaptureImage;
- std::mutex m_mut_cpature;
- std::condition_variable m_capture_cond;
- // 单次截图;
- void CaptureSingleImageEx(LPTSTR lpszFileName, BOOL bIsJPG = TRUE);
- // 单次截图并自动命名;
- std::string CaptureSingleImageAutoNameEx(LPCTSTR lpszDir, BOOL bIsJPG = TRUE);
- // 连续截图;//默认持续1000ms;
- void CaptureMultiImageEx(LPCTSTR lpszDir, LPCTSTR lpszPrefix, BOOL bIsJPG, int nDurationTime = 1000);
- // 截图;
- BOOL SaveImageByCaptureInfo(const CaptureInfo &capInfo);
-
- // 截图线程;
- BYTE* m_pBuffer;
- DWORD m_dwBufferLen;
- std::mutex m_mut_thread;
- std::condition_variable m_thread_cond; //使用std::condition_variable等待数据
- static void CaptureImageThread(CVideoCaptureView *pView);
- // 录屏;
- void StartRecord(DWORD dwDuration, LPCTSTR lpSavePath);
- void StopRecord();
- protected:
- // 生成的消息映射函数
- protected:
- afx_msg void OnFilePrintPreview();
- afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
- afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
- DECLARE_MESSAGE_MAP()
- public:
- void SetRibbonStatusBarText(CString strText, int uId);
- friend class CMemoryClient;
- afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
- afx_msg void OnTimer(UINT_PTR nIDEvent);
- afx_msg void OnCutBmp();
- afx_msg void OnCutJpg();
- afx_msg void OnStartRecord();
- afx_msg void OnStopRecord();
- afx_msg void OnCheckVertically();
- afx_msg void OnCheckHoriontal();
- afx_msg void OnUpdateCheckVertically(CCmdUI* pCmdUI);
- afx_msg void OnUpdateCheckHoriontal(CCmdUI* pCmdUI);
- afx_msg void OnTraymenuReconnect();
- afx_msg void OnCheckSuportGpu();
- afx_msg void OnCheckFormatMp4();
- afx_msg void OnCheckFormatAvi();
- afx_msg void OnUpdateCheckSuportGpu(CCmdUI* pCmdUI);
- afx_msg void OnUpdateCheckFormatMp4(CCmdUI* pCmdUI);
- afx_msg void OnUpdateCheckFormatAvi(CCmdUI* pCmdUI);
- afx_msg void OnUpdateStartRecord(CCmdUI* pCmdUI);
- afx_msg void OnUpdateStopRecord(CCmdUI* pCmdUI);
- };
- #ifndef _DEBUG // VideoCaptureView.cpp 中的调试版本
- inline CVideoCaptureDoc* CVideoCaptureView::GetDocument() const
- { return reinterpret_cast<CVideoCaptureDoc*>(m_pDocument); }
- #endif
|