⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capture.cpp

📁 SDK DVR/DVS HIKVISION
💻 CPP
字号:
// Capture.cpp : implementation file
//

#include "stdafx.h"
#include "newclient.h"
#include "Capture.h"
#include "MyOutput.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCapture dialog
extern CMyOutput myoutput[MAXVIEWNUM];
extern WORD iActiveWndNumber;
extern CLIENTPARAM ClientParam;

int CCapture::m_iObjectCount = 0;

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)
	DDX_Control(pDX, IDC_COMBOJPEGSIZE, m_JPEGSize);
	DDX_Control(pDX, IDC_COMBOJPEGQUA, m_JPEGQuality);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCapture, CDialog)
	//{{AFX_MSG_MAP(CCapture)
	ON_BN_CLICKED(IDC_RADIOBMP, OnRadiobmp)
	ON_BN_CLICKED(IDC_RADIOJPEG, OnRadiojpeg)
	ON_BN_CLICKED(IDC_CAPTURE, OnCapture)
	ON_WM_CREATE()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCapture message handlers

void CCapture::OnRadiobmp() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	CheckRadioButton(IDC_RADIOBMP, IDC_RADIOJPEG, IDC_RADIOBMP);
	GetDlgItem(IDC_COMBOJPEGQUA)->EnableWindow(FALSE);
	GetDlgItem(IDC_COMBOJPEGSIZE)->EnableWindow(FALSE);

	m_bCaptureBMP = TRUE;
	UpdateData(FALSE);
}

void CCapture::OnRadiojpeg() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	CheckRadioButton(IDC_RADIOBMP, IDC_RADIOJPEG, IDC_RADIOJPEG);
	GetDlgItem(IDC_COMBOJPEGQUA)->EnableWindow(TRUE);
	GetDlgItem(IDC_COMBOJPEGSIZE)->EnableWindow(TRUE);

	m_bCaptureBMP = FALSE;
	UpdateData(FALSE);
}

void CCapture::OnCapture() 
{
	// TODO: Add your control notification handler code here
	int i = iActiveWndNumber;
	if(myoutput[i].m_iPlayhandle < 0)
	{
		return;
	}
	UpdateData(TRUE);
	
	char cFilename[256];
	CString sTemp;
	CTime time = CTime::GetCurrentTime();
	if (m_bCaptureBMP)
	{
		sprintf(cFilename, "%s\\Picture_%s_%02d_%4d%02d%02d_%02d%02d%02d_%d.bmp", ClientParam.m_csPictureSavePath, myoutput[i].m_csIP, myoutput[i].m_iChannel,	\
			time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond(), GetTickCount());
		TRACE("Picture save file name : %s", cFilename);
		if(ClientParam.m_bUseCard)
		{
			if(NET_DVR_CapturePicture_Card(myoutput[i].m_iPlayhandle, cFilename))
			{	
				sTemp.Format("Capture picture succeed %s!",cFilename);
				AfxMessageBox(sTemp);
				return;
			}
			else
			{
				AfxMessageBox("Failed to capture picture!");
			}
		}
		else
		{
			if(NET_DVR_CapturePicture(myoutput[i].m_iPlayhandle, cFilename))
			{
				sTemp.Format("catching BMP success: %s!",cFilename);
				AfxMessageBox(sTemp);
				return;
			}
			else
			{
				sTemp.Format("Error: NET_DVR_CapturePicture = %d", NET_DVR_GetLastError());
				AfxMessageBox(sTemp); 
			}
		}
	}
	else
	{
		NET_DVR_JPEGPARA JpegPara;
		JpegPara.wPicQuality = m_JPEGQuality.GetCurSel();
		JpegPara.wPicSize = m_JPEGSize.GetCurSel();
		sTemp.Format("%s\\", ClientParam.m_csPictureSavePath);		
		if (GetFileAttributes(sTemp) != FILE_ATTRIBUTE_DIRECTORY)
		{
			CreateDirectory(sTemp, NULL);
		}
		sprintf(cFilename, "%s\\JPEG_%02d_%4d%02d%02d_%02d%02d%02d_%d.jpg", ClientParam.m_csPictureSavePath, myoutput[i].m_iChannel,	\
			time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond(), GetTickCount());
		TRACE("Picture save file name : %s", cFilename);
		if (!ClientParam.m_bUseCard)
		{
/*
			if (NET_DVR_CaptureJPEGPicture(myoutput[i].m_lServerID , myoutput[i].m_iChannel, &JpegPara, cFilename))
			{
				sTemp.Format("catching JPEG success: %s!",cFilename);
				AfxMessageBox(sTemp); 
			}
			else
			{
				sTemp.Format("Error: NET_DVR_CaptureJPEGPicture = %d", NET_DVR_GetLastError());
				AfxMessageBox(sTemp); 
			}
*/
			int len = 500 * 1024;
			char JpegBuf[500 * 1024];
			DWORD dwRet = 0;
			if (NET_DVR_CaptureJPEGPicture_NEW(myoutput[i].m_lServerID, myoutput[i].m_iChannel, &JpegPara, JpegBuf, len, &dwRet))
			{
				CFile cf;
				cf.Open(cFilename, CFile::modeCreate | CFile::modeWrite);
				cf.Write(JpegBuf, dwRet);
				cf.Close();
				sTemp.Format("catching JPEG success: %s!",cFilename);
				AfxMessageBox(sTemp); 
			}
			else
			{
				sTemp.Format("Error: NET_DVR_CaptureJPEGPicture_NEW = %d", NET_DVR_GetLastError());
				AfxMessageBox(sTemp); 
			}
		}
	}

}

int CCapture::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	m_bCaptureBMP = TRUE;

	m_iObjectCount ++;
	return 0;
}

void CCapture::OnDestroy() 
{
	CDialog::OnDestroy();
	
	m_iObjectCount --;
	// TODO: Add your message handler code here
	
}

void CCapture::OnCancel() 
{
	// TODO: Add extra cleanup here
	CDialog::OnCancel();

	DestroyWindow();
}

BOOL CCapture::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_JPEGQuality.SetCurSel(2);
	m_JPEGSize.SetCurSel(0);

	CheckRadioButton(IDC_RADIOBMP, IDC_RADIOJPEG, IDC_RADIOBMP);
	
	GetDlgItem(IDC_COMBOJPEGQUA)->EnableWindow(FALSE);
	GetDlgItem(IDC_COMBOJPEGSIZE)->EnableWindow(FALSE);
	
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CCapture::IsExisted()
{
	return m_iObjectCount;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -