GetCapture.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // GetCapture.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "StoneU_HC_OCX.h"
  5. #include "GetCapture.h"
  6. #include "MyOutput.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CGetCapture dialog
  14. extern CLIENTPARAM ClientParam;
  15. extern WORD iActiveWndNumber;
  16. extern CMyOutput myoutput[MAXVIEWNUM];
  17. //由于是无模式对话框,所以生成的对象要进行控制,最多一个!!!
  18. int CGetCapture::m_CaptureCount = 0;
  19. CGetCapture::CGetCapture(CWnd* pParent /*=NULL*/)
  20. : CDialog(CGetCapture::IDD, pParent)
  21. {
  22. //{{AFX_DATA_INIT(CGetCapture)
  23. //}}AFX_DATA_INIT
  24. }
  25. CGetCapture::~CGetCapture()
  26. {
  27. }
  28. void CGetCapture::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CGetCapture)
  32. DDX_Control(pDX, IDC_JPEGSIZECOMBO, m_JpegSize);
  33. DDX_Control(pDX, IDC_JPEGQUALCOMBO, m_JpegQual);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CGetCapture, CDialog)
  37. //{{AFX_MSG_MAP(CGetCapture)
  38. ON_BN_CLICKED(IDC_CAPTURE, OnCapture)
  39. ON_BN_CLICKED(IDC_BMPRADIO, OnBmpradio)
  40. ON_BN_CLICKED(IDC_JPEGRADIO, OnJpegradio)
  41. ON_WM_CREATE()
  42. ON_WM_DESTROY()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CGetCapture message handlers
  47. BOOL CGetCapture::OnInitDialog()
  48. {
  49. CDialog::OnInitDialog();
  50. // TODO: Add extra initialization here
  51. m_JpegSize.SetCurSel(0);
  52. m_JpegQual.SetCurSel(2);
  53. m_RadioState = FALSE;
  54. CheckRadioButton(IDC_BMPRADIO, IDC_JPEGRADIO, IDC_BMPRADIO);
  55. GetDlgItem(IDC_JPEGQUALCOMBO)->EnableWindow(FALSE);
  56. GetDlgItem(IDC_JPEGSIZECOMBO)->EnableWindow(FALSE);
  57. return TRUE; // return TRUE unless you set the focus to a control
  58. // EXCEPTION: OCX Property Pages should return FALSE
  59. }
  60. void CGetCapture::OnCapture()
  61. {
  62. // TODO: Add your control notification handler code here
  63. UpdateData(TRUE);
  64. int i = iActiveWndNumber;
  65. if (myoutput[i].m_iPlayhandle < 0)
  66. {
  67. return;
  68. }
  69. if (m_RadioState) //JPEG
  70. {
  71. char cFilename[256];
  72. CString sTemp;
  73. CTime time = CTime::GetCurrentTime();
  74. sTemp.Format("%s\\", ClientParam.m_csPictureSavePath);
  75. if (GetFileAttributes(sTemp) != FILE_ATTRIBUTE_DIRECTORY)
  76. {
  77. CreateDirectory(sTemp, NULL);
  78. }
  79. long m_lServerID = myoutput[i].m_lServerID;
  80. int m_nChanNum = myoutput[i].m_iChannel;
  81. sprintf(cFilename, "%s\\JPEG_%02d_%4d%02d%02d_%02d%02d%02d_%d.jpg", ClientParam.m_csPictureSavePath, m_nChanNum, \
  82. time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond(), GetTickCount());
  83. TRACE("Picture save file name : %s", cFilename);
  84. NET_DVR_JPEGPARA JpegPara;
  85. JpegPara.wPicQuality = m_JpegQual.GetCurSel();
  86. JpegPara.wPicSize = m_JpegSize.GetCurSel();
  87. if (!ClientParam.m_bUseCard)
  88. {
  89. if (NET_DVR_CaptureJPEGPicture(m_lServerID, m_nChanNum, &JpegPara, cFilename))
  90. {
  91. CString sTemp;
  92. sTemp.Format("JPEG抓图成功 %s!", cFilename);
  93. MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION);
  94. return;
  95. }
  96. else
  97. {
  98. MessageBox("JPEG抓图失败!", "温馨提示", MB_ICONINFORMATION);
  99. }
  100. }
  101. }
  102. else //BMP
  103. {
  104. char cFilename[256];
  105. CString sTemp;
  106. CTime time = CTime::GetCurrentTime();
  107. sTemp.Format("%s\\", ClientParam.m_csPictureSavePath);
  108. if(GetFileAttributes(sTemp) != FILE_ATTRIBUTE_DIRECTORY)
  109. {
  110. CreateDirectory(sTemp, NULL);
  111. }
  112. 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, \
  113. time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond(), GetTickCount());
  114. TRACE("Picture save file name : %s", cFilename);
  115. if(ClientParam.m_bUseCard)
  116. {
  117. if(NET_DVR_CapturePicture_Card(myoutput[i].m_iPlayhandle, cFilename))
  118. {
  119. CString sTemp;
  120. sTemp.Format("Capture picture succeed %s!", cFilename);
  121. MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION);
  122. return;
  123. }
  124. else
  125. {
  126. MessageBox("Failed to capture picture!", "温馨提示", MB_ICONINFORMATION);
  127. }
  128. }
  129. else
  130. {
  131. if(NET_DVR_CapturePicture(myoutput[i].m_iPlayhandle, cFilename))
  132. {
  133. CString sTemp;
  134. sTemp.Format("抓图成功 %s!",cFilename);
  135. MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION);
  136. return;
  137. }
  138. else
  139. {
  140. MessageBox("抓图失败!", "温馨提示", MB_ICONINFORMATION);
  141. }
  142. }
  143. }
  144. }
  145. void CGetCapture::OnBmpradio()
  146. {
  147. // TODO: Add your control notification handler code here
  148. m_RadioState = FALSE;
  149. CheckRadioButton(IDC_BMPRADIO, IDC_JPEGRADIO, IDC_BMPRADIO);
  150. GetDlgItem(IDC_JPEGQUALCOMBO)->EnableWindow(FALSE);
  151. GetDlgItem(IDC_JPEGSIZECOMBO)->EnableWindow(FALSE);
  152. }
  153. void CGetCapture::OnJpegradio()
  154. {
  155. // TODO: Add your control notification handler code here
  156. m_RadioState = TRUE;
  157. CheckRadioButton(IDC_BMPRADIO, IDC_JPEGRADIO, IDC_JPEGRADIO);
  158. GetDlgItem(IDC_JPEGQUALCOMBO)->EnableWindow(TRUE);
  159. GetDlgItem(IDC_JPEGSIZECOMBO)->EnableWindow(TRUE);
  160. }
  161. int CGetCapture::OnCreate(LPCREATESTRUCT lpCreateStruct)
  162. {
  163. if (CDialog::OnCreate(lpCreateStruct) == -1)
  164. return -1;
  165. // TODO: Add your specialized creation code here
  166. m_CaptureCount ++;
  167. return 0;
  168. }
  169. void CGetCapture::OnCancel()
  170. {
  171. // TODO: Add extra cleanup here
  172. CDialog::OnCancel();
  173. DestroyWindow();
  174. }
  175. void CGetCapture::OnDestroy()
  176. {
  177. CDialog::OnDestroy();
  178. // TODO: Add your message handler code here
  179. m_CaptureCount --;
  180. }
  181. BOOL CGetCapture::IsExisted()
  182. {
  183. return m_CaptureCount;
  184. }