📄 videocapture.cpp
字号:
// VideoCapture.cpp: implementation of the CVideoCapture class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "NetMeeting.h"
#include "VideoCapture.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#include "NetMeetingDlg.h"
CVideoCapture::CVideoCapture(CWnd *pWnd)
{
m_hWndCap = NULL;
m_pVideoBuffer = NULL;
m_pWnd = pWnd;
}
CVideoCapture::~CVideoCapture()
{
}
//////////////////////////////////////////////////////////////////////////
// 初始化设备
//////////////////////////////////////////////////////////////////////////
BOOL CVideoCapture::InitDevice()
{
m_hWndCap = capCreateCaptureWindow("CaptureWindow",WS_POPUP,0,0,1,1,NULL,NULL);
if (m_hWndCap == NULL)
{
AfxMessageBox("capCreateCaptureWindow error...");
return FALSE;
}
capSetUserData(m_hWndCap,this);
if(!capSetCallbackOnVideoStream(m_hWndCap,OnCaptureVideo))
{
AfxMessageBox("capSetCallbackOnVideoStream error...");
return FALSE;
}
if (!capDriverConnect(m_hWndCap,0))
{
AfxMessageBox("capDriverConnect error...");
return FALSE;
}
if (!SetCapturePara())
{
capDriverDisconnect(m_hWndCap);
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK CVideoCapture::OnCaptureVideo(HWND mwnd,LPVIDEOHDR lphdr)
{
CVideoCapture *pVideoCapture = (CVideoCapture *)capGetUserData(mwnd);
PBYTE pBuffer = new BYTE[lphdr->dwBytesUsed+1];
memcpy(pBuffer,lphdr->lpData,lphdr->dwBytesUsed);
((CNetMeetingDlg *)pVideoCapture->m_pWnd)->Display(
pVideoCapture->m_stBMPInfo,pBuffer);
((CNetMeetingDlg *)pVideoCapture->m_pWnd)->Display263Video(
pVideoCapture->m_stBMPInfo,pBuffer,lphdr->dwBytesUsed);
delete []pBuffer;
pBuffer = NULL;
return 0;
}
BOOL CVideoCapture::SetCapturePara()
{
CAPTUREPARMS captureParam = {0};
if(!capCaptureGetSetup(m_hWndCap,&captureParam,sizeof(captureParam)))
{
AfxMessageBox("capCaptureGetSetup error...");
return FALSE;
}
captureParam.fAbortLeftMouse = FALSE;
captureParam.fAbortRightMouse = FALSE;
captureParam.fYield = TRUE;
if (!capCaptureSetSetup(m_hWndCap,&captureParam,sizeof(captureParam)))
{
AfxMessageBox("capCaptureSetSetup error...");
return FALSE;
}
if(capGetVideoFormat(m_hWndCap,&m_stBMPInfo,sizeof(BITMAPINFO)) == 0)
{
AfxMessageBox("capGetVideoFormat error...");
return FALSE;
}
m_stBMPInfo.bmiHeader.biWidth = IMAGE_WIDTH;
m_stBMPInfo.bmiHeader.biHeight = IMAGE_HEIGHT;
if (!capSetVideoFormat(m_hWndCap,&m_stBMPInfo,sizeof(m_stBMPInfo)))
{
AfxMessageBox("capSetVideoFormat error...");
return FALSE;
}
return TRUE;
}
void CVideoCapture::StartVideo()
{
if(!capCaptureSequenceNoFile(m_hWndCap))
{
AfxMessageBox("capCaptureSequenceNoFile error...");
return ;
}
capGetVideoFormat(m_hWndCap,&m_stBMPInfo,sizeof(BITMAPINFO));
}
void CVideoCapture::StopVideo()
{
capSetCallbackOnVideoStream(m_hWndCap,NULL);
capCaptureStop(m_hWndCap);
capDriverDisconnect(m_hWndCap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -