// GetCapture.cpp : implementation file // #include "stdafx.h" #include "StoneU_HC_OCX.h" #include "GetCapture.h" #include "MyOutput.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CGetCapture dialog extern CLIENTPARAM ClientParam; extern WORD iActiveWndNumber; extern CMyOutput myoutput[MAXVIEWNUM]; //由于是无模式对话框,所以生成的对象要进行控制,最多一个!!! int CGetCapture::m_CaptureCount = 0; CGetCapture::CGetCapture(CWnd* pParent /*=NULL*/) : CDialog(CGetCapture::IDD, pParent) { //{{AFX_DATA_INIT(CGetCapture) //}}AFX_DATA_INIT } CGetCapture::~CGetCapture() { } void CGetCapture::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CGetCapture) DDX_Control(pDX, IDC_JPEGSIZECOMBO, m_JpegSize); DDX_Control(pDX, IDC_JPEGQUALCOMBO, m_JpegQual); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CGetCapture, CDialog) //{{AFX_MSG_MAP(CGetCapture) ON_BN_CLICKED(IDC_CAPTURE, OnCapture) ON_BN_CLICKED(IDC_BMPRADIO, OnBmpradio) ON_BN_CLICKED(IDC_JPEGRADIO, OnJpegradio) ON_WM_CREATE() ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGetCapture message handlers BOOL CGetCapture::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_JpegSize.SetCurSel(0); m_JpegQual.SetCurSel(2); m_RadioState = FALSE; CheckRadioButton(IDC_BMPRADIO, IDC_JPEGRADIO, IDC_BMPRADIO); GetDlgItem(IDC_JPEGQUALCOMBO)->EnableWindow(FALSE); GetDlgItem(IDC_JPEGSIZECOMBO)->EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CGetCapture::OnCapture() { // TODO: Add your control notification handler code here UpdateData(TRUE); int i = iActiveWndNumber; if (myoutput[i].m_iPlayhandle < 0) { return; } if (m_RadioState) //JPEG { char cFilename[256]; CString sTemp; CTime time = CTime::GetCurrentTime(); sTemp.Format("%s\\", ClientParam.m_csPictureSavePath); if (GetFileAttributes(sTemp) != FILE_ATTRIBUTE_DIRECTORY) { CreateDirectory(sTemp, NULL); } long m_lServerID = myoutput[i].m_lServerID; int m_nChanNum = myoutput[i].m_iChannel; sprintf(cFilename, "%s\\JPEG_%02d_%4d%02d%02d_%02d%02d%02d_%d.jpg", ClientParam.m_csPictureSavePath, m_nChanNum, \ time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond(), GetTickCount()); TRACE("Picture save file name : %s", cFilename); NET_DVR_JPEGPARA JpegPara; JpegPara.wPicQuality = m_JpegQual.GetCurSel(); JpegPara.wPicSize = m_JpegSize.GetCurSel(); if (!ClientParam.m_bUseCard) { if (NET_DVR_CaptureJPEGPicture(m_lServerID, m_nChanNum, &JpegPara, cFilename)) { CString sTemp; sTemp.Format("JPEG抓图成功 %s!", cFilename); MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION); return; } else { MessageBox("JPEG抓图失败!", "温馨提示", MB_ICONINFORMATION); } } } else //BMP { char cFilename[256]; CString sTemp; CTime time = CTime::GetCurrentTime(); sTemp.Format("%s\\", ClientParam.m_csPictureSavePath); if(GetFileAttributes(sTemp) != FILE_ATTRIBUTE_DIRECTORY) { CreateDirectory(sTemp, NULL); } 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)) { CString sTemp; sTemp.Format("Capture picture succeed %s!", cFilename); MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION); return; } else { MessageBox("Failed to capture picture!", "温馨提示", MB_ICONINFORMATION); } } else { if(NET_DVR_CapturePicture(myoutput[i].m_iPlayhandle, cFilename)) { CString sTemp; sTemp.Format("抓图成功 %s!",cFilename); MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION); return; } else { MessageBox("抓图失败!", "温馨提示", MB_ICONINFORMATION); } } } } void CGetCapture::OnBmpradio() { // TODO: Add your control notification handler code here m_RadioState = FALSE; CheckRadioButton(IDC_BMPRADIO, IDC_JPEGRADIO, IDC_BMPRADIO); GetDlgItem(IDC_JPEGQUALCOMBO)->EnableWindow(FALSE); GetDlgItem(IDC_JPEGSIZECOMBO)->EnableWindow(FALSE); } void CGetCapture::OnJpegradio() { // TODO: Add your control notification handler code here m_RadioState = TRUE; CheckRadioButton(IDC_BMPRADIO, IDC_JPEGRADIO, IDC_JPEGRADIO); GetDlgItem(IDC_JPEGQUALCOMBO)->EnableWindow(TRUE); GetDlgItem(IDC_JPEGSIZECOMBO)->EnableWindow(TRUE); } int CGetCapture::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDialog::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here m_CaptureCount ++; return 0; } void CGetCapture::OnCancel() { // TODO: Add extra cleanup here CDialog::OnCancel(); DestroyWindow(); } void CGetCapture::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here m_CaptureCount --; } BOOL CGetCapture::IsExisted() { return m_CaptureCount; }