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

📄 netsdkdemo.cpp

📁 用大华sdk
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// NetSDKDemo.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "NetSDKDemo.h"
#include "NetSDKDemoDlg.h"


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

//动态设备信息列表指针;
//CRITICAL_SECTION g_cs;
//CPtrList    *g_ptrdevicelist;
//CDeviceListProtector dlp(&g_ptrdevicelist);
//SplitInfoNode g_splitinfo[MAX_CHANNUM];
CString g_strWorkDir;
/////////////////////////////////////////////////////////////////////////////
// CNetSDKDemoApp
/////////////////////////////////////////////////////////////////////////////
// The one and only CNetSDKDemoApp object

CNetSDKDemoApp theApp;


BEGIN_MESSAGE_MAP(CNetSDKDemoApp, CWinApp)
	//{{AFX_MSG_MAP(CNetSDKDemoApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetSDKDemoApp construction




CNetSDKDemoApp::CNetSDKDemoApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}



/////////////////////////////////////////////////////////////////////////////
// CNetSDKDemoApp initialization

BOOL CNetSDKDemoApp::InitInstance()
{
//	InitializeCriticalSection(&g_cs);
	AfxEnableControlContainer();

//	memset((char *)g_splitinfo, 0, sizeof(g_splitinfo));
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
	
	CNetSDKDemoDlg dlg;
	m_pMainWnd = &dlg;
	
	//new
	m_OnOff = true;				//关机按钮按动状态。2006/12/18
	//初始化红外串口。刘海2006/9/30
	CString stmp,skey;
	int i,j;
	BYTE b;
	m_pszRegistryKey = NULL;
	free((void*)m_pszProfileName);
	m_pszProfileName  =_tcsdup(_T(".\\ir.ini"));
	for (i=0;i<COUNT_BUTTON;i++)
	{		//从ini文件中读取按健码
		skey.Format("key%d",i);
		stmp=GetProfileString(REMOTE_CONTROL,skey,"");
		m_ir_data[i].RemoveAll();
		if (stmp.GetLength()>5 && stmp.GetLength()%2==0)
			for (j=0;j<stmp.GetLength()/2;j++)
			{
				skey=stmp.GetAt(j*2);
				skey+=stmp.GetAt(j*2+1);
				sscanf(skey,"%x",&b);
				m_ir_data[i].Add(b);
			}
	}
	for (i=0;i<8;i++)
	{		//从ini文件中读取按健码
		skey.Format("tv%d",i);
		stmp=GetProfileString(REMOTE_CONTROL,skey,"");
		m_tv_data[i].RemoveAll();
		if (stmp.GetLength()>5 && stmp.GetLength()%2==0)
			for (j=0;j<stmp.GetLength()/2;j++)
			{
				skey=stmp.GetAt(j*2);
				skey+=stmp.GetAt(j*2+1);
				sscanf(skey,"%x",&b);
				m_tv_data[i].Add(b);
			}
	}
	irEvent = CreateEvent(NULL,FALSE,FALSE,NULL);		//自动翻转,创建无信号
	i=GetProfileInt(REMOTE_CONTROL,"port",1);
	InitComm(i);
	m_ir_fn=7;		//默认是dvr
	//串口初始化完毕
	//AfxMessageBox("串口初始化完毕");
	//new

	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}
	
	m_ComPort.Close();
	
	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
//new
void CNetSDKDemoApp::InitComm(int port)
{
	m_learn=false;
	m_learn_count=0;
	try
	{
		m_ComPort.Close();
		m_ComPort.Open(port,LsComm::CComPort::AutoReceiveBySignal,4800 );
		m_ComPort.SetReceiveFunc((FOnReceiveData)OnReceiveData,this); 
		//AfxMessageBox("已经打开串口");
	}
	catch (CException* e)
	{
		char errmesg[20];
		e->GetErrorMessage(errmesg,sizeof(errmesg));
		CString cstring;
		cstring.Format("%s",errmesg);
		//AfxMessageBox("打开串口失败!"+cstring);
	}
}
void CNetSDKDemoApp::RemoteControl(int button)
{
	
	CNetSDKDemoDlg* main=(CNetSDKDemoDlg*) theApp.m_pMainWnd;
	
	main->m_devicelist.SetFocus();

	SetEvent(irEvent);		//发生事件
	
	switch (button)
	{
		case 0:
			if (theApp.m_tv_data[button].GetSize()>0)
			{
			  theApp.m_ComPort.Output(theApp.m_tv_data[button].GetData(),theApp.m_tv_data[button].GetSize());
			  if (m_OnOff)
			    SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-开关");
			  else
				SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-开关,再按确认可关闭电脑");
			}
			else
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-开关,未学习电视遥控器\"开关\"信号");

			m_OnOff = !m_OnOff;
			m_ir_fn=button;
			break;
			
		case 1:
			//控制电视的信号,丛串口发出命令
			if (theApp.m_tv_data[button].GetSize()>0)
			{
			  theApp.m_ComPort.Output(theApp.m_tv_data[button].GetData(),theApp.m_tv_data[button].GetSize());
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-Av/Tv,电视'Av/Tv'切换");
			}
			else
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-Av/Tv,未学习电视遥控器\"Av/Tv\"切换信号");
			break;
			
		case 2:
			//控制电视的信号,丛串口发出命令
			if (theApp.m_tv_data[button].GetSize()>0)
			{
			  theApp.m_ComPort.Output(theApp.m_tv_data[button].GetData(),theApp.m_tv_data[button].GetSize());
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-频道+");
			}
			else
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-频道+,未学习电视遥控器\"频道+\"信号");
			break;
			
		case 3:
			//控制电视的信号,丛串口发出命令
			if (theApp.m_tv_data[button].GetSize()>0)
			{
			  theApp.m_ComPort.Output(theApp.m_tv_data[button].GetData(),theApp.m_tv_data[button].GetSize());
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-频道-");
			}
			else
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-频道-,未学习电视遥控器\"频道-\"信号");
			break;
		case 4:
			//控制电视的信号,丛串口发出命令
			if (theApp.m_tv_data[button].GetSize()>0)
			{
			  theApp.m_ComPort.Output(theApp.m_tv_data[button].GetData(),theApp.m_tv_data[button].GetSize());
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-音量+");
			}
			else
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-音量+,未学习电视遥控器\"音量+\"信号");
			break;
		case 5:
			//控制电视的信号,丛串口发出命令
			if (theApp.m_tv_data[button].GetSize()>0)
			{
			  theApp.m_ComPort.Output(theApp.m_tv_data[button].GetData(),theApp.m_tv_data[button].GetSize());
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-音量-");
			}
			else
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-音量-,未学习电视遥控器\"音量-\"信号");
			break;
		case 6:
			//控制电视的信号,丛串口发出命令
			//控制电视的信号,丛串口发出命令
			if (theApp.m_tv_data[button].GetSize()>0)
			{
			  theApp.m_ComPort.Output(theApp.m_tv_data[button].GetData(),theApp.m_tv_data[button].GetSize());
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-菜单");
			}
			else
			  SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"电视-菜单,未学习电视遥控器\"菜单\"信号");
			break;
		case 7:
			m_ir_fn=button;
			main->Flash(2);
			main->SelDvr(0);
			SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"进入DVR控制,请按方向键选择DVR服务器");
			break;
		case 9:
			m_ir_fn=button;
			//main->m_dlgVod.QueryFile();
			SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"视频回放");
			main->Flash(5);
			main->ShowVod(button);//new
			break;
		case 10:	//通道
			m_ir_fn=button;
			main->Flash(4);
			main->SelDvr(1);
			break;
		case 8:
			m_ir_fn=button;			//聚焦,焦距,云台不引起界面选择变化
			main->Flash(3);
			main->InitlizePtzStopInfo();
			SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"聚焦控制,请按方向键改变聚焦大小");
			break;
		case 11:
			m_ir_fn=button;			//聚焦,焦距,云台不引起界面选择变化
			main->Flash(3);
			main->InitlizePtzStopInfo();
			SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"焦距控制,请按方向键改变焦距大小");
			break;
		case 12:
			m_ir_fn=button;			//聚焦,焦距,云台不引起界面选择变化
			main->Flash(1);
			main->InitlizePtzStopInfo();
			SetDlgItemText(main->m_hWnd,IDC_EDT_HINT,"云台控制,请按方向键改变云台");
			break;
			
		case 13:			//上
			main->Flash(6);
			switch(m_ir_fn)
			{
			case 7:
				main->SelectNext(0,0,0);
				break;
			case 8:
				main->PtzZoomWide();
				break;
			case 9:
				//main->m_dlgVod.SelFile(-1);
				main->ShowVod(button);
				break;
			case 10:
				main->SelectNext(1,0,0);
				break;
			case 11:		//焦距
				main->PtzZoomWide();
				break;
			case 12:		//云台
				main->PtzUp();
				break;
			}
			break;
		case 14:		//下
			main->Flash(7);
			switch(m_ir_fn)
			{
			case 7:
				main->SelectNext(0,1,0);
				break;
			case 8:
				main->PtzZoomTele();
				break;
			case 9:
				//main->m_dlgVod.SelFile(1);
				main->ShowVod(button);
				break;
			case 10:
				main->SelectNext(1,1,0);
				break;
			case 11:		//焦距
				main->PtzZoomTele();
				break;
			case 12:		//云台
				main->PtzDown();
				break;
			}
			break;
		case 15:		//左
			main->Flash(8);
			switch(m_ir_fn)
			{
			case 7:
				main->SelectNext(0,0,0);
				break;
			case 8:
				main->PtzZoomWide();
				break;
			case 9:
				//main->m_dlgVod.SelFile(-1);
				main->ShowVod(button);
				break;
			case 10:
				main->SelectNext(1,0,0);
				break;
			case 11:		//焦距
				main->PtzZoomWide();
				break;
			case 12:		//云台
				main->PtzLeft();
				break;
			}
			break;
		case 16:		//右
			main->Flash(9);
			switch(m_ir_fn)
			{
			case 7:
				main->SelectNext(0,1,0);
				break;
			case 8:
				main->PtzZoomTele();

⌨️ 快捷键说明

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