// RemoteDetectConfig.cpp : implementation file // #include "stdafx.h" #include "StoneU_HC_OCX.h" #include "RemoteDetectConfig.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern LPNET_DVR_MOTION lpMotionDetect; int m_idetectnum; RECT g_ShowRect[2]; RECT g_MouseRect[2]; ///////////////////////////////////////////////////////////////////////////// // CRemoteDetectConfig dialog void CALLBACK DrawFunShow(long nPort,HDC hDc,DWORD nUser) { TRACE("show motion detect area."); CRect rect; int i = 0,j = 0; CPoint point; for(i = 0;i<18;i++) { for(j = 0;j<22;j++) { if(lpMotionDetect->byMotionScope[i][j] == 1) { point.x = j*16; point.y = i*16; rect.left = point.x; rect.top = point.y; rect.right = point.x + 16; rect.bottom = point.y + 16; ::DrawEdge(hDc,&rect,BDR_SUNKENOUTER,BF_RECT); } } } SetBkMode(hDc,TRANSPARENT); } void CALLBACK DrawFun(long nPort,HDC hDc,DWORD nUser) { for(int i=0;ibyMotionSensitive); if(lpMotionDetect->byMotionSensitive == 0xFF) { m_SensitivityCtrl.SetCurSel(0); } else { m_SensitivityCtrl.SetCurSel(lpMotionDetect->byMotionSensitive+1); } F_ShowRecordChan(m_iChannelnumber); playstru.hPlayWnd = m_DetectPic.GetSafeHwnd(); playstru.lChannel = m_iChannel; playstru.lLinkMode = 0; playstru.sMultiCastIP = ""; m_iPlayhandle = NET_DVR_RealPlay(m_lServerID, &playstru); if(m_iPlayhandle == -1) { CString sTemp; sTemp.Format("网络连接失败!"); MessageBox(sTemp, "温馨提示", MB_ICONINFORMATION); } m_bDrawdetect = FALSE; m_bSetMotion = FALSE; m_bHandleType1 = lpMotionDetect->strMotionHandleType.dwHandleType &0x01; m_bHandleType2 = (lpMotionDetect->strMotionHandleType.dwHandleType>>1)&0x01; m_bHandleType3 = (lpMotionDetect->strMotionHandleType.dwHandleType>>2)&0x01; m_bHandleType4 = (lpMotionDetect->strMotionHandleType.dwHandleType>>3)&0x01; m_bHandleType5 = (lpMotionDetect->strMotionHandleType.dwHandleType>>4)&0x01; EnableControl(m_bHandleType4); m_WeekDayCtrl.SetCurSel(0); m_CopyTimeCtrl.SetCurSel(0); m_iHour11 = lpMotionDetect->struAlarmTime[0][0].byStartHour; m_iMin11 = lpMotionDetect->struAlarmTime[0][0].byStartMin; m_iHour12 = lpMotionDetect->struAlarmTime[0][0].byStopHour; m_iMin12 = lpMotionDetect->struAlarmTime[0][0].byStopMin; m_iHour21 = lpMotionDetect->struAlarmTime[0][1].byStartHour; m_iMin21 = lpMotionDetect->struAlarmTime[0][1].byStartMin; m_iHour22 = lpMotionDetect->struAlarmTime[0][1].byStopHour; m_iMin22 = lpMotionDetect->struAlarmTime[0][1].byStopMin; m_iHour31 = lpMotionDetect->struAlarmTime[0][2].byStartHour; m_iMin31 = lpMotionDetect->struAlarmTime[0][2].byStartMin; m_iHour32 = lpMotionDetect->struAlarmTime[0][2].byStopHour; m_iMin32 = lpMotionDetect->struAlarmTime[0][2].byStopMin; m_iHour41 = lpMotionDetect->struAlarmTime[0][3].byStartHour; m_iMin41 = lpMotionDetect->struAlarmTime[0][3].byStartMin; m_iHour42 = lpMotionDetect->struAlarmTime[0][3].byStopHour; m_iMin42 = lpMotionDetect->struAlarmTime[0][3].byStopMin; GetDlgItem(IDC_CHECKGETRECT)->EnableWindow(TRUE); GetDlgItem(IDC_CHECKSETRECT)->EnableWindow(TRUE); GetDlgItem(IDMOTIONOK)->EnableWindow(TRUE); UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CRemoteDetectConfig::OnCheckgetrect() { // TODO: Add your control notification handler code here if(m_iPlayhandle < 0) return; UpdateData(TRUE); if(m_bSetdetect) { m_bSetdetect = FALSE; m_bDrawdetect = FALSE; UpdateData(FALSE); } if(m_bShowdetect) { NET_DVR_RigisterDrawFun(m_iPlayhandle,NULL, 0); Sleep(200); NET_DVR_RigisterDrawFun(m_iPlayhandle,DrawFunShow, 0); } else { NET_DVR_RigisterDrawFun(m_iPlayhandle,NULL, 0); } } void CRemoteDetectConfig::OnChecksetrect() { // TODO: Add your control notification handler code here //设置移动侦测区域 if(m_iPlayhandle < 0) return; UpdateData(TRUE); if(m_bShowdetect) { m_bShowdetect = FALSE; UpdateData(FALSE); } if(m_bSetdetect) { NET_DVR_RigisterDrawFun(m_iPlayhandle,NULL,0); m_idetectnum = 0; m_bDrawdetect = TRUE; m_bSetMotion = TRUE; } else { m_bDrawdetect = FALSE; NET_DVR_RigisterDrawFun(m_iPlayhandle,NULL,0); } } void CRemoteDetectConfig::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (m_bDrawdetect) { if(MK_CONTROL&nFlags) { NET_DVR_RigisterDrawFun(m_iPlayhandle, DrawFun, 0); if (m_idetectnum >=2) m_idetectnum = 0; point.x -= 5; point.y -= 10; g_MouseRect[m_idetectnum].left=point.x/16*16; g_MouseRect[m_idetectnum].top=point.y/16*16; g_MouseRect[m_idetectnum].right=g_MouseRect[m_idetectnum].left; g_MouseRect[m_idetectnum].bottom=g_MouseRect[m_idetectnum].top; POINT tPoint=point; g_ShowRect[m_idetectnum].left=tPoint.x/16*16; g_ShowRect[m_idetectnum].top=tPoint.y/16*16; g_ShowRect[m_idetectnum].right=tPoint.x/16*16+1; g_ShowRect[m_idetectnum].bottom=tPoint.y/16*16+1; m_idetectnum ++; } } CDialog::OnLButtonDown(nFlags, point); } void CRemoteDetectConfig::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (m_bDrawdetect) { if(MK_CONTROL&nFlags&&MK_LBUTTON&nFlags) { point.x -= 5; point.y -= 10; g_MouseRect[m_idetectnum-1].right=point.x/16*16; g_MouseRect[m_idetectnum-1].bottom=point.y/16*16; POINT tPoint=point; g_ShowRect[m_idetectnum-1].right=tPoint.x/16*16; g_ShowRect[m_idetectnum-1].bottom=tPoint.y/16*16; m_bIsResetMotion = true; } } CDialog::OnMouseMove(nFlags, point); } void CRemoteDetectConfig::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CDialog::OnTimer(nIDEvent); } void CRemoteDetectConfig::OnMotionok() { // TODO: Add your control notification handler code here UpdateData(TRUE); int i = 0,j = 0,k = 0; if(!F_TimeTest()) return; i = m_WeekDayCtrl.GetCurSel(); lpMotionDetect->struAlarmTime[i][0].byStartHour = m_iHour11; lpMotionDetect->struAlarmTime[i][0].byStartMin = m_iMin11; lpMotionDetect->struAlarmTime[i][0].byStopHour = m_iHour12; lpMotionDetect->struAlarmTime[i][0].byStopMin = m_iMin12; lpMotionDetect->struAlarmTime[i][1].byStartHour = m_iHour21; lpMotionDetect->struAlarmTime[i][1].byStartMin = m_iMin21; lpMotionDetect->struAlarmTime[i][1].byStopHour = m_iHour22; lpMotionDetect->struAlarmTime[i][1].byStopMin = m_iMin22; lpMotionDetect->struAlarmTime[i][2].byStartHour = m_iHour31; lpMotionDetect->struAlarmTime[i][2].byStartMin = m_iMin31; lpMotionDetect->struAlarmTime[i][2].byStopHour = m_iHour32; lpMotionDetect->struAlarmTime[i][2].byStopMin = m_iMin32; lpMotionDetect->struAlarmTime[i][3].byStartHour = m_iHour41; lpMotionDetect->struAlarmTime[i][3].byStartMin = m_iMin41; lpMotionDetect->struAlarmTime[i][3].byStopHour = m_iHour42; lpMotionDetect->struAlarmTime[i][3].byStopMin = m_iMin42; if( m_bIsResetMotion )//if(m_bSetMotion) { for(i = 0; i < 18; i++) { for(j = 0; j < 22; j++) lpMotionDetect->byMotionScope[i][j] = 0; } for(k = 0; k < m_idetectnum; k++) { if (g_MouseRect[k].top <= g_MouseRect[k].bottom) { if (g_MouseRect[k].left <= g_MouseRect[k].right) { for(i = g_MouseRect[k].top/16; i < 18 && i < g_MouseRect[k].bottom/16; i++) { for(j = g_MouseRect[k].left/16; j < 22 && j < g_MouseRect[k].right/16; j++) { lpMotionDetect->byMotionScope[i][j] = 1; } } } else { for(i = g_MouseRect[k].top/16; i < 18 && i < g_MouseRect[k].bottom/16; i++) { for(j = g_MouseRect[k].right/16; j < 22 && j < g_MouseRect[k].left/16; j++) { lpMotionDetect->byMotionScope[i][j] = 1; } } } } else { if (g_MouseRect[k].left <= g_MouseRect[k].right) { for(i = g_MouseRect[k].bottom/16; i < 18 && i < g_MouseRect[k].top/16; i++) { for(j = g_MouseRect[k].left/16; j < 22 && j < g_MouseRect[k].right/16; j++) { lpMotionDetect->byMotionScope[i][j] = 1; } } } else { for(i = g_MouseRect[k].bottom/16; i < 18 && i < g_MouseRect[k].top/16; i++) { for(j = g_MouseRect[k].right/16; j < 22 && j < g_MouseRect[k].left/16; j++) { lpMotionDetect->byMotionScope[i][j] = 1; } } } } } } m_idetectnum = 0; if(m_SensitivityCtrl.GetCurSel() == 0) { lpMotionDetect->byMotionSensitive = 0xFF; } else { lpMotionDetect->byMotionSensitive = m_SensitivityCtrl.GetCurSel()-1; } lpMotionDetect->strMotionHandleType.dwHandleType = 0; lpMotionDetect->strMotionHandleType.dwHandleType |= (m_bHandleType1 << 0); lpMotionDetect->strMotionHandleType.dwHandleType |= (m_bHandleType2 << 1); lpMotionDetect->strMotionHandleType.dwHandleType |= (m_bHandleType3 << 2); lpMotionDetect->strMotionHandleType.dwHandleType |= (m_bHandleType4 << 3); lpMotionDetect->strMotionHandleType.dwHandleType |= (m_bHandleType5 << 4); lpMotionDetect->strMotionHandleType.byRelAlarmOut[0] = m_bAlarmOut1; lpMotionDetect->strMotionHandleType.byRelAlarmOut[1] = m_bAlarmOut2; lpMotionDetect->strMotionHandleType.byRelAlarmOut[2] = m_bAlarmOut3; lpMotionDetect->strMotionHandleType.byRelAlarmOut[3] = m_bAlarmOut4; lpMotionDetect->byRelRecordChan[0] = m_bRecordChan1; lpMotionDetect->byRelRecordChan[1] = m_bRecordChan2; lpMotionDetect->byRelRecordChan[2] = m_bRecordChan3; lpMotionDetect->byRelRecordChan[3] = m_bRecordChan4; lpMotionDetect->byRelRecordChan[4] = m_bRecordChan5; lpMotionDetect->byRelRecordChan[5] = m_bRecordChan6; lpMotionDetect->byRelRecordChan[6] = m_bRecordChan7; lpMotionDetect->byRelRecordChan[7] = m_bRecordChan8; lpMotionDetect->byRelRecordChan[8] = m_bRecordChan9; lpMotionDetect->byRelRecordChan[9] = m_bRecordChan10; lpMotionDetect->byRelRecordChan[10] = m_bRecordChan11; lpMotionDetect->byRelRecordChan[11] = m_bRecordChan12; lpMotionDetect->byRelRecordChan[12] = m_bRecordChan13; lpMotionDetect->byRelRecordChan[13] = m_bRecordChan14; lpMotionDetect->byRelRecordChan[14] = m_bRecordChan15; lpMotionDetect->byRelRecordChan[15] = m_bRecordChan16; m_bIsResetMotion = false; } void CRemoteDetectConfig::OnExit() { // TODO: Add your control notification handler code here if(m_iPlayhandle >= 0) { NET_DVR_RigisterDrawFun(m_iPlayhandle, NULL, 0); NET_DVR_StopRealPlay(m_iPlayhandle); m_iPlayhandle = -1; } CDialog::OnOK(); } void CRemoteDetectConfig::OnCancel() { // TODO: Add extra cleanup here // CDialog::OnCancel(); } void CRemoteDetectConfig::EnableControl(BOOL bEnable) { if(m_dwAlarmOutNum >= 1) { GetDlgItem(IDC_CHKALARMOUT1)->EnableWindow(bEnable); m_bAlarmOut1 = lpMotionDetect->strMotionHandleType.byRelAlarmOut[0]; } if(m_dwAlarmOutNum >= 2) { GetDlgItem(IDC_CHKALARMOUT2)->EnableWindow(bEnable); m_bAlarmOut2 = lpMotionDetect->strMotionHandleType.byRelAlarmOut[1]; } if(m_dwAlarmOutNum >= 3) { GetDlgItem(IDC_CHKALARMOUT3)->EnableWindow(bEnable); m_bAlarmOut3 = lpMotionDetect->strMotionHandleType.byRelAlarmOut[2]; } if(m_dwAlarmOutNum >= 4) { GetDlgItem(IDC_CHKALARMOUT4)->EnableWindow(bEnable); m_bAlarmOut4 = lpMotionDetect->strMotionHandleType.byRelAlarmOut[3]; } } void CRemoteDetectConfig::OnCheckhandletype4() { // TODO: Add your control notification handler code here UpdateData(TRUE); EnableControl(m_bHandleType4); } BOOL CRemoteDetectConfig::F_ShowRecordChan(int nChan) { if(nChan>=1) { GetDlgItem(IDC_RECORDCHAN1)->EnableWindow(TRUE); m_bRecordChan1 = lpMotionDetect->byRelRecordChan[0]; } if(nChan>=2) { GetDlgItem(IDC_RECORDCHAN2)->EnableWindow(TRUE); m_bRecordChan2 = lpMotionDetect->byRelRecordChan[1]; } if(nChan>=3) { GetDlgItem(IDC_RECORDCHAN3)->EnableWindow(TRUE); m_bRecordChan3 = lpMotionDetect->byRelRecordChan[2]; } if(nChan>=4) { GetDlgItem(IDC_RECORDCHAN4)->EnableWindow(TRUE); m_bRecordChan4 = lpMotionDetect->byRelRecordChan[3]; } if(nChan>=5) { GetDlgItem(IDC_RECORDCHAN5)->EnableWindow(TRUE); m_bRecordChan5 = lpMotionDetect->byRelRecordChan[4]; } if(nChan>=6) { GetDlgItem(IDC_RECORDCHAN6)->EnableWindow(TRUE); m_bRecordChan6 = lpMotionDetect->byRelRecordChan[5]; } if(nChan>=7) { GetDlgItem(IDC_RECORDCHAN7)->EnableWindow(TRUE); m_bRecordChan7 = lpMotionDetect->byRelRecordChan[6]; } if(nChan>=8) { GetDlgItem(IDC_RECORDCHAN8)->EnableWindow(TRUE); m_bRecordChan8 = lpMotionDetect->byRelRecordChan[7]; } if(nChan>=9) { GetDlgItem(IDC_RECORDCHAN9)->EnableWindow(TRUE); m_bRecordChan9 = lpMotionDetect->byRelRecordChan[8]; } if(nChan>=10) { GetDlgItem(IDC_RECORDCHAN10)->EnableWindow(TRUE); m_bRecordChan10 = lpMotionDetect->byRelRecordChan[9]; } if(nChan>=11) { GetDlgItem(IDC_RECORDCHAN11)->EnableWindow(TRUE); m_bRecordChan11 = lpMotionDetect->byRelRecordChan[10]; } if(nChan>=12) { GetDlgItem(IDC_RECORDCHAN12)->EnableWindow(TRUE); m_bRecordChan12 = lpMotionDetect->byRelRecordChan[11]; } if(nChan>=13) { GetDlgItem(IDC_RECORDCHAN13)->EnableWindow(TRUE); m_bRecordChan13 = lpMotionDetect->byRelRecordChan[12]; } if(nChan>=14) { GetDlgItem(IDC_RECORDCHAN14)->EnableWindow(TRUE); m_bRecordChan14 = lpMotionDetect->byRelRecordChan[13]; } if(nChan>=15) { GetDlgItem(IDC_RECORDCHAN15)->EnableWindow(TRUE); m_bRecordChan15 = lpMotionDetect->byRelRecordChan[14]; } if(nChan>=16) { GetDlgItem(IDC_RECORDCHAN16)->EnableWindow(TRUE); m_bRecordChan16 = lpMotionDetect->byRelRecordChan[15]; } return TRUE; } void CRemoteDetectConfig::OnMotiontimeok() { // TODO: Add your control notification handler code here UpdateData(TRUE); if(!F_TimeTest()) return; int i = m_WeekDayCtrl.GetCurSel(); lpMotionDetect->struAlarmTime[i][0].byStartHour = m_iHour11; lpMotionDetect->struAlarmTime[i][0].byStartMin = m_iMin11; lpMotionDetect->struAlarmTime[i][0].byStopHour = m_iHour12; lpMotionDetect->struAlarmTime[i][0].byStopMin = m_iMin12; lpMotionDetect->struAlarmTime[i][1].byStartHour = m_iHour21; lpMotionDetect->struAlarmTime[i][1].byStartMin = m_iMin21; lpMotionDetect->struAlarmTime[i][1].byStopHour = m_iHour22; lpMotionDetect->struAlarmTime[i][1].byStopMin = m_iMin22; lpMotionDetect->struAlarmTime[i][2].byStartHour = m_iHour31; lpMotionDetect->struAlarmTime[i][2].byStartMin = m_iMin31; lpMotionDetect->struAlarmTime[i][2].byStopHour = m_iHour32; lpMotionDetect->struAlarmTime[i][2].byStopMin = m_iMin32; lpMotionDetect->struAlarmTime[i][3].byStartHour = m_iHour41; lpMotionDetect->struAlarmTime[i][3].byStartMin = m_iMin41; lpMotionDetect->struAlarmTime[i][3].byStopHour = m_iHour42; lpMotionDetect->struAlarmTime[i][3].byStopMin = m_iMin42; GetDlgItem(IDC_MOTIONTIMECOPY)->EnableWindow(TRUE); } void CRemoteDetectConfig::OnMotiontimecopy() { // TODO: Add your control notification handler code here UpdateData(TRUE); int j,k; int i = m_WeekDayCtrl.GetCurSel(); int m_nCopyTime = m_CopyTimeCtrl.GetCurSel() - 1; if(m_nCopyTime == -1) { for(j=0; jstruAlarmTime[j][k]), &(lpMotionDetect->struAlarmTime[i][k]), sizeof(NET_DVR_SCHEDTIME)); } } } else { for(k=0; kstruAlarmTime[m_nCopyTime][k]), &(lpMotionDetect->struAlarmTime[i][k]), sizeof(NET_DVR_SCHEDTIME)); } } } void CRemoteDetectConfig::OnSelchangeComboweekday() { // TODO: Add your control notification handler code here UpdateData(TRUE); int i = m_WeekDayCtrl.GetCurSel(); m_iHour11 = lpMotionDetect->struAlarmTime[i][0].byStartHour; m_iMin11 = lpMotionDetect->struAlarmTime[i][0].byStartMin; m_iHour12 = lpMotionDetect->struAlarmTime[i][0].byStopHour; m_iMin12 = lpMotionDetect->struAlarmTime[i][0].byStopMin; m_iHour21 = lpMotionDetect->struAlarmTime[i][1].byStartHour; m_iMin21 = lpMotionDetect->struAlarmTime[i][1].byStartMin; m_iHour22 = lpMotionDetect->struAlarmTime[i][1].byStopHour; m_iMin22 = lpMotionDetect->struAlarmTime[i][1].byStopMin; m_iHour31 = lpMotionDetect->struAlarmTime[i][2].byStartHour; m_iMin31 = lpMotionDetect->struAlarmTime[i][2].byStartMin; m_iHour32 = lpMotionDetect->struAlarmTime[i][2].byStopHour; m_iMin32 = lpMotionDetect->struAlarmTime[i][2].byStopMin; m_iHour41 = lpMotionDetect->struAlarmTime[i][3].byStartHour; m_iMin41 = lpMotionDetect->struAlarmTime[i][3].byStartMin; m_iHour42 = lpMotionDetect->struAlarmTime[i][3].byStopHour; m_iMin42 = lpMotionDetect->struAlarmTime[i][3].byStopMin; UpdateData(FALSE); } BOOL CRemoteDetectConfig::F_TimeTest() { int i, j; WORD wStartTime[4], wStopTime[4]; UpdateData(TRUE); if( (m_iHour11 < 0) || (m_iHour11 > 24) || (m_iHour12 < 0) || (m_iHour12 > 24) || \ (m_iHour21 < 0) || (m_iHour21 > 24) || (m_iHour22 < 0) || (m_iHour22 > 24) || \ (m_iHour31 < 0) || (m_iHour31 > 24) || (m_iHour32 < 0) || (m_iHour32 > 24) || \ (m_iHour41 < 0) || (m_iHour41 > 24) || (m_iHour42 < 0) || (m_iHour42 > 24) ) { MessageBox("小时的范围在0 -- 24之间!", "温馨提示", MB_ICONINFORMATION); return FALSE; } if( (m_iMin11 < 0) || (m_iMin11 > 60) || (m_iMin12 < 0) || (m_iMin12 > 60) || \ (m_iMin21 < 0) || (m_iMin21 > 60) || (m_iMin22 < 0) || (m_iMin22 > 60) || \ (m_iMin31 < 0) || (m_iMin31 > 60) || (m_iMin32 < 0) || (m_iMin32 > 60) || \ (m_iMin41 < 0) || (m_iMin41 > 60) || (m_iMin42 < 0) || (m_iMin42 > 60) ) { MessageBox("分钟的范围在0 -- 60之间!", "温馨提示", MB_ICONINFORMATION); return FALSE; } wStartTime[0] = m_iHour11 * 100 + m_iMin11; wStartTime[1] = m_iHour21 * 100 + m_iMin21; wStartTime[2] = m_iHour31 * 100 + m_iMin31; wStartTime[3] = m_iHour41 * 100 + m_iMin41; wStopTime[0] = m_iHour12 * 100 + m_iMin12; wStopTime[1] = m_iHour22 * 100 + m_iMin22; wStopTime[2] = m_iHour32 * 100 + m_iMin32; wStopTime[3] = m_iHour42 * 100 + m_iMin42; for(i = 0; i < 4; i++) { if( (wStartTime[i] > 2400) || (wStopTime[i] > 2400) ) { MessageBox("布防时间不能超过24:00!", "温馨提示", MB_ICONINFORMATION); return FALSE; } if(wStartTime[i] > wStopTime[i]) { MessageBox("布防起始时间不能大于停止时间!", "温馨提示", MB_ICONINFORMATION); return FALSE; } for(j = 0; j < 4; j++) { if (i == j) continue; if( (wStartTime[i] > wStartTime[j]) && (wStartTime[i] < wStopTime[j]) || \ (wStopTime[i] > wStartTime[j]) && (wStopTime[i] < wStopTime[j]) ) { MessageBox("布防时间段不能重复!", "温馨提示", MB_ICONINFORMATION); return FALSE; } } } return TRUE; }