GetCapture.cpp 5.8 KB

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