//--------------------------------------------------------------------------- #include #pragma hdrstop #include "FrmCctvCamF.h" #include "AppGlobalF.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //TFrmCctvCam *FrmCctvCam; //--------------------------------------------------------------------------- __fastcall TFrmCctvCam::TFrmCctvCam(TComponent* Owner) : TForm(Owner) { PnlBlob->Visible = false; PnlBlob->Align = alClient; FDispBlob = false; FObj = NULL; } //--------------------------------------------------------------------------- void __fastcall TFrmCctvCam::TmrShowTimer(TObject *Sender) { TmrShow->Enabled = false; if (FObj) { Caption = FObj->CCTV_CTLR_ID + ": " + FObj->ISTL_LCTN_NM; if (FDispBlob == false) { CamPlay(); } SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TFrmCctvCam::FormShow(TObject *Sender) { RefreshCctv(); TmrShow->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TFrmCctvCam::CamPlay() { if (!FObj) return; STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInfo; ULONG ret; TMsg msg; SECURITY_ATTRIBUTES sa; sa.bInheritHandle = true; sa.lpSecurityDescriptor = NULL; sa.nLength = sizeof(SECURITY_ATTRIBUTES); FObj->STRM_SESN_NM = "rtsp://211.252.223.178/246/video2d"; String sPlayerName = g_sAppDir + "Player\\rtspPlayer1.exe"; int nHandle = (int)PnlBack->Handle; String sParameter = " O " + String(nHandle) + " " + FObj->STRM_SESN_NM + " " + FObj->CCTV_CTLR_ID + " " + FObj->ISTL_LCTN_NM; String sExeName = sPlayerName + sParameter; ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof(StartupInfo); StartupInfo.dwFlags = STARTF_USESHOWWINDOW;//STARTF_USESTDHANDLES;//STARTF_USESHOWWINDOW; StartupInfo.wShowWindow = SW_HIDE; //SW_SHOW;//SW_HIDE; StartupInfo.hStdInput = NULL; StartupInfo.hStdOutput = NULL; StartupInfo.hStdError = NULL; if (!CreateProcess( (LPCTSTR)NULL, (LPTSTR)WideString(sExeName).c_bstr(), // { pointer to command line string } &sa, // { pointer to process security attributes } &sa, // { pointer to thread security attributes } true, // { handle inheritance flag } 0, // { creation flags } NULL, // { pointer to new environment block } NULL, // { pointer to current directory name } &StartupInfo, // { pointer to STARTUPINFO } &ProcessInfo)) // { pointer to PROCESS_INF } { Application->NormalizeTopMosts(); Application->MessageBox(L"Player¸¦ ½ÇÇàÇÒ ¼ö ¾ø½À´Ï´Ù.", L"Player ¿À·ù", MB_OK|MB_ICONERROR|MB_APPLMODAL); Application->RestoreTopMosts(); return; } HWND hWnd; TRect rc; WaitForInputIdle(ProcessInfo.hProcess, 0xffffffff); FProcessId = ProcessInfo.dwProcessId; Sleep(10); //hWnd = GetWinHandle(ProcessInfo.dwProcessId); // ÇÁ·Î¼¼½º ¾ÆÀ̵ð·Î À©µµ¿ì ÇÚµé ¾ò±â hWnd = GetForegroundWindow(); ::SetParent(hWnd, PnlBack->Handle); SetWindowPos(hWnd, NULL, 0, 0, PnlBack->Width, PnlBack->Height, 0); //if (hWnd) SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0); //SendMessage(hWnd, WM_CLOSE, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TFrmCctvCam::CamStop() { if (!FObj) return; HWND hWnd = GetWinHandle(FProcessId); if (hWnd) { SendMessage(hWnd, WM_CLOSE, 0, 0); } } //--------------------------------------------------------------------------- void __fastcall TFrmCctvCam::FormClose(TObject *Sender, TCloseAction &Action) { try { CamStop(); FObj->FData2 = NULL; } catch(...) {} Action = caFree; } //--------------------------------------------------------------------------- void __fastcall TFrmCctvCam::RefreshCctv() { FDispBlob = false; PnlBlob->Visible = false; String sQry; if (!FObj) { return; } sQry = "SELECT CCTV_SBST_DSPL_YN, CCTV_SBST_IMGN \r\n" " FROM TB_CCTV_CTLR \r\n" " WHERE CCTV_CTLR_ID = :p01 \r\n"; try { pADO->Close(); pADO->SQL->Clear(); pADO->Connection = ITSDb_GetConnection(); pADO->SQL->Text = sQry; pADO->Parameters->ParamByName("p01")->Value = FObj->CCTV_CTLR_ID; pADO->Open(); } catch(EDatabaseError &E) { PnlBlob->Caption = "´ëü¿µ»ó À̹ÌÁö Á¤º¸ ÀÐ±â ½ÇÆÐ"; ShowMessage(String(E.ClassName()) + E.Message); return; } if (pADO->RecordCount == 0) { pADO->Close(); return; } ForceDirectories(g_sTempDir); TADOBlobStream *BS; int nFileSize = 0; String sImgFile = g_sTempDir + "CCTVB_" + FObj->CCTV_CTLR_ID + ".bmp"; try { DeleteFile(sImgFile); } catch(...) {} String sDispBlob; try { sDispBlob = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString; if (sDispBlob == "Y") { BS = (TADOBlobStream *)pADO->CreateBlobStream(pADO->FieldByName("CCTV_SBST_IMGN"), bmRead); //ImgBlob->Picture->Graphic->LoadFromStream(BS); BS->SaveToFile(sImgFile); nFileSize = BS->Size; delete BS; } pADO->Close(); } catch(Exception &e) { delete BS; PnlBlob->Caption = "´ëü¿µ»ó À̹ÌÁö ½ºÆ®¸² ·Îµù ½ÇÆÐ"; return; } if (sDispBlob == "Y") { FDispBlob = true; PnlBlob->Visible = true; PnlBack->Visible = false; if (nFileSize) { try { ImgBlob->Picture->LoadFromFile(sImgFile); return; } catch(...) { ImgBlob->Visible = false; PnlBlob->Caption = "´ëü¿µ»ó À̹ÌÁö ÆÄÀÏ ·Îµù ½ÇÆÐ"; return; } } else { ImgBlob->Visible = false; PnlBlob->Caption = "´ëü¿µ»ó À̹ÌÁö »çÀÌÁî ¿À·ù"; } } else { FDispBlob = false; PnlBlob->Visible = false; PnlBack->Visible = true; } } //---------------------------------------------------------------------------