📄 netsdkdemodlg.cpp
字号:
// 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 "DiskControl.h"
#include "usermanage.h"
#include "configmaindlg.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
#pragma data_seg("sharesec")
__declspec (allocate("sharesec")) HWND g_share_hWnd = NULL;
#pragma comment(linker,"/SECTION:sharesec,RWS")
/////////////////////////////////////////////////////////////////////////////
// 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);
}
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_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_TREE_DEVICELIST, m_devicelist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNetSDKDemoDlg, CDialog)
//{{AFX_MSG_MAP(CNetSDKDemoDlg)
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()
//}}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(" %s[%s] %02d", pDev->Name,pDev->IP, mParam->iChannel + 1);
str = MSG_DEMODLG_MONITOR + str;
// for(int j = 0; j < pDev->State.channelcount; j++)
// {
if(*(pDev->State.cState.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);
Getversion();
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)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//初始化网络sdk,所有调用的开始
BOOL ret = CLIENT_Init(DisConnectFunc, (DWORD)this);
if (!ret)
{
LastError();
}
//设置信息回调函数,默认接收所有设备信息
CLIENT_SetDVRMessCallBack(MessCallBack, (DWORD)this);
//初始化各子窗口
m_selectPannel.Create(IDD_PANNEL_SELECT, this);
//m_screenPannel.Create(IDD_PANNEL_SCREEN, this);
m_screenPannel.Create(
NULL,
NULL,
WS_CHILD|WS_VISIBLE,
CRect(0,0,0,0),
this,
1981);
m_saveDataPannel.Create(IDD_PANNEL_SAVEDATA, this);
m_colorPannel.Create(IDD_PANNEL_COLOR, this);
m_playctrlPannel.Create(IDD_PANNEL_PLAYCTRL, this);
m_normalBtnPannel.Create(IDD_PANNEL_NORMAL_BTN, this);
m_advanceBtnPannel.Create(IDD_PANNEL_ADVANCE_BTN, this);
m_ptzPannel.Create(IDD_PANNEL_PTZ, this);
m_runtimeMsgPannel.Create(IDD_PANNEL_RUNTIME_MSG, this);
UpdatePannelPosition();
m_selectPannel.ShowWindow(SW_SHOW);
m_screenPannel.ShowWindow(SW_SHOW);
m_saveDataPannel.ShowWindow(SW_HIDE);
m_colorPannel.ShowWindow(SW_HIDE);
m_playctrlPannel.ShowWindow(SW_HIDE);
m_devicelist.ShowWindow(SW_SHOW);
m_advanceBtnPannel.ShowWindow(SW_HIDE);
m_ptzPannel.ShowWindow(SW_HIDE);
m_runtimeMsgPannel.ShowWindow(SW_SHOW);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -