123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #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;
- }
- }
- //---------------------------------------------------------------------------
|