⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remotedetectconfig.cpp

📁 监控开发资料,提供二次开发源码和使用说明书
💻 CPP
字号:
// RemoteDetectConfig.cpp : implementation file
//

#include "stdafx.h"
#include "newclient.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;i<m_idetectnum;i++)
		::DrawEdge(hDc,&g_ShowRect[i],BDR_SUNKENOUTER,BF_RECT);
	SetBkMode(hDc,TRANSPARENT);
}

CRemoteDetectConfig::CRemoteDetectConfig(CWnd* pParent /*=NULL*/)
	: CDialog(CRemoteDetectConfig::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRemoteDetectConfig)
	m_bShowdetect = FALSE;
	m_bSetdetect = FALSE;
	m_bHandleType1 = FALSE;
	m_bHandleType2 = FALSE;
	m_bHandleType3 = FALSE;
	m_bHandleType4 = FALSE;
	m_bAlarmOut1 = FALSE;
	m_bAlarmOut2 = FALSE;
	m_bAlarmOut3 = FALSE;
	m_bAlarmOut4 = FALSE;
	m_bRecordChan1 = FALSE;
	m_bRecordChan10 = FALSE;
	m_bRecordChan11 = FALSE;
	m_bRecordChan12 = FALSE;
	m_bRecordChan13 = FALSE;
	m_bRecordChan14 = FALSE;
	m_bRecordChan15 = FALSE;
	m_bRecordChan16 = FALSE;
	m_bRecordChan2 = FALSE;
	m_bRecordChan3 = FALSE;
	m_bRecordChan4 = FALSE;
	m_bRecordChan5 = FALSE;
	m_bRecordChan6 = FALSE;
	m_bRecordChan7 = FALSE;
	m_bRecordChan8 = FALSE;
	m_bRecordChan9 = FALSE;
	//}}AFX_DATA_INIT
}


void CRemoteDetectConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRemoteDetectConfig)
	DDX_Control(pDX, IDC_DETECTPIC, m_DetectPic);
	DDX_Control(pDX, IDC_COMBOSENSITIVE, m_SensitivityCtrl);
	DDX_Check(pDX, IDC_CHECKGETRECT, m_bShowdetect);
	DDX_Check(pDX, IDC_CHECKSETRECT, m_bSetdetect);
	DDX_Check(pDX, IDC_CHECKHANDLETYPE1, m_bHandleType1);
	DDX_Check(pDX, IDC_CHECKHANDLETYPE2, m_bHandleType2);
	DDX_Check(pDX, IDC_CHECKHANDLETYPE3, m_bHandleType3);
	DDX_Check(pDX, IDC_CHECKHANDLETYPE4, m_bHandleType4);
	DDX_Check(pDX, IDC_CHKALARMOUT1, m_bAlarmOut1);
	DDX_Check(pDX, IDC_CHKALARMOUT2, m_bAlarmOut2);
	DDX_Check(pDX, IDC_CHKALARMOUT3, m_bAlarmOut3);
	DDX_Check(pDX, IDC_CHKALARMOUT4, m_bAlarmOut4);
	DDX_Check(pDX, IDC_RECORDCHAN1, m_bRecordChan1);
	DDX_Check(pDX, IDC_RECORDCHAN10, m_bRecordChan10);
	DDX_Check(pDX, IDC_RECORDCHAN11, m_bRecordChan11);
	DDX_Check(pDX, IDC_RECORDCHAN12, m_bRecordChan12);
	DDX_Check(pDX, IDC_RECORDCHAN13, m_bRecordChan13);
	DDX_Check(pDX, IDC_RECORDCHAN14, m_bRecordChan14);
	DDX_Check(pDX, IDC_RECORDCHAN15, m_bRecordChan15);
	DDX_Check(pDX, IDC_RECORDCHAN16, m_bRecordChan16);
	DDX_Check(pDX, IDC_RECORDCHAN2, m_bRecordChan2);
	DDX_Check(pDX, IDC_RECORDCHAN3, m_bRecordChan3);
	DDX_Check(pDX, IDC_RECORDCHAN4, m_bRecordChan4);
	DDX_Check(pDX, IDC_RECORDCHAN5, m_bRecordChan5);
	DDX_Check(pDX, IDC_RECORDCHAN6, m_bRecordChan6);
	DDX_Check(pDX, IDC_RECORDCHAN7, m_bRecordChan7);
	DDX_Check(pDX, IDC_RECORDCHAN8, m_bRecordChan8);
	DDX_Check(pDX, IDC_RECORDCHAN9, m_bRecordChan9);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRemoteDetectConfig, CDialog)
	//{{AFX_MSG_MAP(CRemoteDetectConfig)
	ON_BN_CLICKED(IDC_CHECKGETRECT, OnCheckgetrect)
	ON_BN_CLICKED(IDC_CHECKSETRECT, OnChecksetrect)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDMOTIONOK, OnMotionok)
	ON_BN_CLICKED(IDEXIT, OnExit)
	ON_BN_CLICKED(IDC_CHECKHANDLETYPE4, OnCheckhandletype4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRemoteDetectConfig message handlers
BOOL CRemoteDetectConfig::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	NET_DVR_CLIENTINFO playstru;
	
	m_DetectPic.MoveWindow(DETECTPICTOP,DETECTPICTOP, 352, 288);
	TRACE("移动侦测灵敏度: %d", lpMotionDetect->byMotionSensitive);
	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("网络连接失败!");
		AfxMessageBox(sTemp);
	}	
	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;
	EnableControl(m_bHandleType4);
	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 -= DETECTPICLEFT;
			point.y -= DETECTPICTOP;
			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;
			g_ShowRect[m_idetectnum].top=tPoint.y;
			g_ShowRect[m_idetectnum].right=tPoint.x+1;
			g_ShowRect[m_idetectnum].bottom=tPoint.y+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 -= DETECTPICLEFT;
			point.y -= DETECTPICTOP; 
			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;
			g_ShowRect[m_idetectnum-1].bottom=tPoint.y;
		}
	}	
	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(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++)
		{
			for(i = g_MouseRect[k].top/16; i < g_MouseRect[k].bottom/16+1; i++)
			{
				for(j = g_MouseRect[k].left/16; j < g_MouseRect[k].right/16+1; 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.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;
}

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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -