FrmCctvCamF.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FrmCctvCamF.h"
  5. #include "AppGlobalF.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. //TFrmCctvCam *FrmCctvCam;
  10. //---------------------------------------------------------------------------
  11. __fastcall TFrmCctvCam::TFrmCctvCam(TComponent* Owner)
  12. : TForm(Owner)
  13. {
  14. PnlBlob->Visible = false;
  15. PnlBlob->Align = alClient;
  16. FDispBlob = false;
  17. FObj = NULL;
  18. }
  19. //---------------------------------------------------------------------------
  20. void __fastcall TFrmCctvCam::TmrShowTimer(TObject *Sender)
  21. {
  22. TmrShow->Enabled = false;
  23. if (FObj)
  24. {
  25. Caption = FObj->CCTV_CTLR_ID + ": " + FObj->ISTL_LCTN_NM;
  26. if (FDispBlob == false)
  27. {
  28. CamPlay();
  29. }
  30. SetFocus();
  31. }
  32. }
  33. //---------------------------------------------------------------------------
  34. void __fastcall TFrmCctvCam::FormShow(TObject *Sender)
  35. {
  36. RefreshCctv();
  37. TmrShow->Enabled = true;
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TFrmCctvCam::CamPlay()
  41. {
  42. if (!FObj) return;
  43. STARTUPINFO StartupInfo;
  44. PROCESS_INFORMATION ProcessInfo;
  45. ULONG ret;
  46. TMsg msg;
  47. SECURITY_ATTRIBUTES sa;
  48. sa.bInheritHandle = true;
  49. sa.lpSecurityDescriptor = NULL;
  50. sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  51. FObj->STRM_SESN_NM = "rtsp://211.252.223.178/246/video2d";
  52. String sPlayerName = g_sAppDir + "Player\\rtspPlayer1.exe";
  53. int nHandle = (int)PnlBack->Handle;
  54. String sParameter = " O " + String(nHandle) + " " + FObj->STRM_SESN_NM + " " + FObj->CCTV_CTLR_ID + " " + FObj->ISTL_LCTN_NM;
  55. String sExeName = sPlayerName + sParameter;
  56. ZeroMemory(&StartupInfo, sizeof(StartupInfo));
  57. StartupInfo.cb = sizeof(StartupInfo);
  58. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;//STARTF_USESTDHANDLES;//STARTF_USESHOWWINDOW;
  59. StartupInfo.wShowWindow = SW_HIDE; //SW_SHOW;//SW_HIDE;
  60. StartupInfo.hStdInput = NULL;
  61. StartupInfo.hStdOutput = NULL;
  62. StartupInfo.hStdError = NULL;
  63. if (!CreateProcess(
  64. (LPCTSTR)NULL,
  65. (LPTSTR)WideString(sExeName).c_bstr(), // { pointer to command line string }
  66. &sa, // { pointer to process security attributes }
  67. &sa, // { pointer to thread security attributes }
  68. true, // { handle inheritance flag }
  69. 0, // { creation flags }
  70. NULL, // { pointer to new environment block }
  71. NULL, // { pointer to current directory name }
  72. &StartupInfo, // { pointer to STARTUPINFO }
  73. &ProcessInfo)) // { pointer to PROCESS_INF }
  74. {
  75. Application->NormalizeTopMosts();
  76. Application->MessageBox(L"Player를 실행할 수 없습니다.", L"Player 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  77. Application->RestoreTopMosts();
  78. return;
  79. }
  80. HWND hWnd;
  81. TRect rc;
  82. WaitForInputIdle(ProcessInfo.hProcess, 0xffffffff);
  83. FProcessId = ProcessInfo.dwProcessId;
  84. Sleep(10);
  85. //hWnd = GetWinHandle(ProcessInfo.dwProcessId); // 프로세스 아이디로 윈도우 핸들 얻기
  86. hWnd = GetForegroundWindow();
  87. ::SetParent(hWnd, PnlBack->Handle);
  88. SetWindowPos(hWnd, NULL, 0, 0, PnlBack->Width, PnlBack->Height, 0);
  89. //if (hWnd) SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  90. //SendMessage(hWnd, WM_CLOSE, 0, 0);
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TFrmCctvCam::CamStop()
  94. {
  95. if (!FObj) return;
  96. HWND hWnd = GetWinHandle(FProcessId);
  97. if (hWnd)
  98. {
  99. SendMessage(hWnd, WM_CLOSE, 0, 0);
  100. }
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TFrmCctvCam::FormClose(TObject *Sender, TCloseAction &Action)
  104. {
  105. try {
  106. CamStop();
  107. FObj->FData2 = NULL;
  108. } catch(...) {}
  109. Action = caFree;
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TFrmCctvCam::RefreshCctv()
  113. {
  114. FDispBlob = false;
  115. PnlBlob->Visible = false;
  116. String sQry;
  117. if (!FObj)
  118. {
  119. return;
  120. }
  121. sQry = "SELECT CCTV_SBST_DSPL_YN, CCTV_SBST_IMGN \r\n"
  122. " FROM TB_CCTV_CTLR \r\n"
  123. " WHERE CCTV_CTLR_ID = :p01 \r\n";
  124. try
  125. {
  126. pADO->Close();
  127. pADO->SQL->Clear();
  128. pADO->Connection = ITSDb_GetConnection();
  129. pADO->SQL->Text = sQry;
  130. pADO->Parameters->ParamByName("p01")->Value = FObj->CCTV_CTLR_ID;
  131. pADO->Open();
  132. }
  133. catch(EDatabaseError &E)
  134. {
  135. PnlBlob->Caption = "대체영상 이미지 정보 읽기 실패";
  136. ShowMessage(String(E.ClassName()) + E.Message);
  137. return;
  138. }
  139. if (pADO->RecordCount == 0)
  140. {
  141. pADO->Close();
  142. return;
  143. }
  144. ForceDirectories(g_sTempDir);
  145. TADOBlobStream *BS;
  146. int nFileSize = 0;
  147. String sImgFile = g_sTempDir + "CCTVB_" + FObj->CCTV_CTLR_ID + ".bmp";
  148. try {
  149. DeleteFile(sImgFile);
  150. } catch(...) {}
  151. String sDispBlob;
  152. try
  153. {
  154. sDispBlob = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString;
  155. if (sDispBlob == "Y")
  156. {
  157. BS = (TADOBlobStream *)pADO->CreateBlobStream(pADO->FieldByName("CCTV_SBST_IMGN"), bmRead);
  158. //ImgBlob->Picture->Graphic->LoadFromStream(BS);
  159. BS->SaveToFile(sImgFile);
  160. nFileSize = BS->Size;
  161. delete BS;
  162. }
  163. pADO->Close();
  164. }
  165. catch(Exception &e)
  166. {
  167. delete BS;
  168. PnlBlob->Caption = "대체영상 이미지 스트림 로딩 실패";
  169. return;
  170. }
  171. if (sDispBlob == "Y")
  172. {
  173. FDispBlob = true;
  174. PnlBlob->Visible = true;
  175. PnlBack->Visible = false;
  176. if (nFileSize)
  177. {
  178. try
  179. {
  180. ImgBlob->Picture->LoadFromFile(sImgFile);
  181. return;
  182. }
  183. catch(...)
  184. {
  185. ImgBlob->Visible = false;
  186. PnlBlob->Caption = "대체영상 이미지 파일 로딩 실패";
  187. return;
  188. }
  189. }
  190. else
  191. {
  192. ImgBlob->Visible = false;
  193. PnlBlob->Caption = "대체영상 이미지 사이즈 오류";
  194. }
  195. }
  196. else
  197. {
  198. FDispBlob = false;
  199. PnlBlob->Visible = false;
  200. PnlBack->Visible = true;
  201. }
  202. }
  203. //---------------------------------------------------------------------------