从0开始一个mfc程序(一)

1、首先打开vs2015,新建项目
在这里插入图片描述
2、下一步
在这里插入图片描述
3、下一步
在这里插入图片描述
4、下一步
在这里插入图片描述
5、下一步finish
在这里插入图片描述
6、最后出现如下
在这里插入图片描述
7、一般我们test003.h,我们会添加一个ExitInstance(),函数来做一些初始化,反初始化的事情。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

然后就可以添加好了。
在这里插入图片描述
一般来说,我们在这里做一些初始化动作。
除此之外对该类不做任何变动。
我们做变动,写业务,主要在xxxCDialog的这个类中,在这里我们需要添加我们需要的相关属性值以及行为方法。这个可以看海康官网的一个参考代码
RealPlayDlg.h

// RealPlayDlg.h : header file
//

#if !defined(AFX_REALPLAYDLG_H__4C5D1B67_AC1D_499C_A88A_C0B663F739D0__INCLUDED_)
#define AFX_REALPLAYDLG_H__4C5D1B67_AC1D_499C_A88A_C0B663F739D0__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "GeneralDef.h"
#include "PTZButton.h"
/
// CRealPlayDlg dialog

class CRealPlayDlg : public CDialog
{
// Construction
public:
	CRealPlayDlg(CWnd* pParent = NULL);	// standard constructor

public:
	BOOL m_bTrackRun;
	BOOL m_bIsOnCruise;
	void InitDecoderReferCtrl();
	void GetDecoderCfg();
	void StopRecord();
	void StartRecord();
	int GetPTZSpeed();
	LONG GetPlayHandle();
	int GetCurChanIndex();
	void DbPlayChannel(int ChanIndex);
	void CreateDeviceTree();
	void StartPlay(int iChanIndex);
	void StopPlay();
	BOOL DoLogin();
	void DoGetDeviceResoureCfg();
	BOOL m_bIsLogin;
//	LONG m_lLoginID;
	BOOL m_bIsPlaying;
	BOOL m_bIsRecording;
	HTREEITEM m_hDevItem;
	LOCAL_DEVICE_INFO m_struDeviceInfo;
	int m_iCurChanIndex;               //当前通道在数组中索引
	LONG m_lPlayHandle;



	//下列按钮的顺序一定要和CPTZButton中的处理一致
	CPTZButton m_btnPtzUp;
	CPTZButton m_btnPtzDown;
	CPTZButton m_btnPtzLeft;
	CPTZButton m_btnPtzRight;
	CPTZButton m_btnZoomIn;//调焦拉近,放大
	CPTZButton m_btnZoomOut;//调焦拉远,缩小
	CPTZButton m_btnFocusNear;//聚焦拉近,放大
	CPTZButton m_btnFocusFar;//聚焦拉远,缩小
	CPTZButton m_btnIrisOpen;//光圈放大
	CPTZButton m_btnIrisClose;//光圈缩小
	CPTZButton m_btnPtzUpleft; //左上
	CPTZButton m_btnPtzUpright; //右上
	CPTZButton m_btnPtzDownleft; //左下
	CPTZButton m_btnPtzDownright; //右下
// 	CPTZButton m_btnPtzAuto;      //自动
// 	CPTZButton m_btnLightPwron;   //灯光
// 	CPTZButton m_btnWiperPwron;   //雨刷
// 	CPTZButton m_btnFanPwron;     //风扇
// 	CPTZButton m_btnHeaterPwron;  //加热
// 	CPTZButton m_btnAuxPwron;     //辅助

	BOOL m_bAutoOn;       //自动开
    BOOL m_bLightOn;      //灯光开
    BOOL m_bWiperOn;      //雨刷开
	BOOL m_bFanOn;        //风扇开
	BOOL m_bHeaterOn;     //加热开
	BOOL m_bAuxOn1;        //辅助设备1开
	BOOL m_bAuxOn2;        //辅助设备2开
// Dialog Data
	//{{AFX_DATA(CRealPlayDlg)
	enum { IDD = IDD_REALPLAY_DIALOG };
	CComboBox	m_coJpgQuality;
	CComboBox	m_coJpgSize;
	CComboBox	m_coPicType;
	CComboBox	m_comboSeq;
	CComboBox	m_comboPreset;
	CComboBox	m_comboPTZSpeed;
	CTreeCtrl	m_ctrlTreeChan;
	CIPAddressCtrl	m_ctrlDevIp;
	UINT	m_nDevPort;
	CString	m_csUser;
	CString	m_csPWD;
	//}}AFX_DATA

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

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CRealPlayDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnButtonLogin();
	afx_msg void OnDblclkTreeChan(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnSelchangedTreeChan(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnButtonRecord();
	afx_msg void OnButtonCapture();
	afx_msg void OnButtonPlay();
	afx_msg void OnSelchangeComboPreset();
	afx_msg void OnButtonPresetGoto();
	afx_msg void OnButtonPresetSet();
	afx_msg void OnButtonPresetDel();
	afx_msg void OnButtonSeqGoto();
	afx_msg void OnButtonSeqSet();
	afx_msg void OnButtonTrackRun();
	afx_msg void OnButtonTrackStart();
	afx_msg void OnButtonTrackStop();
	afx_msg void OnBtnPtzAuto();
	afx_msg void OnBtnAuxPwron();
	afx_msg void OnBtnFanPwron();
	afx_msg void OnBtnHeaterPwron();
	afx_msg void OnBtnLightPwron();
	afx_msg void OnBtnWiperPwron();
	afx_msg void OnBtnAuxPwron2();
	afx_msg void OnSelchangeComboPicType();
	afx_msg void OnClose();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_REALPLAYDLG_H__4C5D1B67_AC1D_499C_A88A_C0B663F739D0__INCLUDED_)

对于上述简要说明virtual void DoDataExchange(CDataExchange* pDX);,这个函数主要从控件获取相关值,

void CRealPlayDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRealPlayDlg)
	DDX_Control(pDX, IDC_COMBO_JPG_QUALITY, m_coJpgQuality);
	DDX_Control(pDX, IDC_COMBO_JPG_SIZE, m_coJpgSize);
	DDX_Control(pDX, IDC_COMBO_PIC_TYPE, m_coPicType);
	DDX_Control(pDX, IDC_COMBO_SEQ, m_comboSeq);
	DDX_Control(pDX, IDC_COMBO_PRESET, m_comboPreset);
	DDX_Control(pDX, IDC_COMBO_PTZ_SPEED, m_comboPTZSpeed);
	DDX_Control(pDX, IDC_TREE_CHAN, m_ctrlTreeChan);
	DDX_Control(pDX, IDC_IPADDRESS_DEV, m_ctrlDevIp);
	DDX_Text(pDX, IDC_EDIT_PORT, m_nDevPort);
	DDX_Text(pDX, IDC_EDIT_USER, m_csUser);
	DDX_Text(pDX, IDC_EDIT_PWD, m_csPWD);
	//}}AFX_DATA_MAP
}

这些都是通过添加控件后自动生成,具体步骤如下:
在这里插入图片描述
拖入两个图示控件,右键属性
在这里插入图片描述
就会出现右下角的属性框,

修改static为name,id为IDC_STATIC_NAME,一般我们都是后面增加一个下划线和相应的名称,最后见名字晓意思。同时另外一个也改名字。在这里插入图片描述
右键示例编辑框,添加变量m_name
在这里插入图片描述
分别设置变量类型以及值类型,确定之后就出现了,在这里强调下value和ctrl的区别

control型变量是这个控件所属类的一个实例(对象)可以通过这个变量来对该控件进行一些设置。而value只是用来传递数据,不能对控件进行其它的操作。
control型变量可以获得控件的实例,通过这个变量,你可以操纵控件
value型变量仅仅可以获得该控件的public型变量
如果你添加了一个m_CtrlEdit的control型变量你可以调用控件支持的所有函数,如:
m_CtrlEdit.GetStyle(…)
获得控件的输入内容或者说文本内容:
CString str_name;
m_CtrlEdit.GetWindowText(str_name);
MessageBox(str_name,“提示”,0);
而value型变量一般用于向控件传递数据,如:变量为CString 类型的 m_Str m_Str=“hustwjz”;
UpdateData(FALSE); //可以向控件传递数据
UpdateData(TRUE); //可以从控件获得数据
获得输入数据后可以进行相应操作.以下是写文件用到的,把输入的内容写入文件
UpdateData(TRUE);
student.age=m_age;
strcpy(student.name,m_char);
CString fPath;
fPath=GetAppPath();
IniFileHandle->m_FileName.Format(_T("%s"),fPath+_T(“student”));
IniFileHandle->OpenFile(1);
IniFileHandle->Serialize(student);
IniFileHandle->CloseFile();
可以使用成员变量来代替某个控件,当控件发生变化时,该成员变量的值也发生变化;ClassWizard增加成员变量的时候,选择value类型可以创建一个包含由用户来输入控件文本和控件状态的成员变量;选择Control类型,我们可以对这个控件直接进行访问;
control就是控件,可以得到长度 高度 是不是可用 是不是可见
value是个字符串,跟控件绑定在一起,可以通过UpdateData(TRUE/FALSE)相互更新;
Value 就是一个变量
control 就是一个控件。
主要的区别也就是 变量 和 控件之间的区别,虽然他们实质上都是一样的。
可是选择 Value ,MFC 会把控件的内容对应到一个变量上。除非你用其他API取得这个
控件进行操作,否则,就是一个变量而已。主要的用途是 UpdateData。进行数据读些。
而作为控件,把就是把这个东西直接对应到了一个控件对象上去,比如 CEdit 对象。
你可以直接用这个对象来进行操作。熟悉了之后,就是一个怎么用怎么方便的问题。从其
实质来说,我认为没有什么区别,都是控件。不表示,你选了value ,其控件就不存在,
只是说选择value ,MFC的wizard 做了跟多事情,让你面对这个控件可以把它看作一个值而已。

在这里插入图片描述
在这里插入图片描述
自己就自动添加上去了,这个就是我们在运行时候获取的值,当然这个值还可以初始化,在这里插入图片描述
在这里初始化以后,后期运行首先显示的就是这个值。在用到这个值的时候通过函数:
UpdateData(FALSE):将程序中改变的变量的值更新至控件中去;
UpdateData(TRUE):将控件中输入的值更新到变量中。

然后添加一个button,顺手改名字和ID
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
自动出现上述代码,其中afx_msg是全局变量的一个宏定义。
在这里插入图片描述
然后在上述地方添加代码,就可以添加刚才的UpdateData(TRUE):了
在这里插入图片描述
从这里我们就可以看出,上述一个是获取值,另外一个是操作行为,都是自动添加的。
然后同上添加一个Combo Box
在这里插入图片描述
在这里插入图片描述
注意上述value 要改为control,然后就可以看到如下:在这里插入图片描述
在这里插入图片描述
两个,一个是value一个是control,从这里就可以看出这两个之间的区别,一个是cstring值,另外一个是控件。一个是DDX_Text 另外一个是DDX_Control
在这里插入图片描述
对控件进行设置,添加下拉菜单内容:
在这里插入图片描述
这里可以快速获取到下拉菜单的值:
在这里插入图片描述
关于该控件详细的资料可以参考该链接:

https://www.cnblogs.com/lpxblog/p/4606981.html

关于这两个控件的用法在此,下一篇说一下按钮按下抬起的控件制作。
下面是主参考程序

RealPlayDlg.cpp

/*******************************************************
Copyright 2008-2011 Digital Technology Co., Ltd. 
文  件:	RealPlayDlg.cpp
开发单位:	杭州
编  写:	shizhiping
日  期:	2009.5
描  述:	实时预览对话框
修  改:	
********************************************************/

#include "stdafx.h"
#include "RealPlay.h"
#include "RealPlayDlg.h"
#include "DlgPTZCruise.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CAboutDlg dialog used for App About

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)
	//}}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)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CRealPlayDlg dialog

CRealPlayDlg::CRealPlayDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRealPlayDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRealPlayDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_nDevPort = 8000;
	m_csUser = _T("admin");
	m_csPWD = _T("12345");
	m_bIsLogin = FALSE;
//	m_lLoginID = -1;;
	m_bIsPlaying = FALSE;
	m_bIsRecording = FALSE;
	m_iCurChanIndex = -1;
	m_lPlayHandle = -1;
	m_bIsOnCruise = FALSE;
    m_bTrackRun = FALSE;
	m_bAutoOn = FALSE;
	m_bLightOn = FALSE;
    m_bWiperOn= FALSE;
	m_bFanOn= FALSE;
	m_bHeaterOn= FALSE;
	m_bAuxOn1= FALSE;
	m_bAuxOn2= FALSE;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CRealPlayDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRealPlayDlg)
	DDX_Control(pDX, IDC_COMBO_JPG_QUALITY, m_coJpgQuality);
	DDX_Control(pDX, IDC_COMBO_JPG_SIZE, m_coJpgSize);
	DDX_Control(pDX, IDC_COMBO_PIC_TYPE, m_coPicType);
	DDX_Control(pDX, IDC_COMBO_SEQ, m_comboSeq);
	DDX_Control(pDX, IDC_COMBO_PRESET, m_comboPreset);
	DDX_Control(pDX, IDC_COMBO_PTZ_SPEED, m_comboPTZSpeed);
	DDX_Control(pDX, IDC_TREE_CHAN, m_ctrlTreeChan);
	DDX_Control(pDX, IDC_IPADDRESS_DEV, m_ctrlDevIp);
	DDX_Text(pDX, IDC_EDIT_PORT, m_nDevPort);
	DDX_Text(pDX, IDC_EDIT_USER, m_csUser);
	DDX_Text(pDX, IDC_EDIT_PWD, m_csPWD);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRealPlayDlg, CDialog)
	//{{AFX_MSG_MAP(CRealPlayDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_LOGIN, OnButtonLogin)
	ON_NOTIFY(NM_DBLCLK, IDC_TREE_CHAN, OnDblclkTreeChan)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_CHAN, OnSelchangedTreeChan)
	ON_BN_CLICKED(IDC_BUTTON_RECORD, OnButtonRecord)
	ON_BN_CLICKED(IDC_BUTTON_CAPTURE, OnButtonCapture)
	ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
	ON_CBN_SELCHANGE(IDC_COMBO_PRESET, OnSelchangeComboPreset)
	ON_BN_CLICKED(IDC_BUTTON_PRESET_GOTO, OnButtonPresetGoto)
	ON_BN_CLICKED(IDC_BUTTON_PRESET_SET, OnButtonPresetSet)
	ON_BN_CLICKED(IDC_BUTTON_PRESET_DEL, OnButtonPresetDel)
	ON_BN_CLICKED(IDC_BUTTON_SEQ_GOTO, OnButtonSeqGoto)
	ON_BN_CLICKED(IDC_BUTTON_SEQ_SET, OnButtonSeqSet)
	ON_BN_CLICKED(IDC_BUTTON_TRACK_RUN, OnButtonTrackRun)
	ON_BN_CLICKED(IDC_BUTTON_TRACK_START, OnButtonTrackStart)
	ON_BN_CLICKED(IDC_BUTTON_TRACK_STOP, OnButtonTrackStop)
	ON_BN_CLICKED(IDC_BTN_PTZ_AUTO, OnBtnPtzAuto)
	ON_BN_CLICKED(IDC_BTN_AUX_PWRON, OnBtnAuxPwron)
	ON_BN_CLICKED(IDC_BTN_FAN_PWRON, OnBtnFanPwron)
	ON_BN_CLICKED(IDC_BTN_HEATER_PWRON, OnBtnHeaterPwron)
	ON_BN_CLICKED(IDC_BTN_LIGHT_PWRON, OnBtnLightPwron)
	ON_BN_CLICKED(IDC_BTN_WIPER_PWRON, OnBtnWiperPwron)
	ON_BN_CLICKED(IDC_BTN_AUX_PWRON2, OnBtnAuxPwron2)
	ON_CBN_SELCHANGE(IDC_COMBO_PIC_TYPE, OnSelchangeComboPicType)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CRealPlayDlg message handlers

BOOL CRealPlayDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	// TODO: Add extra initialization here
	//默认IP
	m_ctrlDevIp.SetAddress(172,7,96,7);

	//云台速度
	m_comboPTZSpeed.SetCurSel(5);

    //云台按钮
	m_btnPtzUp.SubclassDlgItem(IDC_BTN_PTZ_UP,this);
	m_btnPtzDown.SubclassDlgItem(IDC_BTN_PTZ_DOWN,this);
	m_btnPtzLeft.SubclassDlgItem(IDC_BTN_PTZ_LEFT,this);
	m_btnPtzRight.SubclassDlgItem(IDC_BTN_PTZ_RIGHT,this);	
	m_btnZoomOut.SubclassDlgItem(IDC_BTN_ZOOM_OUT,this);
	m_btnZoomIn.SubclassDlgItem(IDC_BTN_ZOOM_IN,this);
	m_btnFocusNear.SubclassDlgItem(IDC_BTN_FOCUS_NEAR,this);
	m_btnFocusFar.SubclassDlgItem(IDC_BTN_FOCUS_FAR,this);
	m_btnIrisOpen.SubclassDlgItem(IDC_BTN_IRIS_OPEN,this);
	m_btnIrisClose.SubclassDlgItem(IDC_BTN_IRIS_CLOSE,this);
    m_btnPtzUpleft.SubclassDlgItem(IDC_BTN_PTZ_UPLEFT,this);
    m_btnPtzUpright.SubclassDlgItem(IDC_BTN_PTZ_UPRIGHT,this);
	m_btnPtzDownleft.SubclassDlgItem(IDC_BTN_PTZ_DOWNLEFT,this);
    m_btnPtzDownright.SubclassDlgItem(IDC_BTN_PTZ_DOWNRIGHT,this);

	//抓图combo
	m_coPicType.SetCurSel(0);
	m_coJpgSize.SetCurSel(0);
	m_coJpgQuality.SetCurSel(0);
	GetDlgItem(IDC_STATIC_JPGPARA)->EnableWindow(FALSE);
	m_coJpgSize.EnableWindow(FALSE);
	m_coJpgQuality.EnableWindow(FALSE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CRealPlayDlg::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 CRealPlayDlg::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 CRealPlayDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/*************************************************
函数名:    	OnButtonLogin
函数描述:	注册/注销 按钮
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonLogin() 
{
	
	if(!m_bIsLogin)    //login
	{
		if(!DoLogin())
			return;
		DoGetDeviceResoureCfg();  //获取设备资源信息	
		CreateDeviceTree();        //创建通道树
		GetDecoderCfg();                           //获取云台解码器信息
		InitDecoderReferCtrl();         //初始化解码器相关控件      
		GetDlgItem(IDC_BUTTON_LOGIN)->SetWindowText("Logout");
		m_bIsLogin = TRUE;
		
	}
	else      //logout
	{
		
		
		if(m_bIsPlaying|| m_bIsRecording)
		{
			MessageBox("Stop Play or record first!");
			return;
		}
        NET_DVR_Logout_V30(m_struDeviceInfo.lLoginID); 
		GetDlgItem(IDC_BUTTON_LOGIN)->SetWindowText("Login");
		m_ctrlTreeChan.DeleteAllItems();
		m_struDeviceInfo.lLoginID = -1;
		m_bIsLogin = FALSE;
	}
}

/*************************************************
函数名:    	DoLogin
函数描述:	向设备注册
输入参数:   
输出参数:   			
返回值:		
**************************************************/
BOOL CRealPlayDlg::DoLogin()
{
	UpdateData(TRUE);
	CString DeviceIp;
	BYTE nField0,nField1,nField2,nField3; 
	m_ctrlDevIp.GetAddress(nField0,nField1,nField2,nField3);
	DeviceIp.Format("%d.%d.%d.%d",nField0,nField1,nField2,nField3);
	
	NET_DVR_DEVICEINFO_V30 DeviceInfoTmp;
	memset(&DeviceInfoTmp,0,sizeof(NET_DVR_DEVICEINFO_V30));
	
	LONG lLoginID = NET_DVR_Login_V30(DeviceIp.GetBuffer(DeviceIp.GetLength()),m_nDevPort, \
		m_csUser.GetBuffer(m_csUser.GetLength()),m_csPWD.GetBuffer(m_csPWD.GetLength()),&DeviceInfoTmp);
	if(lLoginID == -1)
	{
		MessageBox("Login to Device failed!\n");
		return FALSE;
	}
    m_struDeviceInfo.lLoginID = lLoginID;
	m_struDeviceInfo.iDeviceChanNum = DeviceInfoTmp.byChanNum;
    m_struDeviceInfo.iIPChanNum = DeviceInfoTmp.byIPChanNum;
    m_struDeviceInfo.iStartChan  = DeviceInfoTmp.byStartChan;
    m_struDeviceInfo.iIPStartChan  = DeviceInfoTmp.byStartDChan;
	return TRUE;
}

/*************************************************
函数名:    	DoGetDeviceResoureCfg
函数描述:	获取设备的通道资源
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::DoGetDeviceResoureCfg()
{
	NET_DVR_IPPARACFG_V40 IpAccessCfg;
	memset(&IpAccessCfg,0,sizeof(IpAccessCfg));	
	DWORD  dwReturned;

	m_struDeviceInfo.bIPRet = NET_DVR_GetDVRConfig(m_struDeviceInfo.lLoginID,NET_DVR_GET_IPPARACFG_V40,0,&IpAccessCfg,sizeof(NET_DVR_IPPARACFG_V40),&dwReturned);

	int i;
    if(!m_struDeviceInfo.bIPRet)   //不支持ip接入,9000以下设备不支持禁用模拟通道
	{
		for(i=0; i<MAX_ANALOG_CHANNUM; i++)
		{
			if (i < m_struDeviceInfo.iDeviceChanNum)
			{
				sprintf(m_struDeviceInfo.struChanInfo[i].chChanName,"camera%d",i+m_struDeviceInfo.iStartChan);
				m_struDeviceInfo.struChanInfo[i].iChanIndex=i+m_struDeviceInfo.iStartChan;  //通道号
				m_struDeviceInfo.struChanInfo[i].bEnable = TRUE;
				
			}
			else
			{
				m_struDeviceInfo.struChanInfo[i].iChanIndex = -1;
				m_struDeviceInfo.struChanInfo[i].bEnable = FALSE;
				sprintf(m_struDeviceInfo.struChanInfo[i].chChanName, "");	
			}
		}
	}
	else        //支持IP接入,9000设备
	{
		for(i=0; i<MAX_ANALOG_CHANNUM; i++)  //模拟通道
		{
			if (i < m_struDeviceInfo.iDeviceChanNum)
			{
				sprintf(m_struDeviceInfo.struChanInfo[i].chChanName,"camera%d",i+m_struDeviceInfo.iStartChan);
				m_struDeviceInfo.struChanInfo[i].iChanIndex=i+m_struDeviceInfo.iStartChan;
				if(IpAccessCfg.byAnalogChanEnable[i])
				{
					m_struDeviceInfo.struChanInfo[i].bEnable = TRUE;
				}
				else
				{
					m_struDeviceInfo.struChanInfo[i].bEnable = FALSE;
				}
				
			}
			else//clear the state of other channel
			{
				m_struDeviceInfo.struChanInfo[i].iChanIndex = -1;
				m_struDeviceInfo.struChanInfo[i].bEnable = FALSE;
				sprintf(m_struDeviceInfo.struChanInfo[i].chChanName, "");	
			}		
		}

		//数字通道
		for(i=0; i<MAX_IP_CHANNEL; i++)
		{
			if(IpAccessCfg.struStreamMode[i].uGetStream.struChanInfo.byEnable)  //ip通道在线
			{
				m_struDeviceInfo.struChanInfo[i+MAX_ANALOG_CHANNUM].bEnable = TRUE;
                m_struDeviceInfo.struChanInfo[i+MAX_ANALOG_CHANNUM].iChanIndex = i+IpAccessCfg.dwStartDChan;
				sprintf(m_struDeviceInfo.struChanInfo[i+MAX_ANALOG_CHANNUM].chChanName,"IP Camera %d",i+1);

			}
			else
			{
               m_struDeviceInfo.struChanInfo[i+MAX_ANALOG_CHANNUM].bEnable = FALSE;
			    m_struDeviceInfo.struChanInfo[i+MAX_ANALOG_CHANNUM].iChanIndex = -1;
			}
		}
		
		
	}

}

/*************************************************
函数名:    	CreateDeviceTree
函数描述:	创建通道树
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::CreateDeviceTree()
{
	m_hDevItem = m_ctrlTreeChan.InsertItem("Dev");
	m_ctrlTreeChan.SetItemData(m_hDevItem,DEVICETYPE*1000);
    for(int i=0; i<MAX_CHANNUM_V30; i++)
	{
		if(m_struDeviceInfo.struChanInfo[i].bEnable)  //通道有效,插入通道树
		{
             HTREEITEM ChanItem = m_ctrlTreeChan.InsertItem(m_struDeviceInfo.struChanInfo[i].chChanName,m_hDevItem);
			 m_ctrlTreeChan.SetItemData(ChanItem,CHANNELTYPE*1000+i);   //Data对应通道在数组中的索引
		}
	}
	m_ctrlTreeChan.Expand(m_hDevItem,TVE_EXPAND);
}

/*************************************************
函数名:    	OnDblclkTreeChan
函数描述:	双击通道数,播放选中通道
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnDblclkTreeChan(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HTREEITEM hSelected = m_ctrlTreeChan.GetSelectedItem();
	//未选中
	if(NULL == hSelected)
		return;
	DWORD itemData = m_ctrlTreeChan.GetItemData(hSelected);
	HTREEITEM hParent = NULL;
	int itype = itemData/1000;    //
	int iIndex = itemData%1000;

	switch(itype)
	{
	case DEVICETYPE:
		m_iCurChanIndex = -1;
		break;
	case CHANNELTYPE:
		m_iCurChanIndex = iIndex;
		TRACE("select chan: %d\n",iIndex);
        DbPlayChannel(iIndex);
		OnSelchangeComboPreset();
		break;
	default:
		break;

	}
	*pResult = 0;
}

/*************************************************
函数名:    	DbPlayChannel
函数描述:	双击播放
输入参数:   ChanIndex-通道号
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::DbPlayChannel(int ChanIndex)
{
 
	if(!m_bIsPlaying)  //Play
	{
		StartPlay(ChanIndex);
	}
	else                //Stop,play
	{
        StopPlay();
		StartPlay(ChanIndex);

	}
}

/*************************************************
函数名:    	StartPlay
函数描述:	开始一路播放
输入参数:   ChanIndex-通道号
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::StartPlay(int iChanIndex)
{
	NET_DVR_CLIENTINFO ClientInfo;
	ClientInfo.hPlayWnd     = GetDlgItem(IDC_STATIC_PLAY)->m_hWnd;
	ClientInfo.lChannel     = m_iCurChanIndex+1;
	ClientInfo.lLinkMode    = 0;
    ClientInfo.sMultiCastIP = NULL;
	TRACE("Channel number:%d\n",ClientInfo.lChannel);
	m_lPlayHandle = NET_DVR_RealPlay_V30(m_struDeviceInfo.lLoginID,&ClientInfo,NULL,NULL,TRUE);
	if(-1 == m_lPlayHandle)
	{
		DWORD err=NET_DVR_GetLastError();
		CString m_csErr;
        m_csErr.Format("播放出错,错误代码%d",err);
		MessageBox(m_csErr);
	}

	m_bIsPlaying = TRUE;
	GetDlgItem(IDC_BUTTON_PLAY)->SetWindowText("停止播放");

}

/*************************************************
函数名:    	StopPlay
函数描述:	停止播放
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::StopPlay()
{
	if(m_lPlayHandle != -1)
	{
		if(m_bIsRecording)  //正在录像,先停止
		{
			StopRecord();
		}
		NET_DVR_StopRealPlay(m_lPlayHandle);
		m_lPlayHandle=-1;
		m_bIsPlaying = FALSE;
		GetDlgItem(IDC_STATIC_PLAY)->Invalidate();
	}
}

/*************************************************
函数名:    	OnSelchangedTreeChan
函数描述:	获取选中的通道号
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnSelchangedTreeChan(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	HTREEITEM hSelected = m_ctrlTreeChan.GetSelectedItem();
	//未选中
	if(NULL == hSelected)
		return;
	DWORD itemData = m_ctrlTreeChan.GetItemData(hSelected);
	HTREEITEM hParent = NULL;
	int itype = itemData/1000;    //
	int iIndex = itemData%1000;
	
	switch(itype)
	{
	case DEVICETYPE:
        m_iCurChanIndex = -1;
		break;
	case CHANNELTYPE:
		m_iCurChanIndex = iIndex;
		OnSelchangeComboPreset();
		TRACE("select chan index: %d\n",iIndex);
		break;
	default:
		break;
		
	}
	*pResult = 0;
}

/*************************************************
函数名:    	GetCurChanIndex
函数描述:	获取当前选中的通道号
输入参数:   
输出参数:   			
返回值:		当前选中的通道号
**************************************************/
int CRealPlayDlg::GetCurChanIndex()
{
    return m_iCurChanIndex;
}

/*************************************************
函数名:    	GetPlayHandle
函数描述:	获取播放句柄
输入参数:   
输出参数:   			
返回值:		播放句柄
**************************************************/
LONG CRealPlayDlg::GetPlayHandle()
{
    return m_lPlayHandle;
}

/*************************************************
函数名:    	GetPTZSpeed
函数描述:	获取云台速度
输入参数:   
输出参数:   			
返回值:		云台速度
**************************************************/
int CRealPlayDlg::GetPTZSpeed()
{
   return (m_comboPTZSpeed.GetCurSel());
}

/*************************************************
函数名:    	OnButtonRecord
函数描述:	开始/停止录像 按钮
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonRecord() 
{
	if(m_lPlayHandle == -1)
	{
        MessageBox("请先选择一个通道播放");
		return;
	}
	if(!m_bIsRecording)
	{
		StartRecord();
	}
	else
	{
        StopRecord();
	}
	
}

/*************************************************
函数名:    	StartRecord
函数描述:	开始录像
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::StartRecord()
{
	char RecName[256] = {0};
	
	CTime CurTime = CTime::GetCurrentTime();;
	sprintf(RecName,"%04d%02d%02d%02d%02d%02d_ch%02d.mp4",CurTime.GetYear(),CurTime.GetMonth(),CurTime.GetDay(), \
		CurTime.GetHour(),CurTime.GetMinute(),CurTime.GetSecond(),m_struDeviceInfo.struChanInfo[GetCurChanIndex()].iChanIndex);

	 if(!NET_DVR_SaveRealData(m_lPlayHandle,RecName))
	 {
		 MessageBox("启动录像失败");
		 return;
	 }
     m_bIsRecording = TRUE;
	 GetDlgItem(IDC_BUTTON_RECORD)->SetWindowText("停止录像");
}

/*************************************************
函数名:    	StopRecord
函数描述:	停止录像
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::StopRecord()
{
    if(!NET_DVR_StopSaveRealData(m_lPlayHandle))
	{
		MessageBox("停止录像失败");
		return;
	}
	m_bIsRecording = FALSE;
	 GetDlgItem(IDC_BUTTON_RECORD)->SetWindowText("录像");
}

/*************************************************
函数名:    	OnButtonCapture
函数描述:	抓图
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonCapture() 
{
	if(m_lPlayHandle == -1)
	{
        MessageBox("请先选择一个通道播放");
		return;
	}
	UpdateData(TRUE);

	char PicName[256] = {0};
	
	int iPicType = m_coPicType.GetCurSel();
	if(0 == iPicType)  //bmp
	{
		CTime CurTime = CTime::GetCurrentTime();;
		sprintf(PicName,"%04d%02d%02d%02d%02d%02d_ch%02d.bmp",CurTime.GetYear(),CurTime.GetMonth(),CurTime.GetDay(), \
			CurTime.GetHour(),CurTime.GetMinute(),CurTime.GetSecond(),m_struDeviceInfo.struChanInfo[GetCurChanIndex()].iChanIndex);
    
		if(NET_DVR_CapturePicture(m_lPlayHandle,PicName))
		{
			MessageBox("抓图成功!");
		}
	}
	else if(1 == iPicType)  //jgp
	{
		CTime CurTime = CTime::GetCurrentTime();;
		sprintf(PicName,"%04d%02d%02d%02d%02d%02d_ch%02d.jpg",CurTime.GetYear(),CurTime.GetMonth(),CurTime.GetDay(), \
			CurTime.GetHour(),CurTime.GetMinute(),CurTime.GetSecond(),m_struDeviceInfo.struChanInfo[GetCurChanIndex()].iChanIndex);
    
		//组建jpg结构
		NET_DVR_JPEGPARA JpgPara = {0};
        JpgPara.wPicSize = (WORD)m_coJpgSize.GetCurSel();
		JpgPara.wPicQuality = (WORD)m_coJpgQuality.GetCurSel();

		LONG iCurChan = m_struDeviceInfo.struChanInfo[GetCurChanIndex()].iChanIndex;

		if(NET_DVR_CaptureJPEGPicture(m_struDeviceInfo.lLoginID, iCurChan, &JpgPara, PicName))
		{
			MessageBox("抓图成功");
		}
	}
	
	return;	
}

/*************************************************
函数名:    	OnButtonPlay
函数描述:	播放选中通道
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonPlay() 
{
	if(m_iCurChanIndex == -1)
	{
		MessageBox("选择一个通道");
		return;
	}
	if(!m_bIsPlaying)
	{
         StartPlay(m_iCurChanIndex);
		 m_bIsPlaying = TRUE;
		 GetDlgItem(IDC_BUTTON_PLAY)->SetWindowText("停止播放");

	}
	else
	{
		StopPlay();
		m_bIsPlaying = FALSE;
		GetDlgItem(IDC_BUTTON_PLAY)->SetWindowText("播放");
	}
	
}


/*************************************************
函数名:    	GetDecoderCfg
函数描述:	获取云台解码器信息
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::GetDecoderCfg()
{
     NET_DVR_DECODERCFG_V30 DecoderCfg;
	 DWORD  dwReturned;
	 BOOL bRet;
		
      
	 //获取通道解码器信息
	 for(int i=0; i<MAX_CHANNUM_V30; i++)
	 {
		 if(m_struDeviceInfo.struChanInfo[i].bEnable)
		 {
			 memset(&DecoderCfg,0,sizeof(NET_DVR_DECODERCFG_V30));
			 bRet = NET_DVR_GetDVRConfig(m_struDeviceInfo.lLoginID,NET_DVR_GET_DECODERCFG_V30 , \
				 m_struDeviceInfo.struChanInfo[i].iChanIndex,&DecoderCfg,sizeof(NET_DVR_DECODERCFG_V30),&dwReturned);
			 if(!bRet)
			 {
				 TRACE("Get DecderCfg failed,Chan:%d\n",m_struDeviceInfo.struChanInfo[i].iChanIndex);
				 continue;
			 }

			 memcpy(&m_struDeviceInfo.struChanInfo[i].struDecodercfg,&DecoderCfg,sizeof(NET_DVR_DECODERCFG_V30));
		 }
		 
	 }

}

/*************************************************
函数名:    	InitDecoderReferCtrl
函数描述:	初始化云台控制相关控件
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::InitDecoderReferCtrl()
{
    int i;
	CString tmp;
	//设置预置点
	for(i=0; i<MAX_PRESET_V30; i++)
	{  
		tmp.Format("%d",i+1);     //i+1
		m_comboPreset.AddString(tmp);
	}
	m_comboPreset.SetCurSel(0);

	GetDlgItem(IDC_BUTTON_PRESET_GOTO)->EnableWindow(FALSE);
    //GetDlgItem(IDC_BUTTON_PRESET_SET)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_PRESET_DEL)->EnableWindow(FALSE);

	//巡航轨迹
    for(i=0; i<MAX_CRUISE_SEQ; i++)
	{
         tmp.Format("%d",i+1);     //i+1
		 m_comboSeq.AddString(tmp);
	}
	m_comboSeq.SetCurSel(0);


}



/*************************************************
函数名:    	OnSelchangeComboPreset
函数描述:	预置点combobox,改变按钮状态
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnSelchangeComboPreset() 
{
	int iIndex = m_comboPreset.GetCurSel();    
	
	if(m_struDeviceInfo.struChanInfo[m_iCurChanIndex].struDecodercfg.bySetPreset[iIndex])
	{
        GetDlgItem(IDC_BUTTON_PRESET_GOTO)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_PRESET_DEL)->EnableWindow(TRUE);
	}
	else
	{
        GetDlgItem(IDC_BUTTON_PRESET_GOTO)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON_PRESET_DEL)->EnableWindow(FALSE);
	}
}

/*************************************************
函数名:    	OnButtonPresetGoto
函数描述:	调用预置点
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonPresetGoto() 
{
	int iPreset = m_comboPreset.GetCurSel()+1;    //+1
	if(m_lPlayHandle >= 0)
	{
		if(!NET_DVR_PTZPreset(m_lPlayHandle,GOTO_PRESET,iPreset))
		{
			MessageBox("调用预置点失败");
			return;
		}
	}
	else
	{
		if(!NET_DVR_PTZPreset_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex, \
			                  GOTO_PRESET,iPreset))
		{
			MessageBox("调用预置点失败");
			return;
		}

	}
}

/*************************************************
函数名:    	OnButtonPresetSet
函数描述:	设置预置点
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonPresetSet() 
{
	int iPreset = m_comboPreset.GetCurSel()+1;    //+1
	if(m_lPlayHandle >= 0)
	{
		if(!NET_DVR_PTZPreset(m_lPlayHandle,SET_PRESET,iPreset))
		{
			MessageBox("设置预置点失败");
			return;
		}
	}
	else
	{
		if(!NET_DVR_PTZPreset_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex, \
			SET_PRESET,iPreset))
		{
			MessageBox("设置预置点失败");
			return;
		}
		
	}

	//添加到预置点信息
	m_struDeviceInfo.struChanInfo[m_iCurChanIndex].struDecodercfg.bySetPreset[iPreset-1] = TRUE;
	//更新按钮状态
    OnSelchangeComboPreset();
	
}


/*************************************************
函数名:    	OnButtonPresetDel
函数描述:	删除预置点
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonPresetDel() 
{
	int iPreset = m_comboPreset.GetCurSel()+1;    //+1
	if(m_lPlayHandle >= 0)
	{
		if(!NET_DVR_PTZPreset(m_lPlayHandle,CLE_PRESET,iPreset))
		{
			MessageBox("删除预置点失败");
			return;
		}
	}
	else
	{
		if(!NET_DVR_PTZPreset_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex, \
			CLE_PRESET,iPreset))
		{
			MessageBox("删除预置点失败");
			return;
		}
		
	}
	
	//添加到预置点信息
	m_struDeviceInfo.struChanInfo[m_iCurChanIndex].struDecodercfg.bySetPreset[iPreset-1] = FALSE;
	//更新按钮状态
    OnSelchangeComboPreset();
	
}




/*************************************************
函数名:    	OnButtonSeqGoto
函数描述:	调用/停止 巡航
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonSeqGoto() 
{
	int iSeq = m_comboSeq.GetCurSel()+1;    //+1
	if(!m_bIsOnCruise)
	{
		if(m_lPlayHandle >= 0)
		{
	    	if(!NET_DVR_PTZCruise(m_lPlayHandle,RUN_SEQ,iSeq,0,0))
			{
		    	MessageBox("调用巡航失败");
		    	return;
			}
		}
	    else
		{
	    	if(!NET_DVR_PTZCruise_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex, \
		                             	RUN_SEQ,iSeq,0,0))
			{
		    	MessageBox("调用巡航失败");
		    	return;
			}
		
		}
        m_bIsOnCruise = TRUE;
		GetDlgItem(IDC_BUTTON_SEQ_GOTO)->SetWindowText("停止");
	}
	else
	{
        if(m_lPlayHandle >= 0)
		{
			if(!NET_DVR_PTZCruise(m_lPlayHandle,STOP_SEQ,iSeq,0,0))
			{
				MessageBox("停止巡航失败");
				return;
			}
		}
		else
		{
			if(!NET_DVR_PTZCruise_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex, \
				STOP_SEQ,iSeq,0,0))
			{
				MessageBox("停止巡航失败");
				return;
			}
			
		}
		m_bIsOnCruise = FALSE;
		GetDlgItem(IDC_BUTTON_SEQ_GOTO)->SetWindowText("调用");
	}
	
}

/*************************************************
函数名:    	OnButtonSeqSet
函数描述:	设置巡航路径
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonSeqSet() 
{
	CDlgPTZCruise Dlg;
	Dlg.DoModal();
	
}


/*************************************************
函数名:    	OnButtonTrackRun
函数描述:	开始运行轨迹
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonTrackRun() 
{
	if(!m_bTrackRun)
	{
		if(m_lPlayHandle >= 0)
		{
			if(!NET_DVR_PTZTrack(m_lPlayHandle,RUN_CRUISE))
			{
				MessageBox("运行轨迹失败");
			}
		}
		else
		{
			if(!NET_DVR_PTZTrack(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex))
			{
				MessageBox("运行轨迹失败");
			}
		}
		m_bTrackRun = TRUE;
		GetDlgItem(IDC_BUTTON_TRACK_RUN)->SetWindowText("停止");    
	}
	else
	{
        //随便发送一个云台控制命令停止运行
        if(m_lPlayHandle >= 0)
		{
			if(!NET_DVR_PTZControl(m_lPlayHandle,TILT_UP,1))
			{
				MessageBox("停止轨迹失败");
			}
		}
		else
		{
			if(!NET_DVR_PTZControl_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex,TILT_UP,1))
			{
				MessageBox("停止轨迹失败");
			}
		}
		m_bTrackRun = FALSE;
		GetDlgItem(IDC_BUTTON_TRACK_RUN)->SetWindowText("运行");   
	}


	
}

/*************************************************
函数名:    	OnButtonTrackStart
函数描述:	开始记录轨迹
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonTrackStart() 
{
	
	if(m_lPlayHandle >= 0)
	{
		if(!NET_DVR_PTZTrack(m_lPlayHandle,STA_MEM_CRUISE))
		{
			MessageBox("开始记录轨迹失败");
			return;
		}

	}
	else
	{
       if(!NET_DVR_PTZTrack_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex,STA_MEM_CRUISE))
	   {
		   MessageBox("开始记录轨迹失败");
			return;
	   }
	}

	
}

/*************************************************
函数名:    	OnButtonTrackStop
函数描述:	停止记录轨迹
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnButtonTrackStop() 
{
	if(m_lPlayHandle >= 0)
	{
		if(!NET_DVR_PTZTrack(m_lPlayHandle,STO_MEM_CRUISE))
		{
			MessageBox("停止失败");
			return;
		}
		
	}
	else
	{
		if(!NET_DVR_PTZTrack_Other(m_struDeviceInfo.lLoginID,m_struDeviceInfo.struChanInfo[m_iCurChanIndex].iChanIndex,STO_MEM_CRUISE))
		{
			MessageBox("停止失败");
			return;
		}
	}
	
}

/*************************************************
函数名:    	OnBtnPtzAuto
函数描述:	云台开始/停止左右自动扫描
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnBtnPtzAuto() 
{
	int iSpeed = GetPTZSpeed();
	if(m_lPlayHandle >= 0)
	{
	if(!m_bAutoOn)
	{
       if(iSpeed >= 1)
	   {
		   NET_DVR_PTZControlWithSpeed(m_lPlayHandle,PAN_AUTO,0,iSpeed);
	   }
	   else
	   {
		    NET_DVR_PTZControl(m_lPlayHandle,PAN_AUTO,0);
	   }
        GetDlgItem(IDC_BTN_PTZ_AUTO)->SetWindowText("停止");
		m_bAutoOn = TRUE;
	}
	else
	{
		 if(iSpeed >= 1)
		 {
			 NET_DVR_PTZControlWithSpeed(m_lPlayHandle,PAN_AUTO,1,iSpeed);
		 }
		 else
		 {
             NET_DVR_PTZControl(m_lPlayHandle,PAN_AUTO,1);
		 }
		 GetDlgItem(IDC_BTN_PTZ_AUTO)->SetWindowText("自动");
		 m_bAutoOn = FALSE;
	}
	}
	
}

/*************************************************
函数名:    	OnBtnAuxPwron
函数描述:	开始/停止 辅助设备1
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnBtnAuxPwron() 
{
	if(m_lPlayHandle >= 0)
	{
		if(!m_bAuxOn1)
		{
			NET_DVR_PTZControl(m_lPlayHandle,AUX_PWRON1,0);
			GetDlgItem(IDC_BTN_AUX_PWRON)->SetWindowText("停止1");
			m_bAuxOn1 = TRUE;
		}
		else
		{
			NET_DVR_PTZControl(m_lPlayHandle,AUX_PWRON1,1);
			GetDlgItem(IDC_BTN_AUX_PWRON)->SetWindowText("辅助1");
			m_bAuxOn1 = FALSE;
		}
	}

	
}

/*************************************************
函数名:    	OnBtnAuxPwron2
函数描述:	开始/停止 辅助设备2
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnBtnAuxPwron2() 
{
	if(m_lPlayHandle >= 0)
	{
		if(!m_bAuxOn2)
		{
			NET_DVR_PTZControl(m_lPlayHandle,AUX_PWRON2,0);
			GetDlgItem(IDC_BTN_AUX_PWRON2)->SetWindowText("停止2");
			m_bAuxOn2 = TRUE;
		}
		else
		{
			NET_DVR_PTZControl(m_lPlayHandle,AUX_PWRON2,1);
			GetDlgItem(IDC_BTN_AUX_PWRON2)->SetWindowText("辅助2");
			m_bAuxOn2 = FALSE;
		}
	}
	
}

/*************************************************
函数名:    	OnBtnFanPwron
函数描述:	开始/停止 风扇
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnBtnFanPwron() 
{
	if(m_lPlayHandle >= 0)
	{
		if(!m_bFanOn)
		{
			NET_DVR_PTZControl(m_lPlayHandle,FAN_PWRON,0);
			GetDlgItem(IDC_BTN_FAN_PWRON)->SetWindowText("停风");
			m_bFanOn = TRUE;
		}
		else
		{
			NET_DVR_PTZControl(m_lPlayHandle,FAN_PWRON,1);
			GetDlgItem(IDC_BTN_FAN_PWRON)->SetWindowText("风扇");
			m_bFanOn = FALSE;
		}
	}
	
	
}

/*************************************************
函数名:    	OnBtnHeaterPwron
函数描述:	开始/停止加热
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnBtnHeaterPwron() 
{
	if(m_lPlayHandle >= 0)
	{
		if(!m_bHeaterOn)
		{
			NET_DVR_PTZControl(m_lPlayHandle,HEATER_PWRON,0);
			GetDlgItem(IDC_BTN_HEATER_PWRON)->SetWindowText("停止");
			m_bHeaterOn = TRUE;
		}
		else
		{
			NET_DVR_PTZControl(m_lPlayHandle,HEATER_PWRON,1);
			GetDlgItem(IDC_BTN_HEATER_PWRON)->SetWindowText("加热");
			m_bHeaterOn = FALSE;
		}
	}
	
	
}

/*************************************************
函数名:    	OnBtnLightPwron
函数描述:	打开/关闭灯光
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnBtnLightPwron() 
{
	if(m_lPlayHandle >= 0)
	{
		if(!m_bLightOn)
		{
			NET_DVR_PTZControl(m_lPlayHandle,LIGHT_PWRON,0);
			GetDlgItem(IDC_BTN_LIGHT_PWRON)->SetWindowText("关灯");
			m_bLightOn = TRUE;
		}
		else
		{
			NET_DVR_PTZControl(m_lPlayHandle,LIGHT_PWRON,1);
			GetDlgItem(IDC_BTN_LIGHT_PWRON)->SetWindowText("灯光");
			m_bLightOn = FALSE;
		}
	}
	
}

/*************************************************
函数名:    	OnBtnWiperPwron
函数描述:	开始/停止雨刷
输入参数:   
输出参数:   			
返回值:		
**************************************************/
void CRealPlayDlg::OnBtnWiperPwron() 
{
	if(m_lPlayHandle >= 0)
	{	
		if(!m_bWiperOn)
		{
		    NET_DVR_PTZControl(m_lPlayHandle,WIPER_PWRON,0);
		    GetDlgItem(IDC_BTN_WIPER_PWRON)->SetWindowText("雨停");
		    m_bWiperOn = TRUE;
		}
	    else
		{
            NET_DVR_PTZControl(m_lPlayHandle,WIPER_PWRON,1);
	    	GetDlgItem(IDC_BTN_WIPER_PWRON)->SetWindowText("雨刷");
	    	m_bWiperOn = FALSE;
		}

	}

}


void CRealPlayDlg::OnSelchangeComboPicType() 
{
	int iSel = m_coPicType.GetCurSel();
	if(0 == iSel)  //bmp
	{   
		GetDlgItem(IDC_STATIC_JPGPARA)->EnableWindow(FALSE);
        m_coJpgSize.EnableWindow(FALSE);
		m_coJpgQuality.EnableWindow(FALSE);
	}
	else if(1 == iSel)          //jpg
	{
		GetDlgItem(IDC_STATIC_JPGPARA)->EnableWindow(TRUE);
        m_coJpgSize.EnableWindow(TRUE);
		m_coJpgQuality.EnableWindow(TRUE);
	}
	
}

void CRealPlayDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if (m_bIsLogin)
	{
        StopPlay();		
        NET_DVR_Logout_V30(m_struDeviceInfo.lLoginID); 
	}
	CDialog::OnClose();
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值