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

📄 netsdkdemodlg.cpp

📁 它是一个可以实时交互的嵌入式软件系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
   // NetSDKDemoDlg.cpp : implementation file

#include "stdafx.h"
#include "NetSDKDemo.h"
#include "NetSDKDemoDlg.h"
#include "splitinfodlg.h"
#include "adddevicedlg.h"
#include "searchrecord.h"
#include "systemconfig.h"
#include "dhextptzctrl.h"
#include "dhptzmenu.h"
#include "transcom.h"
#include "recordctrldlg.h"
#include "deviceworkstate.h"
#include "alarmctrldlg.h"
#include "cyclemonitor.h"
#include "systemcfg.h"
#include "direct.h"
#include "playbackbytime.h"
#include "downloadbytime.h"
#include "NetUpgrade.h"
#include "DDNS_QueryIP.h"
#include "IrDlg.h"
#include  "Winsock2.h" 
/*
/////////////////////////////////////////
//console
////////////////////////////////////////
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <iostream>
#include <fstream>
*/


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CNetSDKDemoApp theApp;
#pragma data_seg("sharesec")
__declspec (allocate("sharesec")) HWND g_share_hWnd = NULL;
#pragma comment(linker,"/SECTION:sharesec,RWS")


#define CUR_MAXCHAN 16
#define	CUR_SPLIT	SPLIT16

extern CNetSDKDemoApp theApp;
UserInfo *g_userinfo_main[10];
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

/*

using namespace std;

static const WORD MAX_CONSOLE_LINES = 500;

void RedirectIOToConsole()
{
	int hConHandle;
	long lStdHandle;
	
	CONSOLE_SCREEN_BUFFER_INFO coninfo; // 控制台信息
	FILE *fp;
	
	// allocate a console for this app
	AllocConsole();  // 打开一个控制台
	
	// set the screen buffer to be big enough to let us scroll text
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
	
	// 设置控制台参数
	coninfo.dwSize.Y = MAX_CONSOLE_LINES;
	SetConsoleScreenBufferSize(
		GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
	
	// redirect unbuffered STDOUT to the console
	lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); 
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); 
	
	fp = _fdopen(hConHandle, "w" );
	*stdout = *fp; // 为全局c变量stdout赋值,使用自己打开的控制台.
	setvbuf(stdout, NULL, _IONBF, 0);
	
	// redirect unbuffered STDIN to the console
	lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
	fp = _fdopen( hConHandle, "r");
	*stdin = *fp;
	setvbuf(stdin, NULL, _IONBF, 0);
	
	// redirect unbuffered STDERR to the console
	lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
	fp = _fdopen(hConHandle, "w");
	*stderr = *fp;
	setvbuf(stderr, NULL, _IONBF, 0);
	
	// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog 
	// point to console as well
	ios::sync_with_stdio();
}
*/

inline void dbg_print_ex(int level, const char *msg, ...)
{
	char buf[256];
	
	va_list ap;
	va_start(ap, msg); // use variable arg list
	vsprintf(buf, msg, ap);
	va_end( ap );
	
	OutputDebugString(buf);
}
extern CNetSDKDemoApp theApp;
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetSDKDemoDlg dialog

CNetSDKDemoDlg::CNetSDKDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNetSDKDemoDlg::IDD, pParent)
{
	m_connectwaittime = 3000;
	m_myBrush.CreateSolidBrush(RGB(255,255,255));
	//{{AFX_DATA_INIT(CNetSDKDemoDlg)
	m_ptz_data = 5;
	m_play_frame = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = 0;//AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CNetSDKDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNetSDKDemoDlg)
	DDX_Control(pDX, IDC_BUTTON_DOWN, m_btn_down);
	DDX_Control(pDX, IDC_BUTTON_CNL, m_btn_cnl);
	DDX_Control(pDX, IDC_BUTTON_VOD, m_btn_vod);
	DDX_Control(pDX, IDC_BUTTON_UP, m_btn_up);
	DDX_Control(pDX, IDC_BUTTON_RIGHT, m_btn_right);
	DDX_Control(pDX, IDC_BUTTON_OK, m_btn_ok);
	DDX_Control(pDX, IDC_BUTTON_LEFT, m_btn_left);
	DDX_Control(pDX, IDC_BUTTON_FOS, m_btn_fos);
	DDX_Control(pDX, IDC_BUTTON_DVR, m_btn_dvr);
	DDX_Control(pDX, IDC_BUTTON_PZT, m_btn_ptz);
	DDX_Control(pDX, IDC_BUTTON_SETUP, m_btn_setup);
	DDX_Control(pDX, IDC_BUTTON_MIN, m_btn_min);
	DDX_Control(pDX, IDC_BUTTON_CLOSE, m_btn_close);
	DDX_Control(pDX, IDC_LOGO, m_logopic);
	DDX_Control(pDX, IDC_STATICTOP, m_toppic);
	DDX_Control(pDX, IDC_STATICRIGHT, m_rightpic);
	DDX_Control(pDX, IDC_STATICLEFT, m_leftpic);
	DDX_Control(pDX, IDC_STATICRMTCTL, m_rmtctl);
	DDX_Control(pDX, IDC_TREE_DEVICELIST, m_devicelist);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNetSDKDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CNetSDKDemoDlg)
	ON_MESSAGE(WM_IR_RECIEVE, OnIRRecieve) 
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_WM_TIMER()
	ON_WM_CTLCOLOR()
	ON_NOTIFY(NM_DBLCLK, IDC_TREE_DEVICELIST, OnDblclkTreeDevicelist)
	ON_WM_SIZE()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnCloseWindow)
	ON_BN_CLICKED(IDC_BUTTON_MIN, OnWindowMin)
	ON_BN_CLICKED(IDC_BUTTON_SETUP, OnButtonSetup)
	ON_NOTIFY(TVN_KEYDOWN, IDC_TREE_DEVICELIST, OnKeydownTreeDevicelist)
	ON_BN_CLICKED(IDC_BUTTON_DVR, OnButtonDvr)
	ON_BN_CLICKED(IDC_BUTTON_CNL, OnButtonCnl)
	ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp)
	ON_BN_CLICKED(IDC_BUTTON_DOWN, OnButtonDown)
	ON_BN_CLICKED(IDC_BUTTON_LEFT, OnButtonLeft)
	ON_BN_CLICKED(IDC_BUTTON_RIGHT, OnButtonRight)
	ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOk)
	ON_BN_CLICKED(IDC_BUTTON_FOS, OnButtonFos)
	ON_BN_CLICKED(IDC_BUTTON_VOD, OnButtonVod)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////初始化回调相关的函数////////////////////////////////////////////////
//设备断开时回调函数,可以用来处理断开后设备列表的更新及设备的删除操作
void CALLBACK DisConnectFunc(LONG lLoginID, char *pchDVRIP, LONG nDVRPort, DWORD dwUser)
{
	if(dwUser == 0)
	{
		return;
	}
	CNetSDKDemoDlg *dlg = (CNetSDKDemoDlg *)dwUser;
	dlg->DeviceDisConnect(lLoginID, pchDVRIP,nDVRPort);
}

//设备断开处理
void CNetSDKDemoDlg::DeviceDisConnect(LONG lLoginID, char *sDVRIP,LONG nDVRPort)
{
	DeviceNode node;
	int r = CDevMgr::GetDevMgr().GetDev(lLoginID, node);
	if (r < 0)
	{
		return ;
	}

	/*
	DeviceNode *nDev=(DeviceNode *)FindDeviceInfo(lLoginID, sDVRIP,nDVRPort);
	if(nDev == NULL)
	{
		return;
	}
	*/
	CString nStr;
	nStr.Format("%s device disconnect ",node.IP);

	ProcessDeleteDevice(&node, true, true);
	UpdateDeviceList();
	UpdateCurScreenInfo();
	
	MessageBox(nStr);
	UpdateScreen(m_normalBtnPannel.GetSplit());
//	Invalidate(true);
}

//消息回调处理函数,是对整个sdk应用的回调
BOOL CALLBACK MessCallBack(LONG lCommand, LONG lLoginID, char *pBuf, DWORD dwBufLen, 
						   char *pchDVRIP, LONG nDVRPort, DWORD dwUser)
{
	if(!dwUser) return FALSE;

	CNetSDKDemoDlg *dlg = (CNetSDKDemoDlg *)dwUser;
	return dlg ->ReceiveMessage(lLoginID, lCommand, pchDVRIP, nDVRPort,pBuf, dwBufLen);
}

//接收到设备消息的处理,目前只定义了报警消息回调
BOOL CNetSDKDemoDlg::ReceiveMessage(LONG lLoginID, LONG lCommand, char *pchDVRIP, LONG nDVRPort, 
		char *pBuf, DWORD dwBufLen)
{
//	EnterCriticalSection(&g_csAlarm);
//	CCSLock lk(g_cs);
/*
		if (!m_bShowStatus) 
		{
			return false;
		}*/
	int nRet = CDevMgr::GetDevMgr().SetAlarmInfo(lLoginID, lCommand, pchDVRIP, nDVRPort, 
		pBuf, dwBufLen);
	return nRet<0?FALSE:TRUE;
/*
	DeviceNode node;
	int r = CDevMgr::GetDevMgr().GetDev(lLoginID, node);
	if (r < 0)
	{
		LeaveCriticalSection(&g_csAlarm);
		return false;
	}

	DeviceNode *nDev = &node;

	DeviceNode *nDev = (DeviceNode *)FindDeviceInfo(lLoginID, pchDVRIP,nDVRPort );
	
	if(nDev == NULL)
	{
		goto e_exit;
	}
	

	switch(lCommand) {
	case COMM_ALARM:
	{
	 
					NET_CLIENT_STATE *ClientState = (NET_CLIENT_STATE *)pBuf;
					
					if(ClientState == NULL)
					{
						return FALSE;
					}
					
					printf("alarm infomation:\n");
					
					CString str;
					
					for(int i=0; i<ClientState->channelcount; i++)
					{
						CString strTemp;
						strTemp.Format("%d ", ClientState->record[i]);
						str += strTemp;
					}
					
					printf("alarm: Recording Status-- %s\n", str.GetBuffer(0));
					
					for(i=0; i<ClientState->alarminputcount; i++)
					{
						CString strTemp;
						strTemp.Format("%d ", ClientState->alarm[i]);
						str += strTemp;
					}
					
					printf("alarm: Extern Alarm-- %s\n", str.GetBuffer(0));
					
					
					for(i=0; i<ClientState->channelcount; i++)
					{
						CString strTemp;
						strTemp.Format("%d ", ClientState->motiondection[i]);
						str += strTemp;
					}
					
					printf("alarm: Motion Detect-- %s\n", str.GetBuffer(0));
					
					for(i=0; i<ClientState->channelcount; i++)
					{
						CString strTemp;
						strTemp.Format("%d ", ClientState->videolost[i]);
						str += strTemp;
					}
					
					printf("alarm: Video Lost-- %s\n", str.GetBuffer(0));
		
		}
		UpdateDeviceState(nDev, pBuf, dwBufLen);
		//m_ClientStateDlg.UpdateState(nDev,pBuf, dwBufLen);
		if(!m_ClientStateDlg.m_isNoMoreShow)
		{
			m_ClientStateDlg.ShowWindow(SW_SHOW);
		}
		break;
	default : 
		goto e_exit;
	}

//	LeaveCriticalSection(&g_csAlarm);
	return true;
e_exit:
//	LeaveCriticalSection(&g_csAlarm);
	return false;
	*/
/*

	DeviceNode *nDev = (DeviceNode *)FindDeviceInfo(lLoginID, pchDVRIP,nDVRPort );

	if(nDev == NULL)
	{
		m_bShowStatus = FALSE;
		return false;
	}
	switch(lCommand) {
	case COMM_ALARM:
		UpdateDeviceState(nDev, pBuf, dwBufLen);
		m_ClientStateDlg.UpdateState(nDev,pBuf, dwBufLen);
		if(!m_ClientStateDlg.m_isNoMoreShow)
		{
			m_ClientStateDlg.ShowWindow(SW_SHOW);
		}
		break;
	default : 
		m_bShowStatus = FALSE;
		return false;
	}
	m_bShowStatus = FALSE;
	return true;*/

}

//自定义画板回调,可以用来显示通道信息
void CALLBACK ChannelAutoDraw(LONG lLoginID, LONG lPlayHandle, HDC hDC, DWORD dwUser)
{
	if(!dwUser) return;

	CNetSDKDemoDlg *dlg = (CNetSDKDemoDlg *)dwUser;
	dlg->AddDisplayInfo(lLoginID, lPlayHandle, hDC);
}

//叠加字符或图片
void CNetSDKDemoDlg::AddDisplayInfo(LONG lLoginID, LONG lPlayHandle, HDC hDC)
{
	DeviceNode *pDev;
	CString str;

	//取得窗口号
	int i = GetHandleSplit(lPlayHandle);
	if(i < 0)
	{
		return;
	}

	SplitInfoNode siNode;
	memset(&siNode, 0, sizeof(siNode));
	BOOL ret = GetSplitInfo_Main(i, &siNode);
	if (!ret)
	{
		return;
	}

	switch(siNode.Type) 
	{
	case SPLIT_TYPE_MONITOR:
		{
			SplitMonitorParam *mParam = (SplitMonitorParam *)siNode.Param;
			if (mParam)
			{
				pDev = mParam->pDevice;
				str.Format(" %02d",  mParam->iChannel + 1);
				str = MSG_DEMODLG_MONITOR + str;
			//	for(int j = 0; j < pDev->State.channelcount; j++)
			//	{
					if(*(pDev->State.motiondection + mParam->iChannel))
					{
						CString almstr;
						almstr.Format("! ALARM !");
						SetTextColor(hDC, RGB(255,0,0));
						CRect rect;
						//m_playWnd[i].GetClientRect(&rect);
						CWnd* pWnd = m_screenPannel.GetPage(i);
						if (!pWnd)
						{
							MessageBox("unexpected error!!");
						}
						pWnd->GetClientRect(&rect);
						if (pWnd && ::IsWindow(pWnd->GetSafeHwnd()))
						{
							TextOut(hDC, rect.right / 3, rect.bottom / 2, almstr.GetBuffer(0), almstr.GetLength());
						}
					//	break;
					}
			//	}
			}
		}
		break;
	case SPLIT_TYPE_MULTIPLAY:
		pDev = (DeviceNode *)siNode.Param;
		str.Format(" %s[%s]", pDev->Name,  pDev->IP);
		str = MSG_DEMODLG_PREVIEW + str;
		break;

	case SPLIT_TYPE_NETPLAY:
		{
			SplitNetPlayParam *nParam = (SplitNetPlayParam *)siNode.Param; 
			pDev = nParam->pFileInfo->pDevice;
			str.Format(" %s[%s]%02d", pDev->Name, pDev->IP, 
				nParam->pFileInfo->fileinfo.ch + 1);
			str = MSG_DEMODLG_PLAYBACKCHL + str;
		}
		break;
	case SPLIT_TYPE_PBBYTIME:
		{
			break;
		}
	case SPLIT_TYPE_CYCLEMONITOR:
		{
			SplitCycleParam *cParam = (SplitCycleParam *)siNode.Param;
			CycleChannelInfo *cci = 0;
			POSITION pos = cParam->pChannelList->GetHeadPosition();
			for (int counter = 0; counter <= cParam->iCurPosition; counter++)
			{
				cci = (CycleChannelInfo *)cParam->pChannelList->GetNext(pos);
			}
			pDev = (DeviceNode *)cci->dwDeviceID;
			str.Format(" %s[%s](%02d)", pDev->Name, pDev->IP, cci->iChannel + 1);
			str = MSG_DEMODLG_CYCLEMONITOR + str;
			break;
		}
	default :
		return;
	}

	SetBkMode(hDC, TRANSPARENT);
	SetTextColor(hDC, RGB(255,255,0));
	TextOut(hDC, 0, 0, str.GetBuffer(0), str.GetLength());
	
}
// CNetSDKDemoDlg message handlers
BOOL CNetSDKDemoDlg::OnInitDialog()
{
//	RedirectIOToConsole();
	if(g_share_hWnd)
	{
		AfxMessageBox(_T("Only one process allowed"));
		CWnd* pWnd = CWnd::FromHandle(g_share_hWnd);
		if(pWnd)
		{
			if (pWnd->IsIconic())
			{
				pWnd->ShowWindow(SW_RESTORE);
			}
			pWnd->SetForegroundWindow(); 
		}
		exit(0);
	}
	else
	{
		g_share_hWnd = m_hWnd;
	}
	CDialog::OnInitDialog();
	g_SetWndStaticText(this);
	
	char tmpDir[1000];
	_getcwd(tmpDir, 1000);
	g_strWorkDir.Format("%s", tmpDir);

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)

⌨️ 快捷键说明

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