📄 capture.cpp
字号:
// Capture.cpp : implementation file
//
#include "stdafx.h"
#include "ImageCodes.h"
#include "Capture.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern HWND m_hCapWnd;
extern CCapture dlg;
/////////////////////////////////////////////////////////////////////////////
// CCapture dialog
CCapture::CCapture(CWnd* pParent /*=NULL*/)
: CDialog(CCapture::IDD, pParent)
{
//{{AFX_DATA_INIT(CCapture)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CCapture::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCapture)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCapture, CDialog)
//{{AFX_MSG_MAP(CCapture)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCapture message handlers
BOOL CCapture::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
PV_InitHW();
// TODO: Add extra initialization here
m_bInit = FALSE;
CWnd * pWnd = GetDlgItem(IDC_VEDIO );
CRect rect ;
pWnd->GetWindowRect(&rect);//得到窗口大小
// 设置预视窗口
m_hCapWnd = capCreateCaptureWindow((LPTSTR)TEXT("Capture Test"), // 标题
WS_CHILD | WS_VISIBLE
| WS_EX_CLIENTEDGE
| WS_EX_DLGMODALFRAME, // 风格
0, 0, rect.Width(), rect.Width(), // 大小
pWnd->GetSafeHwnd(), // 窗口句柄
(int) 0); // 窗口的ID号
ASSERT(m_hCapWnd);
// 连接驱动器
if(capDriverConnect(m_hCapWnd, 0)) // 连接第0号驱动器
{
m_bInit = TRUE;
// 得到驱动器的性能
capDriverGetCaps(m_hCapWnd, &m_CapDrvCap, sizeof(CAPDRIVERCAPS));
// 是否初始化成功
if(m_CapDrvCap.fCaptureInitialized)
{
// 得到驱动器状态
capGetStatus(m_hCapWnd ,&m_CapStatus, sizeof(m_CapStatus));
// 设置预视帧率
//capPreviewRate(m_hCapWnd, 30);
// 设置为预视方式
//capPreview(m_hCapWnd, TRUE);
capOverlay(m_hCapWnd, TRUE);
}
else
{// 初始化未成功
AfxMessageBox("Driver not initialized!");
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
}
else
{ // 未能连接到驱动器
AfxMessageBox("Conncet to driver Fail!");
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
// 设置捕捉文件
m_CapFileName = "G:\\Capture.avi";
capFileSetCaptureFile(m_hCapWnd, m_CapFileName.GetBuffer(255));
//设置视频数据回调函数
//** capSetCallbackOnVideoStream(m_hCapWnd,(FARPROC)VideoCallbackProc);
return TRUE; // return TRUE unless you set the focus to a control
}
CCapture::~CCapture()
{
// 断开驱动器连接
PV_DeInitHW();
capDriverDisconnect(m_hCapWnd);
::DestroyWindow(dlg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -