📄 netsdkdemodlg.cpp
字号:
{
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_HIDE);
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_HIDE);
//初始化画面分割模式选择项
m_normalBtnPannel.InitSplit(CUR_SPLIT);
m_normalBtnPannel.ShowWindow(SW_HIDE);
m_curScreen = 0;
m_screenPannel.SetShowPlayWin(CUR_SPLIT, m_curScreen);
//设置连接等待时间
CLIENT_SetConnectTime(m_connectwaittime, 10);
LastError();
CLIENT_RigisterDrawFun(ChannelAutoDraw, (DWORD)this);
LastError();
// for (int j = 0; j < CUR_MAXCHAN; j++)
// {
// m_playWnd[j].Create(IDD_CHILD_PLAYWND, &m_screenPannel);//can't input this point,may be input
// m_playWnd[j].SetWinID(j);
// }
// m_originParent = 0;
// m_bFullSCRN = FALSE;
//初始化关闭声音
m_curSoundSplit = -1;
//创建状态页面和系统配置页面
m_ClientStateDlg.Create(IDD_CLIENT_STATE);
m_ClientStateDlg.CenterWindow();
m_ClientStateDlg.m_isNoMoreShow = TRUE;
m_ClientStateDlg.UpdateData(false);
//初始化云台控制状态
m_bPTZCtrl = FALSE;
//刷新界面信息
UpdateScreen(CUR_SPLIT+1);
UpdateCurScreenInfo();
//目前还没实现的功能
// GetDlgItem(IDC_UPDATECPROCESS)->EnableWindow(false);
// GetDlgItem(IDC_SETIFRAME)->EnableWindow(false);
// GetDlgItem(IDC_DEVICE_WORKSTATE)->EnableWindow(false);
//设置系统秒定时器,用于刷新码流统计和进度条并更新客户端信息
// m_bShowStatus = FALSE;
// SetTimer(TIMER_KBPS, 1111,NULL);
//实现全屏幕代码
SetWindowLong(this->GetSafeHwnd(),GWL_STYLE,0);
SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,0);
CRect rectDesktop;
::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
WINDOWPLACEMENT wp;
GetWindowPlacement (&wp);
wp.showCmd = SW_SHOWNORMAL;
wp.rcNormalPosition = rectDesktop;
SetWindowPlacement ( &wp );
//this->ShowWindow(SW_SHOWMAXIMIZED);
m_bSelectPanel=false;
this->m_bBright=false;
this->m_flashTime=0;
//this->m_btn_current=NULL;
//界面初始化
m_btn_close.SetBitmaps(IDB_CLOSE,0);
m_btn_min.SetBitmaps(IDB_MIN,0);
m_btn_setup.SetBitmaps(IDB_SETUP,0);
m_btn_ptz.SetBmp(IDB_PTZ,IDB_PTZB);
m_btn_ptz.SetBitmaps(IDB_PTZ,0);
m_btn_dvr.SetBmp(IDB_CTL_DVR,IDB_CTL_DVRB);
m_btn_dvr.SetBmp1();
m_btn_fos.SetBmp(IDB_CTL_FOS,IDB_CTL_FOSB);
m_btn_fos.SetBmp1();
m_btn_cnl.SetBmp(IDB_CTL_CNL,IDB_CTL_CNLB);
m_btn_cnl.SetBmp1();
m_btn_vod.SetBmp(IDB_CTL_VOD,IDB_CTL_VODB);
m_btn_vod.SetBmp1();
m_btn_up.SetBmp(IDB_CTL_UP,IDB_CTL_UPB);
m_btn_up.SetBmp1();
m_btn_down.SetBmp(IDB_CTL_DOWN,IDB_CTL_DOWNB);
m_btn_down.SetBmp1();
m_btn_left.SetBmp(IDB_CTL_LEFT,IDB_CTL_LEFTB);
m_btn_left.SetBmp1();
m_btn_right.SetBmp(IDB_CTL_RIGHT,IDB_CTL_RIGHTB);
m_btn_right.SetBmp1();
m_btn_ok.SetBmp(IDB_CTL_OK,IDB_CTL_OKB);
m_btn_ok.SetBmp1();
for(int j=0;j<6;j++)
{
m_ptzstop[j]=false;
}
for(int k=0;k<16;k++)
{
m_bFullSCRN[j]=false;
}
m_bVod=false;
isChannel=false;
this->UpdateData();
this->UpdateData(false);
this->InitlizeDevices();
//this->AddDevice();
return TRUE;
}
void CNetSDKDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CNetSDKDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CNetSDKDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
////////////////////////////////内部使用小接口函数///////////////////////////////////////////////////
//根据登录ID获取设备信息指针
void *CNetSDKDemoDlg::FindDeviceInfo(LONG lLoginID, char *sDVRIP,LONG nDVRPort)
{
/*
POSITION nPos;
DeviceNode *pInfo;
nPos = g_ptrdevicelist->GetHeadPosition();
for(int i = 0; i < g_ptrdevicelist->GetCount(); i ++ )
{
pInfo = (DeviceNode *)g_ptrdevicelist->GetNext(nPos);
if(pInfo->LoginID == lLoginID)
{
return pInfo;
}
}
*/
return NULL;
}
//获取当前设备列表中选择的设备信息指针
void *CNetSDKDemoDlg::GetCurDeviceInfo()
{
HTREEITEM node;
DWORD nData;
node = m_devicelist.GetSelectedItem();
if(!node)
{
//MessageBox(MSG_DEMODLG_CHECKSEL);
return NULL;
}
nData = m_devicelist.GetItemData(node);
if((nData >19) && (nData<30))
{
//MessageBox("NO CONNECT");
return NULL;
}
if(nData < 16) //通道选项,取得父项
{
node = m_devicelist.GetParentItem(node);
}
return (void *)m_devicelist.GetItemData(node); //父项记录的数据为设备的信息指针值
}
//根据句柄获取播放窗口序号,其中句柄可以是监视通道Id,播放Id,预览id等
int CNetSDKDemoDlg::GetHandleSplit(LONG lPlayHandle)
{
SplitInfoNode siNode;
memset(&siNode, 0, sizeof(siNode));
for(int i = 0; i < MAX_CHANNUM; i++)
{
if (!GetSplitInfo_Main(i, &siNode))
{
return -1;
}
if(siNode.Type != SPLIT_TYPE_NULL)
{
if(siNode.iHandle == (DWORD)lPlayHandle)
{
return i;
}
}
}
return -1;
}
//获取当前画面分割模式的指定画面的起始画面序号
int CNetSDKDemoDlg::GetCurSplitStart(int nScreen, int nSplit)
{
return -1;
/*
//设置到对应画面的单画面
int nScreenStart = 0;
if(nScreen >= nSplit * nSplit)
{
nScreenStart = m_curScreen/(nSplit * nSplit)*(nSplit * nSplit);
}
//当当前画面选择通道序号大于16时更改选择通道
//例如当前画面序号时10时,显示9画面,则显示7~16通道;
if((nScreenStart + nSplit * nSplit) >= CUR_MAXCHAN)
{
nScreenStart = CUR_MAXCHAN - nSplit * nSplit;
}
return nScreenStart;
*/
}
//检测当前画面状态并关闭当前状态
BOOL CNetSDKDemoDlg::CheckCurSplitAndClose()
{
ProcessCloseScreen(m_curScreen);
UpdateCurScreenInfo();
return TRUE;
}
//检测当前选择通道是否在某个轮循列表中
BOOL CNetSDKDemoDlg::IsCycling(DWORD deviceID, int channelNo)
{
SplitInfoNode siNode;
memset(&siNode, 0, sizeof(siNode));
for (int i = 0; i < MAX_CHANNUM; i++)
{
BOOL ret = GetSplitInfo_Main(i, &siNode);
if (!ret)
{
MessageBox("error while getting split information");
return TRUE;
}
if (siNode.Type == SPLIT_TYPE_CYCLEMONITOR)
{
POSITION pos = ((SplitCycleParam *)siNode.Param)->pChannelList->GetHeadPosition();
for (int j = 0; j < ((SplitCycleParam *)siNode.Param)->pChannelList->GetCount(); j++)
{
CycleChannelInfo *tempnode;
tempnode = (CycleChannelInfo *)((SplitCycleParam *)siNode.Param)->pChannelList->GetNext(pos);
if ((tempnode->dwDeviceID == deviceID) && (tempnode->iChannel == channelNo))
{
return TRUE;
}
}
}
}
return FALSE;
}
void CNetSDKDemoDlg::DeleteCycleParam(int nScreen)
{
SplitInfoNode siNode;
memset(&siNode, 0, sizeof(siNode));
BOOL ret = GetSplitInfo_Main(nScreen, &siNode);
if (!ret)
{
MessageBox("error while getting split info");
return;
}
int count;
count = ((SplitCycleParam *)siNode.Param)->pChannelList->GetCount();
for (int i = 0; i < count; i++)
{
delete (CycleChannelInfo *)((SplitCycleParam *)siNode.Param)->pChannelList->GetTail();
((SplitCycleParam *)siNode.Param)->pChannelList->RemoveTail();
}
delete ((SplitCycleParam *)siNode.Param)->pChannelList;
delete (SplitCycleParam *)siNode.Param;
siNode.Type = SPLIT_TYPE_NULL;
siNode.Param = NULL;
ret = SetSplitInfo_Main(nScreen, &siNode);
if (!ret)
{
MessageBox("error while setting split info");
}
CPlayWnd *plWnd = (CPlayWnd *)m_screenPannel.GetPage(nScreen);
if (plWnd)
{
plWnd->PostMessage(VIDEO_REPAINT);
}
}
//关闭画面的显示状态
BOOL CNetSDKDemoDlg::ProcessCloseScreen(int scrNo, BOOL bDis)
{
BOOL ret = TRUE;
// EnterCriticalSection(&g_cs);
// CCSLock lck(g_cs);
SplitInfoNode siNode;
memset(&siNode, 0, sizeof(siNode));
ret = GetSplitInfo_Main(scrNo, &siNode);
if (!ret)
{
MessageBox("error while getting split info");
return FALSE;
}
switch(siNode.Type)
{
case SPLIT_TYPE_MONITOR:
{
// ret = CLIENT_StopRealPlay(siNode.iHandle);
ret = CLIENT_StopRealPlayEx(siNode.iHandle);
if (!ret)
{
LastError();
if (!bDis)
{
MessageBox(MSG_CYCLE_STOPMONITORERROR);
}
}
delete (SplitMonitorParam *)siNode.Param;
siNode.Param = NULL;
siNode.Type = SPLIT_TYPE_NULL;
ret = SetSplitInfo_Main(scrNo, &siNode);
if (!ret)
{
MessageBox("error while getting split info");
}
CPlayWnd *plWnd = (CPlayWnd *)m_screenPannel.GetPage(scrNo);
if (plWnd)
{
plWnd->PostMessage(VIDEO_REPAINT);
}
break;
}
case SPLIT_TYPE_MULTIPLAY:
{
// ret = CLIENT_StopMultiPlay(siNode.iHandle);
ret = CLIENT_StopRealPlayEx(siNode.iHandle);
if (!ret)
{
LastError();
if (!bDis)
{
MessageBox(MSG_CYCLE_STOPMULTIPLAYERROR);
}
}
siNode.Param = NULL;
siNode.Type = SPLIT_TYPE_NULL;
ret = SetSplitInfo_Main(scrNo, &siNode);
if (!ret)
{
MessageBox("error while getting split info");
}
m_advanceBtnPannel.EnableTalk(TRUE);
CPlayWnd *plWnd = (CPlayWnd *)m_screenPannel.GetPage(scrNo);
if (plWnd)
{
plWnd->PostMessage(VIDEO_REPAINT);
}
break;
}
case SPLIT_TYPE_NETPLAY:
case SPLIT_TYPE_PBBYTIME:
{
int nRet = PlayStop(scrNo, bDis);
if (nRet < 0)
{
ret = FALSE;
}
else
{
ret = TRUE;
}
break;
}
case SPLIT_TYPE_CYCLEMONITOR:
{
//仅用于“关闭”指令,删除与断开设备有另外的代码。
KillTimer(scrNo);
// EnterCriticalSection(&g_csCycle);
ret = CLIENT_StopRealPlay(siNode.iHandle);
if (!ret)
{
LastError();
MessageBox(MSG_CYCLE_STOPCYCLEERROR);
}
if (siNode.Param)
{
DeleteCycleParam(scrNo);
}
// LeaveCriticalSection(&g_csCycle);
break;
}
default:
break;
}
// LeaveCriticalSection(&g_cs);
return ret;
}
int UpdateDeviceListCallback(const DeviceNode& node, DWORD dwUser)
{
CNetSDKDemoDlg* pThis = (CNetSDKDemoDlg*)dwUser;
if (!pThis)
{
return 1;
}
return pThis->UpdateDeviceListCallback_Imp(node);
}
//在设备列表树中添加设备信息
int CNetSDKDemoDlg::UpdateDeviceListCallback_Imp(const DeviceNode& node)
{
m_theImageList.Create(IDB_TREE_BITMAP,16,1,RGB(0,255,0));//创建图像列表
m_devicelist.SetImageList(&m_theImageList,TVSIL_NORMAL);//树形控件载入位图
CString strDev, strCh;
HTREEITEM hnode, hnode1;
//CDevMgr::DeviceNode* nDev = &node;
//sun modify
char cTemp[200];
CString dvrName;
DWORD dwReturned;
NET_DEV_DEVICECFG m_deviceCFG;
memset(&m_deviceCFG, 0, sizeof(NET_DEV_DEVICECFG));
CLIENT_GetDevConfig(node.LoginID, DEV_GET_DEVICECFG, 0,&m_deviceCFG, sizeof(NET_DEV_DEVICECFG), &dwReturned);
ZeroMemory(cTemp, 200);
memcpy(cTemp, m_deviceCFG.sDVRName, NAME_LEN);
dvrName.Format("%s", cTemp);
//sun modify
strDev.Format("%s(%s)",dvrName,node.IP);
hnode = m_devicelist.InsertItem(strDev,0,1,TVI_ROOT);
//设备项直接将设备信息指针作为列表Id
m_devicelist.SetItemData(hnode,(DWORD)&node);
//sun modify
char buf[512];
int chancount;
int bRet = CLIENT_QueryChannelName(node.LoginID, (char *)buf, 512, &chancount);
if (bRet)
{
//CString s;
//s.Format("%d",node.Info.byChanNum);
//AfxMessageBox(s);
NET_DEV_PICCFG m_piccfg[MAX_CHANNUM];
for (int i = 0; i < node.Info.byChanNum; i++)
{
strcpy((char *)m_piccfg[i].sChanName, buf+ 32*i);
}
for(int j = 0; j < node.Info.byChanNum; j++)
{
strCh.Format("%s",m_piccfg[j].sChanName);
hnode1 = m_devicelist.InsertItem(strCh,0,2,hnode);
//通道项将通道序号作为列表ID
m_devicelist.SetItemData(hnode1,j);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -