// MsSDKTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MsSDKTest.h"
#include "MsSDKTestDlg.h"
#include "DlgPlayBack.h"
#include "DlgUserSettings.h"
#include "DlgPtz.h"
#include "DlgVideoConfig.h"
#include "DlgAudioConfig.h"
#include "DlgCmosConfig.h"
#include "DlgAlarmConfig.h"
#include "DlgSmtp.h"
#include "DlgFtp.h"
#include "DlgDdns.h"
#include "DlgMask.h"
#include "DlgConnectLimit.h"
//#include <string>
//using namespace std;

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CMsSDKTestDlg *CMsSDKTestDlg::m_pThis = NULL;
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()

/////////////////////////////////////////////////////////////////////////////
// CMsSDKTestDlg dialog

CMsSDKTestDlg::CMsSDKTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMsSDKTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMsSDKTestDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	CMsSDKTestDlg::m_pThis = this;
	m_DateTime = 0;
	memset(m_sModel, 0, sizeof(m_sModel));
}

void CMsSDKTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMsSDKTestDlg)
	DDX_Control(pDX, IDC_BUTTON_DBG_TEST, m_btnDbgTest);
	DDX_Control(pDX, IDC_TIME_PICKER, m_DT_Time);
	DDX_Control(pDX, IDC_DATE_PICKER, m_DT_Date);
	DDX_Control(pDX, IDC_STATIC_LIVE, m_wndLivePlay);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMsSDKTestDlg, CDialog)
	//{{AFX_MSG_MAP(CMsSDKTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_LOGIN, OnBtnLogin)
	ON_BN_CLICKED(IDC_BTN_GETNETROK, OnBtnGetnetwork)
	ON_BN_CLICKED(IDC_BTN_SETNETWORK, OnBtnSetnetwork)
	ON_BN_CLICKED(IDC_BTN_GET_SYSTEM_INFO, OnBtnGetSystemInfo)
	ON_BN_CLICKED(IDC_BTN_GET_DATETIME, OnBtnGetDatetime)
	ON_BN_CLICKED(IDC_BTN_SET_DATETIME, OnBtnSetDatetime)
	ON_BN_CLICKED(IDC_BTN_REBOOT, OnBtnReboot)
	ON_BN_CLICKED(IDC_BTN_RESTORE, OnBtnRestore)
	ON_BN_CLICKED(IDC_BTN_PLAY, OnBtnPlay)
	ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BTN_SEARCH, OnBtnSearch)
	ON_BN_CLICKED(IDC_BTN_CLEAR_TEXT, OnBtnClearText)
	ON_BN_CLICKED(IDC_BTN_LOGOUT, OnBtnLogout)
	ON_BN_CLICKED(IDC_BTN_PLAYBACK, OnBtnPlayback)
	ON_BN_CLICKED(IDC_BTN_CAPTURE_IMAGE, OnBtnCaptureImage)
	ON_BN_CLICKED(IDC_BTN_RECORD, OnBtnRecord)
	ON_BN_CLICKED(IDC_BTN_GET_RTSP_UTL, OnBtnGetRtspUtl)
	ON_BN_CLICKED(IDC_CHK_SHOW_GRID, OnChkShowGrid)
	ON_BN_CLICKED(IDC_STATIC_LIVE, OnStaticLive)
	ON_BN_CLICKED(IDC_BTN_SELECT_FILE, OnBtnSelectFile)
	ON_BN_CLICKED(IDC_BTN_UPDATE_FIREWARE, OnBtnUpdateFirmware)
	ON_BN_CLICKED(IDC_BTN_USER_SETTING, OnBtnUserSetting)
	ON_BN_CLICKED(IDC_BTN_PTZ, OnBtnPtz)
	ON_BN_CLICKED(IDC_BTN_VIDEO_CONFIG, OnBtnVideoConfig)
	ON_BN_CLICKED(IDC_BTN_AUDIO_CONFIG, OnBtnAudioConfig)
	ON_BN_CLICKED(IDC_BTN_SD_CONFIG, OnBtnSdConfig)
	ON_BN_CLICKED(IDC_BTN_PRIVACY_MASK, OnBtnPrivacyMask)
	ON_BN_CLICKED(IDC_BTN_ALARM_CONFIG, OnBtnAlarmConfig)
	ON_BN_CLICKED(IDC_BTN_CMOS_CONFIG, OnBtnCmosConfig)
	ON_BN_CLICKED(IDC_BTN_CLEAR_OUTPUT, OnBtnClearOutput)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_BTN_SMTP, OnBtnSmtp)
	ON_BN_CLICKED(IDC_BTN_FTP, OnBtnFtp)
	ON_BN_CLICKED(IDC_BTN_DDNS, OnBtnDdns)
	ON_BN_CLICKED(IDC_RADIO_DT_MANUAL, OnRadioDtManual)
	ON_BN_CLICKED(IDC_RADIO_DT_SNTP, OnRadioDtSntp)
	ON_BN_CLICKED(IDC_RADIO_DT_COMPUTER, OnRadioDtComputer)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BTN_DEFAULT_PARA, OnBtnDefaultPara)
	ON_BN_CLICKED(IDC_BTN_SET_SYSTEM_INFO, OnBtnSetSystemInfo)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BTN_CONNECT, OnBtnConnectLimit)
	ON_BN_CLICKED(IDC_BTN_GETPORT, OnBtnGetport)
	ON_BN_CLICKED(IDC_BTN_SETPORT, OnBtnSetport)
	ON_BN_CLICKED(IDC_BUTTON_DBG_TEST, OnButtonDbgTest)
	//}}AFX_MSG_MAP
	ON_NOTIFY_EX(TTN_NEEDTEXT,0,OnToolTipNotify)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMsSDKTestDlg message handlers
void CMsSDKTestDlg::UpdateText(char *sParam)
{
	char sText[2048] = {0};
	UpdateData(TRUE);
	CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT_OUTPUT);

	GetDlgItem(IDC_EDIT_OUTPUT)->GetWindowText(sText, sizeof(sText));
	_snprintf(sText, sizeof(sText)-1, "%s%s", sText, sParam);
	GetDlgItem(IDC_EDIT_OUTPUT)->SetWindowText(sText);
	
	pEdit->LineScroll(pEdit->GetLineCount(), 0);
	UpdateData(FALSE);
}

void CMsSDKTestDlg::OutputTips(const char* pText, ...)
{
	va_list  va;
	char szParam[1024] = "";
	struct tm * pt;
	time_t now;
	now = time(NULL);
	pt = localtime(&now);
	_snprintf(szParam, sizeof(szParam) - 1, "%04d/%02d/%02d %02d:%02d:%02d -- ", pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday, pt->tm_hour, pt->tm_min, pt->tm_sec);
	
	va_start (va, pText);
	_vsnprintf(szParam + strlen(szParam), sizeof(szParam) - strlen(szParam) - 1, pText, va);
	_snprintf(szParam, sizeof(szParam)-1, "%s\r\n", szParam);
	va_end(va);

	OutputDebugString(szParam);
	((CMsSDKTestDlg*)m_pThis)->UpdateText(szParam);
}

bool CMsSDKTestDlg::UTF8ToMB(char *pmb, const char* pu8, int utf8Len)
{
	// convert an UTF8 string to widechar 
	int nLen = MultiByteToWideChar(CP_UTF8, 0, pu8, -1, NULL, 0);

	WCHAR* lpszW = NULL;
	
	lpszW = new WCHAR[nLen];

	int nRtn = MultiByteToWideChar(CP_UTF8, 0, pu8, -1, lpszW, nLen);

	if(nRtn != nLen)
	{
		delete[] lpszW;
		return false;
	}

	// convert an widechar string to Multibyte 
	int MBLen = WideCharToMultiByte(CP_ACP, 0, lpszW, -1, NULL, 0, NULL, NULL);
	if (MBLen <=0)
	{
		return false;
	}
	nRtn = WideCharToMultiByte(CP_ACP, 0, lpszW, -1, pmb, MBLen, NULL, NULL);
	delete[] lpszW;

	if(nRtn != MBLen)
	{
		return false;
	}
	return true;
}

bool CMsSDKTestDlg::MBToUTF8(char* pu8, const char* pmb, int mLen)  
{  
	// convert an MBCS string to widechar   
	int nLen = MultiByteToWideChar(CP_ACP, 0, pmb, mLen, NULL, 0);  
	
	WCHAR* lpszW = NULL;  
	
	lpszW = new WCHAR[nLen];  
	
	int nRtn = MultiByteToWideChar(CP_ACP, 0, pmb, mLen, lpszW, nLen);  
	
	if(nRtn != nLen)  
	{  
		delete[] lpszW;  
		return false;  
	}  
	// convert an widechar string to utf8  
	int utf8Len = WideCharToMultiByte(CP_UTF8, 0, lpszW, nLen, NULL, 0, NULL, NULL);  
	if (utf8Len <= 0)  
	{  
		return false;  
	}
	nRtn = WideCharToMultiByte(CP_UTF8, 0, lpszW, nLen, pu8, utf8Len, NULL, NULL);  
	delete[] lpszW;  
	
	if (nRtn != utf8Len)  
	{  
		return false;  
	}  
	return true;  
}

BOOL CMsSDKTestDlg::encodeURL(const char *sUrl, char *sEncodeUrl, int nEnLen)
{
	unsigned char *pWork = (unsigned char *)sUrl;
	memset(sEncodeUrl, 0x0, nEnLen);
	if((int)strlen(sUrl) > nEnLen)
		return FALSE;
	while( *pWork != 0x0 )
	{
		if ( *pWork != '!' && *pWork != '@' && *pWork != '#' &&
		*pWork != '$' && *pWork != '&' && *pWork != '*' &&
		*pWork != '(' && *pWork != ')' && *pWork != '=' &&
		*pWork != ':' && *pWork != '/' && *pWork != ';' &&
		*pWork != '?' && *pWork != '+' && *pWork != '\'' &&
		*pWork != '.' )
		{
			sprintf(sEncodeUrl+strlen(sEncodeUrl),"%%%2X",*pWork);
		}
		else
		{
			sprintf(sEncodeUrl+strlen(sEncodeUrl),"%c",*pWork);
		}
		pWork++;
	}
	return TRUE;
}

int CMsSDKTestDlg::Multibyte_2_Widechar(int nCode, LPCSTR szSrc, LPTSTR szDest, int nMaxChars)//失败返回0
{
	if (szSrc == NULL || szDest == NULL || strlen(szSrc) == 0)
		return 0;
	int nSize = 0;
#ifdef UNICODE
	nSize = MultiByteToWideChar(nCode, 0, szSrc, -1, NULL, 0);
#else
	nSize = strlen(szSrc);
#endif
	
	nSize = ((nSize<nMaxChars)?nSize:(nMaxChars-1));
	
#ifdef UNICODE
	return MultiByteToWideChar(nCode, 0, szSrc, -1, szDest, nSize);
#else
	return ((lstrcpy(szDest, szSrc) == NULL) ? 0 : nSize);
#endif	
	
}

int CMsSDKTestDlg::Widechar_2_Multibyte(int nCode, LPCTSTR szSrc, LPSTR szDest, int nMaxBytes, BOOL bNeedEscape/* = TRUE*/)//失败返回0
{
	if (szSrc == NULL || szDest == NULL || lstrlen(szSrc) == 0)
		return 0;
	
	CString strTemp = _T("");
	strTemp.Format(_T("%s"), szSrc);
	int nSize = 0;
	int nReturn = 0;
	TCHAR* szTempBuf = new TCHAR[nMaxBytes*2];
	TRY {
		if (bNeedEscape)
		{
			ZeroMemory(szTempBuf, nMaxBytes*2);
			int nIndex = 0;
			for (int i = 0; i < strTemp.GetLength(); i++)
			{
				TCHAR ch = strTemp.GetAt(i);
				if (ch == '\\' || ch == '\'')
				{
					szTempBuf[nIndex] = '\\';
					nIndex++;
				}
				szTempBuf[nIndex] = ch;
				nIndex++;
			}
			szTempBuf[nMaxBytes-1] = '\0';
		}
		else
		{
			lstrcpy(szTempBuf, strTemp.GetBuffer(0));
		}
		
#ifdef UNICODE
		nSize = WideCharToMultiByte(nCode, 0, szTempBuf, -1, NULL, 0, NULL, 0);//返回需要的字节数(字节数包含一个字节的结束符)
#else
		nSize = lstrlen(szSrc);
#endif
		
		nSize = ((nSize<nMaxBytes)?nSize:(nMaxBytes-1));
		
#ifdef UNICODE
		nReturn = WideCharToMultiByte(nCode, 0, szTempBuf, -1, szDest, nSize, NULL, 0);
#else
		nReturn = ((lstrcpy(szDest, szSrc) == NULL) ? 0 : nSize);
#endif
		
		delete []szTempBuf;
	}
	CATCH (CMemoryException, e)
	{
		delete []szTempBuf;
		e->Delete();
	}
	END_CATCH
		
	strTemp.ReleaseBuffer();//ljc add
		return nReturn;
}


int MsSscanf(const char *sText, const char *sRegExp, const char sSep[1], char *sResult)
{
	int i = 0;
	int nStart = strlen(sRegExp);
	const char *pStr = strstr(sText, sRegExp);
	if(!pStr)
		return -1;
	for(; i < (int)strlen(pStr); i++){
		if(pStr[nStart+i] == sSep[0])
			break;
		sResult[i] = pStr[nStart+i];
	}
	return i;
}

void CMsSDKTestDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	char sDiskPath[MAX_PATH] = {0};
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DISK);
	pComboBox->GetLBText(pComboBox->GetCurSel(), sDiskPath);

	CRegOp regObj;
	regObj.WriteReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_SAVEDISK, sDiskPath, strlen(sDiskPath), REG_SZ);
	KillTimer(1001);
	Ms_Sdk_Destroy();	
}

BOOL CMsSDKTestDlg::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
#ifndef _DEBUG
	m_btnDbgTest.ShowWindow(SW_HIDE);
#endif
	
	memset(m_sMacAddr, 0, sizeof(m_sMacAddr));
	char sIP[32] = {0}, sPort[32] = {0}, sUserName[32] = {0}, sPassword[16] = {0};
	CRegOp regObj;
	regObj.ReadReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_IP, "192.168.5.190", sIP, sizeof(sIP));
	regObj.ReadReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_PORT, "80", sPort, sizeof(sPort));
	regObj.ReadReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_USER, "admin", sUserName, sizeof(sUserName));
	regObj.ReadReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_PASSWORD, "ms1234", sPassword, sizeof(sPassword));
	GetDlgItem(IDC_EDIT_LOGIN_IP)->SetWindowText(sIP);
	GetDlgItem(IDC_EDIT_LOGIN_PORT)->SetWindowText(sPort);
 	GetDlgItem(IDC_EDIT_LOGIN_USERNAME)->SetWindowText(sUserName);
//	GetDlgItem(IDC_EDIT_LOGIN_USERNAME)->SetWindowText("admin");
// 	((CEdit*)GetDlgItem(IDC_EDIT_LOGIN_USERNAME))->SetReadOnly(TRUE);
	GetDlgItem(IDC_EDIT_LOGIN_PASSWORD)->SetWindowText(sPassword);
	FillDiskData();//IDC_COMBO_DISK
	CComboBox *pComboBoxStreamType = (CComboBox*)GetDlgItem(IDC_COMBO_STREAM_TYPE);
	pComboBoxStreamType->InsertString(0, "Main");
	pComboBoxStreamType->InsertString(1, "Sub");
	pComboBoxStreamType->SetCurSel(0);
	CSliderCtrl *pSliderB = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_BRIGHTNESS);
	CSliderCtrl *pSliderC = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_CONTRAST);
	CSliderCtrl *pSliderS = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SATURATION);
	CSliderCtrl *pSliderSp = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SHARPNESS);
	CSliderCtrl *pSliderR = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_REDUCTION);
	pSliderS->SetRange(0, 100);
	pSliderC->SetRange(0, 100);
	pSliderB->SetRange(0, 100);
	pSliderSp->SetRange(0, 100);
	pSliderR->SetRange(0, 100);
	UpdateData(FALSE);
	m_tooltip.Create(this); 
	m_tooltip.AddTool(pSliderB, LPSTR_TEXTCALLBACK);
	m_tooltip.AddTool(pSliderC, LPSTR_TEXTCALLBACK);
	m_tooltip.AddTool(pSliderS, LPSTR_TEXTCALLBACK);
	m_tooltip.AddTool(pSliderSp, LPSTR_TEXTCALLBACK);
	m_tooltip.AddTool(pSliderR, LPSTR_TEXTCALLBACK);

	m_nUserID = -1;
	m_bPlay = FALSE;
	m_bFullClient = FALSE;
	m_bRecord = FALSE;
	// TODO: Add extra initialization here
	LONG nResult = Ms_Sdk_Init();
	OnBtnLogin();
	OnBtnGetnetwork();
	OnBtnGetport();
	OnBtnGetSystemInfo();
	OnBtnGetDatetime();
	OnBtnGetRtspUtl();
	//OnBtnUserSetting();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMsSDKTestDlg::FillDiskData()
{
	int nIndex = 0;
	TCHAR buf[128]; 
    DWORD len = GetLogicalDriveStrings(sizeof(buf)/sizeof(TCHAR),buf); 
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DISK);
	for(TCHAR* s=buf; *s; s+=_tcslen(s)+1) 
	{ 
		LPCTSTR sDrivePath = s;
		int nDriverType = GetDriveType(sDrivePath);

		if(nDriverType == DRIVE_FIXED){
			pComboBox->InsertString(nIndex++, sDrivePath);
		}
	} 
	char sDiskPath[MAX_PATH] = {0};
	CRegOp regObj;
	regObj.ReadReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_SAVEDISK, "C:\\", sDiskPath, sizeof(sDiskPath));
	if(pComboBox->SelectString(-1, sDiskPath) == CB_ERR)
		pComboBox->SetCurSel(0);
}

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

void CMsSDKTestDlg::OnBtnLogin() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	char sIP[32] = {0}, sPort[32] = {0}, sUserName[32] = {0}, sPassword[16] = {0};
	GetDlgItem(IDC_EDIT_LOGIN_IP)->GetWindowText(sIP, sizeof(sIP));
	GetDlgItem(IDC_EDIT_LOGIN_PORT)->GetWindowText(sPort, sizeof(sPort));
	GetDlgItem(IDC_EDIT_LOGIN_USERNAME)->GetWindowText(sUserName, sizeof(sUserName));
	GetDlgItem(IDC_EDIT_LOGIN_PASSWORD)->GetWindowText(sPassword, sizeof(sPassword));
	
	Ms_Ipc_Logout(m_nUserID);
	LONG nResult = Ms_Ipc_Login(sIP, sIP, atoi(sPort), sUserName, sPassword, NULL);
	if(nResult != -1)
		OutputTips("Login Successfully.");
	else{
		OutputTips("Login Failed.");
		return;
	}
	m_nUserID = nResult;
	Ms_Ipc_SystemInfo systemInfo = {0};
	memset(m_sModel, 0, sizeof(m_sModel));
	if(!Ms_Ipc_GetSystemInfo(m_nUserID, &systemInfo)){
		_snprintf(m_sModel, sizeof(m_sModel), "%s", systemInfo.sModel);
	}

	CRegOp regObj;
	regObj.WriteReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_IP, sIP, strlen(sIP), REG_SZ);
	regObj.WriteReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_PORT, sPort, strlen(sPort), REG_SZ);
	regObj.WriteReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_USER, sUserName, strlen(sUserName), REG_SZ);
	regObj.WriteReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_PASSWORD, sPassword, strlen(sPassword), REG_SZ);

	CSliderCtrl *pSliderB = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_BRIGHTNESS);
	CSliderCtrl *pSliderC = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_CONTRAST);
	CSliderCtrl *pSliderS = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SATURATION);
	CSliderCtrl *pSliderSp = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SHARPNESS);
	CSliderCtrl *pSliderR = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_REDUCTION);
	Ms_Ipc_ImagingSettings imgSettings = {0};
	if(Ms_Ipc_GetImagingSettings(m_nUserID, &imgSettings))
		return;
	pSliderB->SetPos(imgSettings.nBrightness);
	pSliderC->SetPos(imgSettings.nContrast);
	pSliderS->SetPos(imgSettings.nSaturation);
	pSliderSp->SetPos(imgSettings.nSharpness);
	pSliderR->SetPos(imgSettings.nFLevel);
}

void CMsSDKTestDlg::OnBtnLogout() 
{
	LONG nResult = Ms_Ipc_Logout(m_nUserID);
	if(!nResult)
		OutputTips("Logout Successfully.");
}

void CMsSDKTestDlg::OnBtnGetnetwork() 
{
	char sValue[32] = {0};
	Ms_Ipc_Network network = {0};
//	Ms_Ipc_WifiInfo wifiinfo = {0};
	LONG nResult = Ms_Ipc_GetNetwork(m_nUserID, &network);	
//	nResult = Ms_Ipc_GetWifiInfo(m_nUserID, &wifiinfo);	
	if(nResult)
		return;
	UpdateData(TRUE);

	if(network.bDHCP)
		CheckRadioButton(IDC_RADIO_DHCP, IDC_RADIO_MANAUL, IDC_RADIO_DHCP);
	else
		CheckRadioButton(IDC_RADIO_DHCP, IDC_RADIO_MANAUL, IDC_RADIO_MANAUL);

	GetDlgItem(IDC_EDIT_IP)->SetWindowText(network.sIP);
	GetDlgItem(IDC_EDIT_NETMAKS)->SetWindowText(network.sNetmask);
	GetDlgItem(IDC_EDIT_GATEWAY)->SetWindowText(network.sGateway);
	GetDlgItem(IDC_EDIT_DNS)->SetWindowText(network.sDNS);
	_snprintf(m_sMacAddr, sizeof(m_sMacAddr)-1, "%s", network.sMacAddress);
	_snprintf(sValue, sizeof(sValue)-1, "%d", network.nHttpPort);
	GetDlgItem(IDC_EDIT_HTTP_PORT)->SetWindowText(sValue);
	UpdateData(FALSE);
}

void CMsSDKTestDlg::OnBtnSetnetwork() 
{
	char sValue[32] = {0};
	Ms_Ipc_Network network = {0};
	UpdateData(TRUE);
	if(GetCheckedRadioButton(IDC_RADIO_DHCP, IDC_RADIO_MANAUL) == IDC_RADIO_DHCP)
		network.bDHCP = 1;
	else
		network.bDHCP = 0;
	// avoid empty value
	CString strTemp;
	GetDlgItem(IDC_EDIT_IP)->GetWindowText(strTemp);
	strTemp.TrimLeft();
	strTemp.TrimRight();
	GetDlgItem(IDC_EDIT_IP)->SetWindowText(strTemp);
	GetDlgItem(IDC_EDIT_NETMAKS)->GetWindowText(strTemp);
	strTemp.TrimLeft();
	strTemp.TrimRight();
	GetDlgItem(IDC_EDIT_NETMAKS)->SetWindowText(strTemp);
	GetDlgItem(IDC_EDIT_GATEWAY)->GetWindowText(strTemp);
	strTemp.TrimLeft();
	strTemp.TrimRight();
	GetDlgItem(IDC_EDIT_GATEWAY)->SetWindowText(strTemp);
	GetDlgItem(IDC_EDIT_DNS)->GetWindowText(strTemp);
	strTemp.TrimLeft();
	strTemp.TrimRight();
	GetDlgItem(IDC_EDIT_DNS)->SetWindowText(strTemp);
// 	GetDlgItem(IDC_EDIT_HTTP_PORT)->GetWindowText(strTemp);
// 	strTemp.TrimLeft();
// 	strTemp.TrimRight();
// 	GetDlgItem(IDC_EDIT_HTTP_PORT)->SetWindowText(strTemp);
	//end

	GetDlgItem(IDC_EDIT_IP)->GetWindowText(network.sIP, sizeof(network.sIP));
	GetDlgItem(IDC_EDIT_NETMAKS)->GetWindowText(network.sNetmask, sizeof(network.sNetmask));
	GetDlgItem(IDC_EDIT_GATEWAY)->GetWindowText(network.sGateway, sizeof(network.sGateway));
	GetDlgItem(IDC_EDIT_DNS)->GetWindowText(network.sDNS, sizeof(network.sDNS));
	GetDlgItem(IDC_EDIT_HTTP_PORT)->GetWindowText(sValue, sizeof(sValue));
	network.nHttpPort = atoi(sValue);
	if(network.bDHCP == 0 && (network.sIP[0] == '\0' || network.sNetmask[0] == '\0' || network.sGateway[0] == '\0' || network.sDNS[0] == '\0'/* || network.nHttpPort < 1 || network.nHttpPort > 65535*/))
	{
		OutputTips("Field can't be empty.");
		return;
	}

	Ms_Ipc_Network networkGet = {0};
	LONG nResult = Ms_Ipc_GetNetwork(m_nUserID, &networkGet);
	if(network.bDHCP == 1)
	{
		if(network.sIP[0] == '\0')
			_snprintf(network.sIP, sizeof(network.sIP)-1, "%s", networkGet.sIP);
		if(network.sNetmask[0] == '\0')
			_snprintf(network.sNetmask, sizeof(network.sNetmask)-1, "%s", networkGet.sNetmask);
		if(network.sGateway[0] == '\0')
			_snprintf(network.sGateway, sizeof(network.sGateway)-1, "%s", networkGet.sGateway);
		if(network.sDNS[0] == '\0')
			_snprintf(network.sDNS, sizeof(network.sDNS)-1, "%s", networkGet.sDNS);
	}
	nResult = Ms_Ipc_SetNetwork(m_nUserID, &network);
	if(nResult){
		OutputTips("Modify Network Failed.");
		return;
	}
	OutputTips("Modify Network Successfully. Wait for relogin automatically.");
	GetDlgItem(IDC_EDIT_LOGIN_IP)->SetWindowText(network.sIP);
	Sleep(2000);
	char sUserName[32] = {0}, sPassword[16] = {0}, sPort[32] = {0};
	//GetDlgItem(IDC_EDIT_LOGIN_IP)->SetWindowText(network.sIP);
	//GetDlgItem(IDC_EDIT_LOGIN_PORT)->SetWindowText(network.nHttpPort);
	GetDlgItem(IDC_EDIT_LOGIN_PORT)->GetWindowText(sPort, sizeof(sPort));
	GetDlgItem(IDC_EDIT_LOGIN_USERNAME)->GetWindowText(sUserName, sizeof(sUserName));
	GetDlgItem(IDC_EDIT_LOGIN_PASSWORD)->GetWindowText(sPassword, sizeof(sPassword));
	m_nUserID = Ms_Ipc_Login(network.sIP, network.sIP, atoi(sPort), sUserName, sPassword, NULL);
	if(m_nUserID == -1){
		AfxMessageBox("Relogin Failed.");
		return;
	}
	OutputTips("Relogin Successfully.");
	CRegOp regObj;
	regObj.WriteReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_IP, network.sIP, strlen(network.sIP), REG_SZ);
}

void CMsSDKTestDlg::OnBtnGetSystemInfo() 
{
	Ms_Ipc_SystemInfo systemInfo = {0};
	LONG nResult = Ms_Ipc_GetSystemInfo(m_nUserID, &systemInfo);
	if(nResult)
		return;
	UpdateData(TRUE);
	char sNameMB[32] = {0};
	UTF8ToMB(sNameMB, systemInfo.sDeviceName, sizeof(sNameMB));
	GetDlgItem(IDC_EDIT_DEVICE_NAME)->SetWindowText(sNameMB);
	GetDlgItem(IDC_EDIT_MODEL)->SetWindowText(systemInfo.sModel);
	GetDlgItem(IDC_EDIT_SOFTWARE_VERSION)->SetWindowText(systemInfo.sSoftwareVersion);
	GetDlgItem(IDC_EDIT_HARDWARE_VERSION)->SetWindowText(systemInfo.sHardwareVersion);	
	GetDlgItem(IDC_EDIT_MAC)->SetWindowText(m_sMacAddr);
	UpdateData(FALSE);		
}

void CMsSDKTestDlg::OnBtnSetSystemInfo() // just for modify device name
{
	// TODO: Add your control notification handler code here
	char sDeviceName[32] = {0};
	// avoid empty value
	CString strTemp;
	GetDlgItem(IDC_EDIT_DEVICE_NAME)->GetWindowText(strTemp);
	strTemp.TrimLeft();
	strTemp.TrimRight();
	GetDlgItem(IDC_EDIT_DEVICE_NAME)->SetWindowText(strTemp);
	//end
	GetDlgItem(IDC_EDIT_DEVICE_NAME)->GetWindowText(sDeviceName, sizeof(sDeviceName));
	if(sDeviceName[0] == '\0')
	{
		AfxMessageBox("Device name can't be empty.");
		return;
	}
	char sEncodeName[128] = {0};
	char sNameUtf8[32] = {0};
	MBToUTF8(sNameUtf8, sDeviceName, sizeof(sDeviceName));
	encodeURL(sNameUtf8, sEncodeName, sizeof(sEncodeName));
	if(!Ms_Ipc_SetDeviceName(m_nUserID, sEncodeName))
		OutputTips("Set System info Successfully.");
	else
		OutputTips("Set System info Failed.");
}

void CMsSDKTestDlg::OnBtnReboot() 
{
	LONG nResult = Ms_Ipc_RebootSystem(m_nUserID);
	if(nResult)
		OutputTips("Reboot Failed.");
	else
		OutputTips("Reboot Successfully.");
}

void CMsSDKTestDlg::OnBtnRestore() 
{
	// TODO: Add your control notification handler code here
	LONG nResult = Ms_Ipc_RestoreSystem(m_nUserID);
	if(nResult)
		OutputTips("Restore Failed.");
	else
		OutputTips("Restore Successfully.");
}

void CMsSDKTestDlg::OnBtnGetDatetime() 
{
	KillTimer(1001);
	m_DT_Date.SetMonthCalColor(MCSC_TITLETEXT,RGB(255,0,0));
	m_DT_Date.SetFormat(_T("yyyy/MM/dd"));
	m_DT_Date.SetMonthCalColor(MCSC_TITLEBK,RGB(229,237,240));//改变背景色
	m_DT_Date.SetMonthCalColor(MCSC_MONTHBK,RGB(229,237,240));

	char sValue[32] = {0};
	Ms_Ipc_SystemDate dateTime = {0};
	LONG nResult = Ms_Ipc_GetSystemDate(m_nUserID, &dateTime);
	if(nResult)
		return;

	UpdateData(TRUE);
	((CButton*)GetDlgItem(IDC_CHECK_DAYLIGHT))->SetCheck(dateTime.bDaylightSaving);
	m_DT_Date.EnableWindow(FALSE);
	m_DT_Time.EnableWindow(FALSE);
	int nYear = 0, nMonth = 0, nDay = 0, nHour = 0, nMinute = 0, nSecond = 0;
	sscanf(dateTime.sDate, "%d/%d/%d", &nYear, &nMonth, &nDay);
	sscanf(dateTime.sTime, "%d:%d:%d", &nHour, &nMinute, &nSecond);

	if(nYear<1900 || nMonth < 1 || nMonth > 12 || nDay < 1 || nDay > 31){

	}else{
		CTime time(nYear, nMonth, nDay, nHour, nMinute, nSecond);
		m_DT_Date.SetTime(&time);
		m_DT_Time.SetTime(&time);
		m_DateTime = time;
		SetTimer(1001, 1000, NULL); // 时间自动更新
	}
	
	((CButton*)GetDlgItem(IDC_RADIO_DT_MANUAL))->SetCheck(FALSE);
	((CButton*)GetDlgItem(IDC_RADIO_DT_SNTP))->SetCheck(FALSE);
	OnRadioDtSntp();
	((CButton*)GetDlgItem(IDC_RADIO_DT_COMPUTER))->SetCheck(FALSE);

	GetDlgItem(IDC_EDIT_DT_NTP_SERVER)->SetWindowText(dateTime.sNtpServer);
	((CComboBox*)GetDlgItem(IDC_COMBO_DT_TIMEZONE))->SetCurSel(dateTime.nTimeZone);	
	UpdateData(FALSE);

}

void CMsSDKTestDlg::OnRadioDtManual() 
{
	// TODO: Add your control notification handler code here
	m_DT_Date.EnableWindow(TRUE);
	m_DT_Time.EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_DT_NTP_SERVER)->EnableWindow(FALSE);
}

void CMsSDKTestDlg::OnRadioDtSntp() 
{
	// TODO: Add your control notification handler code here
	m_DT_Date.EnableWindow(FALSE);
	m_DT_Time.EnableWindow(FALSE);
	if(((CButton*)GetDlgItem(IDC_RADIO_DT_SNTP))->GetCheck())
		GetDlgItem(IDC_EDIT_DT_NTP_SERVER)->EnableWindow(TRUE);
	else
		GetDlgItem(IDC_EDIT_DT_NTP_SERVER)->EnableWindow(FALSE);
}

void CMsSDKTestDlg::OnRadioDtComputer() 
{
	// TODO: Add your control notification handler code here
	m_DT_Date.EnableWindow(FALSE);
	m_DT_Time.EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_DT_NTP_SERVER)->EnableWindow(FALSE);
}

void CMsSDKTestDlg::OnBtnSetDatetime() 
{
	// TODO: Add your control notification handler code here
	char sValue[32] = {0};
	Ms_Ipc_SystemDate dateTime = {0};
	dateTime.nTimeZone = ((CComboBox*)GetDlgItem(IDC_COMBO_DT_TIMEZONE))->GetCurSel();
	dateTime.nType = (BYTE)3;
	if(GetCheckedRadioButton(IDC_RADIO_DT_MANUAL, IDC_RADIO_DT_COMPUTER) == IDC_RADIO_DT_SNTP)
		dateTime.nType = (BYTE)1;
	else if(GetCheckedRadioButton(IDC_RADIO_DT_MANUAL, IDC_RADIO_DT_COMPUTER) == IDC_RADIO_DT_COMPUTER)
		dateTime.nType = (BYTE)2;
	else if(GetCheckedRadioButton(IDC_RADIO_DT_MANUAL, IDC_RADIO_DT_COMPUTER) == IDC_RADIO_DT_MANUAL)
		dateTime.nType = (BYTE)0;
	GetDlgItem(IDC_EDIT_DT_NTP_SERVER)->GetWindowText(dateTime.sNtpServer, sizeof(dateTime.sNtpServer));
	if(dateTime.nType == 1 && dateTime.sNtpServer[0] == '\0')
	{
		AfxMessageBox("SNTP Server can't be empty.");
		return;
	}

	if(dateTime.nType == 2) // COMPUTER
	{
		struct tm * pt;
		time_t now;
		now = time(NULL);
		pt = localtime(&now);
		_snprintf(dateTime.sDate, sizeof(dateTime.sDate)-1, "%04d/%02d/%02d", pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday);
		_snprintf(dateTime.sTime, sizeof(dateTime.sTime)-1, "%02d:%02d:%02d", pt->tm_hour, pt->tm_min, pt->tm_sec);
		
		CTime time(pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday, pt->tm_hour, pt->tm_min, pt->tm_sec);
		m_DT_Date.SetTime(&time);
		m_DT_Time.SetTime(&time);
	}else{
		m_DT_Date.GetWindowText(dateTime.sDate, sizeof(dateTime.sDate));
		m_DT_Time.GetWindowText(dateTime.sTime, sizeof(dateTime.sTime));
	}
	int nYear = 0, nMonth = 0, nDay = 0, nHour = 0, nMinute = 0, nSecond = 0;
	sscanf(dateTime.sDate, "%d/%d/%d", &nYear, &nMonth, &nDay);
	sscanf(dateTime.sTime, "%d:%d:%d", &nHour, &nMinute, &nSecond);
	CTime time(nYear, nMonth, nDay, nHour, nMinute, nSecond);
	m_DateTime = time;

	dateTime.bDaylightSaving = (BYTE)((CButton*)GetDlgItem(IDC_CHECK_DAYLIGHT))->GetCheck();
	((CButton*)GetDlgItem(IDC_RADIO_DT_MANUAL))->SetCheck(FALSE);
	((CButton*)GetDlgItem(IDC_RADIO_DT_SNTP))->SetCheck(FALSE);
	((CButton*)GetDlgItem(IDC_RADIO_DT_COMPUTER))->SetCheck(FALSE);
	m_DT_Date.EnableWindow(FALSE);
	m_DT_Time.EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_DT_NTP_SERVER)->EnableWindow(FALSE);
	
	LONG nResult = Ms_Ipc_SetSystemDate(m_nUserID, &dateTime);
	if(nResult)
		OutputTips("Set date & time failed.");
	else
		OutputTips("Set date & time Successfully.");
}

void CMsSDKTestDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == 1001)
	{
		if(((CButton*)GetDlgItem(IDC_RADIO_DT_MANUAL))->GetCheck())
		{
			m_DateTime += 1;
		}else{
			m_DateTime += 1;
			if(!m_bFullClient){
				m_DT_Date.SetTime(&m_DateTime);
				m_DT_Time.SetTime(&m_DateTime);
			}
		}
	}
	CDialog::OnTimer(nIDEvent);
}

/*void CMsSDKTestDlg::OnBtnTest() 
{
	LONG nResult = -1;
	Ms_Ipc_MotionConfig motionConfig = {0};
	motionConfig.nMotionBlock[0] = 10;
	motionConfig.nMotionBlock[1] = 15;
	motionConfig.nMotionBlock[2] = 15;
	Ms_Ipc_SetMotionConifg(m_nUserID, &motionConfig);
}*/

void CALLBACK LivePlayCallBack(LONG nLiveHandle, DWORD dwDataType, void *pBuffer, DWORD dwBuffSize, int nWidth, int nHeight, void *pUser)
{
	CMsSDKTestDlg *pTestDlg = (CMsSDKTestDlg*)pUser;
	pTestDlg->m_bPlay = TRUE;
	if(dwDataType == IPC_DATA_TYPE_VIDEO){
		//OutputDebugString("Video Data\n");
	}else if(dwDataType == IPC_DATA_TYPE_AUDIO){
		//OutputDebugString("Audio Data\n");
	}
}

void CMsSDKTestDlg::OnBtnPlay() 
{
	//////////////////////////////////////
	//				For Test			//
	//////////////////////////////////////
	Test();
	//////////////////////////////////////
	//				End Test			//
	//////////////////////////////////////

	Ms_Ipc_ClientInfo clientInfo = {0};
	clientInfo.nProtocol = IPC_RTSP_PROTOCOL_UDP;
	clientInfo.hPlayWnd = m_wndLivePlay.m_hWnd;
	clientInfo.nDisplayStream = IPC_STREAM_TYPE_MAIN;
	
	int nCurConnNum = 0;
	int nMaxConnNum = 0;
	Ms_IpcClient_GetMaxConnectionLimit(m_nUserID, &nMaxConnNum);
	Ms_IpcClient_GetCurrentConnectionNum(m_nUserID, &nCurConnNum);
	if(!m_bPlay && nMaxConnNum != 0 && nCurConnNum >= nMaxConnNum){
		OutputTips("Connections already exceed the limit. Please try again later.");
		return;
	}

	LONG nResult = Ms_IpcClient_LivePlay(m_nUserID, &clientInfo, LivePlayCallBack, this);
	if(nResult){
		OutputTips("Live Play Failed.");
		m_bPlay = FALSE;
	}else{
		if(!m_bPlay)
			OutputTips("Live Play Successfully.");
		m_bPlay = TRUE;
		OnChkShowGrid();
	}
}

void CMsSDKTestDlg::OnStaticLive() 
{
	// TODO: Add your control notification handler code here
	if(!m_bPlay)
		return;
	CRect rcClient;
	if(!m_bFullClient){	
		m_wndLivePlay.GetWindowRect(&m_rcStatic);
		ScreenToClient(&m_rcStatic);

		GetClientRect(&rcClient);
		m_wndLivePlay.MoveWindow(rcClient);
		//UpdateData(FALSE);
	}else{
		m_wndLivePlay.MoveWindow(m_rcStatic);
		Invalidate();
		//UpdateData(FALSE);
	}
	m_bFullClient = !m_bFullClient;
//	OnBtnStop();
	OnBtnPlay();
}


void CMsSDKTestDlg::OnChkShowGrid() 
{
	BYTE motionMap[32][24] = {0};
	UpdateData(TRUE);
	if(((CButton*)GetDlgItem(IDC_CHK_SHOW_GRID))->GetCheck()){
		//memset(motionMap, 1, sizeof(BYTE)*32*24);
//		memset(motionMap[15], 1, sizeof(BYTE)*24);
		Ms_IpcClient_DrawGrid(m_nUserID, TRUE, motionMap);	
	}else{
		Ms_IpcClient_DrawGrid(m_nUserID, FALSE, motionMap);	
	}
}

void CMsSDKTestDlg::OnBtnStop() 
{
	if(m_bRecord)
		OnBtnRecord();
	Ms_IpcClient_StopLivePlay(m_nUserID);
	m_wndLivePlay.Invalidate(TRUE);
	m_bPlay = FALSE;
	OutputTips("Stop Play Successfully.");
}

void __stdcall SearchCallBack(Ms_Ipc_Device *pDevice, void *pUser)
{
	CString strText;
	char sBuffer[1024] = {0};
	_snprintf(sBuffer, sizeof(sBuffer)-1, "%s:%d\r\nMAC:%s\r\nName:%s\r\nModel:%s\r\n\r\n", 
		pDevice->sIP, pDevice->nPort, pDevice->sMacAddr, pDevice->sName, pDevice->sModel);
	CMsSDKTestDlg *pTestDlg = (CMsSDKTestDlg*)pUser;
	pTestDlg->GetDlgItem(IDC_EDIT_SEARCH)->GetWindowText(strText);
	strText += sBuffer;
	pTestDlg->GetDlgItem(IDC_EDIT_SEARCH)->SetWindowText(strText);
	//OutputDebugString(sBuffer);
	CEdit *pEdit = (CEdit*)pTestDlg->GetDlgItem(IDC_EDIT_SEARCH);
	pEdit->LineScroll(pEdit->GetLineCount(), 0);
}

void CMsSDKTestDlg::OnBtnSearch() 
{
	OnBtnClearText();
	Ms_Sdk_SearchIpc(&SearchCallBack, this);
}

void CMsSDKTestDlg::OnBtnClearText() 
{
	GetDlgItem(IDC_EDIT_SEARCH)->SetWindowText("");
}

void CMsSDKTestDlg::OnBtnPlayback() 
{
	char sDiskPath[MAX_PATH] = {0};
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DISK);
	pComboBox->GetLBText(pComboBox->GetCurSel(), sDiskPath);

	CDlgPlayBack playBackDlg(this);
	playBackDlg.m_nUserId = m_nUserID;
	_snprintf(playBackDlg.m_sDiskPath, sizeof(playBackDlg.m_sDiskPath)-1, "%s", sDiskPath);
	playBackDlg.DoModal();
}

void CMsSDKTestDlg::OnBtnCaptureImage() 
{
	char sFilePath[MAX_PATH] = {0};
	char sDiskPath[MAX_PATH] = {0};
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DISK);
	pComboBox->GetLBText(pComboBox->GetCurSel(), sDiskPath);
	if(!Ms_IpcClient_CaptureImage(m_nUserID, sFilePath, sizeof(sFilePath), sDiskPath)){
		OutputDebugString(sFilePath);
		OutputTips("Capture Image:%s.", sFilePath);
		Sleep(1000);
		ShellExecute(NULL, "open", sFilePath, NULL, NULL, SW_SHOWNORMAL);
	}
	else{
//		OutputTips("Capture image failed. Ensure that live play successfully...");
	}
}

void CMsSDKTestDlg::OnBtnRecord() 
{
	if(!m_bPlay)
		return;
	char sDiskPath[MAX_PATH] = {0};
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DISK);
	pComboBox->GetLBText(pComboBox->GetCurSel(), sDiskPath);
	if(!m_bRecord){
		Ms_IpcClient_SaveLiveData(m_nUserID, sDiskPath);
		GetDlgItem(IDC_BTN_RECORD)->SetWindowText("Stop Record");
		OutputTips("Start recording.");
	}else{
		Ms_IpcClient_StopSaveLiveData(m_nUserID);
		GetDlgItem(IDC_BTN_RECORD)->SetWindowText("Start Record");
		OutputTips("Stop recording.");
	}
	m_bRecord = !m_bRecord;
	UpdateData(FALSE);
}

void CMsSDKTestDlg::OnBtnGetRtspUtl() 
{
	// TODO: Add your control notification handler code here
	char sUrl[256] = {0};
	CComboBox *pCbStreamType = (CComboBox*)GetDlgItem(IDC_COMBO_STREAM_TYPE);
	int nIndex = pCbStreamType->GetCurSel();
	if(nIndex == 0)
		nIndex = IPC_STREAM_TYPE_MAIN;
	else
		nIndex = IPC_STREAM_TYPE_SUB;
	Ms_IpcClient_GetRtspUrl(m_nUserID, nIndex, sUrl, sizeof(sUrl));
	GetDlgItem(IDC_EDIT_RTSP_URL)->SetWindowText(sUrl);
}

void CMsSDKTestDlg::OnBtnSelectFile() 
{
	CFileDialog fileDlg(TRUE);
	if(fileDlg.DoModal() == IDOK){
		CFile file(fileDlg.GetPathName(), CFile::modeRead);
		int fileSize = (int)file.GetLength();

		if(fileSize <= 0 || fileSize > 1024*1024*100){//100M
			AfxMessageBox("The upload file size must comply with the requirements.");
			return;
		}

		GetDlgItem(IDC_EDIT_FIREWARE_PATH)->SetWindowText(fileDlg.GetPathName());
	}	
}

void CMsSDKTestDlg::OnBtnUpdateFirmware() 
{
	char sFilePath[MAX_PATH] = {0};
	GetDlgItem(IDC_EDIT_FIREWARE_PATH)->GetWindowText(sFilePath, sizeof(sFilePath));
	if(sFilePath[0] == '\0')
		return;
	if(!Ms_Ipc_UpdateFirmware(m_nUserID, sFilePath))
		AfxMessageBox("Update Firmware Successfully.");
	else
		AfxMessageBox("Update Firmware Failed.");
}

void CMsSDKTestDlg::OnBtnUserSetting() 
{
	// TODO: Add your control notification handler code here
	CDlgUserSettings dlgUser(this);
	dlgUser.m_nUserId = m_nUserID;
	dlgUser.DoModal();
}

void CMsSDKTestDlg::OnBtnPtz() 
{
	// TODO: Add your control notification handler code here
	CDlgPtz dlgPtz(this);
	dlgPtz.m_nUserId = m_nUserID;
	dlgPtz.DoModal();
}

void CMsSDKTestDlg::OnBtnVideoConfig() 
{
	// TODO: Add your control notification handler code here
	CDlgVideoConfig dlgVideoConfig(this);
	dlgVideoConfig.m_nUserId = m_nUserID;
	dlgVideoConfig.DoModal();
}

void CMsSDKTestDlg::OnBtnAudioConfig() 
{
	// TODO: Add your control notification handler code here
	CDlgAudioConfig dlgAudioConfig(this);
	dlgAudioConfig.m_nUserId = m_nUserID;
	dlgAudioConfig.DoModal();
}

void CMsSDKTestDlg::OnBtnSdConfig() 
{
	// TODO: Add your control notification handler code here
	Ms_Ipc_SdCard sdCard = {0};
	char sTips[512] = {0};
	if(Ms_Ipc_GetSdCardInfo(m_nUserID, &sdCard))
	{
		OutputTips("GetSdcard info failed. Please try again...");
		return;
	}
	if(sdCard.nSdStatus == 0)
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "Sd Status:%d", sdCard.nSdStatus/*, "no sdcard"*/);
	else if(sdCard.nSdStatus == 1)
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "Sd Status:%d", sdCard.nSdStatus/*, "unmount"*/);
	else if(sdCard.nSdStatus == 3)
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "Sd Status:%d", sdCard.nSdStatus/*, "mounted"*/);
	else
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "Sd Status:%d", sdCard.nSdStatus);

	int nGBytes = 0, nMBytes = 0, nKBytes = 0;
	int nUsedSpace = sdCard.dwSdVolume-sdCard.dwSdFreeSpace;
	if(sdCard.nSdStatus == 3 && sdCard.dwSdVolume > 0)
	{
		nGBytes = sdCard.dwSdVolume/(1024*1024);
		nMBytes = sdCard.dwSdVolume/1024 - nGBytes*1024;
		nKBytes = sdCard.dwSdVolume%1024;
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "  Total:", 0);
		if(nGBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "%dGB", nGBytes);
		if(nMBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, " %dMB", nMBytes);
		if(nKBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, " %dKB", nKBytes);
	}
	else
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, " Total:%dKB", 0);

	if(sdCard.nSdStatus == 3 && sdCard.dwSdFreeSpace > 0)
	{
		nGBytes = sdCard.dwSdFreeSpace/(1024*1024);
		nMBytes = sdCard.dwSdFreeSpace/1024 - nGBytes*1024;
		nKBytes = sdCard.dwSdFreeSpace%1024;
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "  Free:", 0);
		if(nGBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "%dGB", nGBytes);
		if(nMBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, " %dMB", nMBytes);
		if(nKBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, " %dKB", nKBytes);
	}
	else
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "  Free:%dKB", 0);

	if(sdCard.nSdStatus == 3 && nUsedSpace > 0)
	{
		nGBytes = nUsedSpace/(1024*1024);
		nMBytes = nUsedSpace/1024 - nGBytes*1024;
		nKBytes = nUsedSpace%1024;
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "  Used:", 0);
		if(nGBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "%dGB", nGBytes);
		if(nMBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, " %dMB", nMBytes);
		if(nKBytes > 0)
			_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, " %dKB", nKBytes);
	}
	else
		_snprintf(sTips+strlen(sTips), sizeof(sTips)-strlen(sTips)-1, "  Used:%dKB", 0);

	OutputTips("%s", sTips);
}

void CMsSDKTestDlg::OnBtnPrivacyMask() 
{
	// TODO: Add your control notification handler code here
	CDlgMask dlgMask(this);
	dlgMask.m_nUserId = m_nUserID;
	dlgMask.DoModal();

	if(m_bPlay){
		OnBtnPlay();
	}
}

void CMsSDKTestDlg::OnBtnAlarmConfig() 
{
	// TODO: Add your control notification handler code here
	CDlgAlarmConfig alarmConfig(this);
	alarmConfig.m_nUserId = m_nUserID;
	alarmConfig.DoModal();
}

void CMsSDKTestDlg::OnBtnCmosConfig() 
{
	// TODO: Add your control notification handler code here
	CDlgCmosConfig dlgCmosConfig(this);
	dlgCmosConfig.m_nUserId = m_nUserID;
	dlgCmosConfig.DoModal();
}

void CMsSDKTestDlg::OnBtnClearOutput() 
{
	// TODO: Add your control notification handler code here
	CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT_OUTPUT);
	pEdit->SetWindowText("");
	UpdateData(FALSE);
}

void CMsSDKTestDlg::OnBtnSmtp() 
{
	// TODO: Add your control notification handler code here
	CDlgSmtp dlgSmtp(this);
	dlgSmtp.m_nUserId = m_nUserID;
	dlgSmtp.DoModal();
}

void CMsSDKTestDlg::OnBtnFtp() 
{
	// TODO: Add your control notification handler code here
	CDlgFtp dlgFtp(this);
	dlgFtp.m_nUserId = m_nUserID;
	dlgFtp.DoModal();
}

void CMsSDKTestDlg::OnBtnDdns() 
{
	// TODO: Add your control notification handler code here
	CDlgDdns dlgDdns(this);
	dlgDdns.m_nUserId = m_nUserID;
	dlgDdns.DoModal();
}

void CMsSDKTestDlg::OnBtnConnectLimit() 
{
	// TODO: Add your control notification handler code here
	CDlgConnectLimit dlgConnect(this);
	dlgConnect.m_nUserId = m_nUserID;
	dlgConnect.DoModal();
}

void CMsSDKTestDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CSliderCtrl *pSlider=(CSliderCtrl*)pScrollBar;
	CSliderCtrl *pSliderB = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_BRIGHTNESS);
	CSliderCtrl *pSliderC = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_CONTRAST);
	CSliderCtrl *pSliderS = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SATURATION);
	CSliderCtrl *pSliderSp = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SHARPNESS);
	CSliderCtrl *pSliderR = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_REDUCTION);
	if (pSlider == pSliderB || pSlider == pSliderC || pSlider == pSliderS || pSlider == pSliderSp || pSlider == pSliderR)
	{
		m_tooltip.Update();//更新tip
	}
	if(m_nUserID < 0){
		CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
		return;
	}
	// TODO: Add your message handler code here and/or call default
	Ms_Ipc_ImagingSettings imgSettings = {0};
	imgSettings.nBrightness = pSliderB->GetPos();
	imgSettings.nContrast = pSliderC->GetPos();
	imgSettings.nSaturation = pSliderS->GetPos();
	imgSettings.nSharpness = pSliderSp->GetPos();
	imgSettings.nFLevel = pSliderR->GetPos();
	
	Ms_Ipc_SetImagingSettings(m_nUserID, &imgSettings);

	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

BOOL CMsSDKTestDlg::OnToolTipNotify(UINT id,NMHDR *pNMHDR,LRESULT *pResult)
{	
    TOOLTIPTEXT   *pTTT   =   (TOOLTIPTEXT*)pNMHDR; 
    UINT   nID   = pNMHDR->idFrom; 
    if (pTTT->uFlags  &  TTF_IDISHWND) 
    { 
        nID  =  ::GetDlgCtrlID((HWND)nID); 
		CString str;
        if(nID == IDC_SLIDER_BRIGHTNESS)//如果现在这个ID是你要显示Tip的控件 
        {   
            str.Format(_T("%d"),((CSliderCtrl*)GetDlgItem(IDC_SLIDER_BRIGHTNESS))->GetPos());
            strcpy(pTTT->lpszText, str);
            return TRUE; 
        }else if(nID == IDC_SLIDER_CONTRAST){
			//CString str;
            str.Format(_T("%d"),((CSliderCtrl*)GetDlgItem(IDC_SLIDER_CONTRAST))->GetPos());
            strcpy(pTTT->lpszText, str);
            return TRUE; 
		}else if( nID == IDC_SLIDER_SATURATION){
			//CString str;
            str.Format(_T("%d"),((CSliderCtrl*)GetDlgItem(IDC_SLIDER_SATURATION))->GetPos());
            strcpy(pTTT->lpszText, str);
            return TRUE; 
		}else if(nID == IDC_SLIDER_SHARPNESS)
        {   
            str.Format(_T("%d"),((CSliderCtrl*)GetDlgItem(IDC_SLIDER_SHARPNESS))->GetPos());
            strcpy(pTTT->lpszText, str);
            return TRUE; 
        }else if(nID == IDC_SLIDER_REDUCTION)
        {   
            str.Format(_T("%d"),((CSliderCtrl*)GetDlgItem(IDC_SLIDER_REDUCTION))->GetPos());
            strcpy(pTTT->lpszText, str);
            return TRUE; 
        }

    }
    return FALSE; 
} 

BOOL CMsSDKTestDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_tooltip.m_hWnd != NULL) 
        m_tooltip.RelayEvent(pMsg);
	if(pMsg->message == WM_KEYDOWN)
		if(int(pMsg->wParam) == VK_ESCAPE || int(pMsg->wParam) == VK_RETURN)
			return TRUE;
	return CDialog::PreTranslateMessage(pMsg);
}

void CMsSDKTestDlg::OnBtnDefaultPara() 
{
	// TODO: Add your control notification handler code here
	CSliderCtrl *pSliderB = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_BRIGHTNESS);
	CSliderCtrl *pSliderC = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_CONTRAST);
	CSliderCtrl *pSliderS = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SATURATION);
	CSliderCtrl *pSliderSp = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SHARPNESS);
	CSliderCtrl *pSliderR = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_REDUCTION);
	Ms_Ipc_ImagingSettings imgSettings = {0};
	pSliderB->SetPos(50);
	pSliderC->SetPos(50);
	pSliderS->SetPos(50);
	pSliderSp->SetPos(50);
	pSliderR->SetPos(50);
	imgSettings.nBrightness = 50;
	imgSettings.nContrast = 50;
	imgSettings.nSaturation = 50;
	imgSettings.nSharpness = 50;
	imgSettings.nFLevel = 50;
	Ms_Ipc_SetImagingSettings(m_nUserID, &imgSettings);
}

void CMsSDKTestDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if(m_bPlay)
	{
		AfxMessageBox("Please stop live play first.");
		return;
	}
	CDialog::OnClose();
}


void CMsSDKTestDlg::OnBtnGetport() 
{
	// TODO: Add your control notification handler code here
	char sValue[32] = {0};
	Ms_Ipc_Port portInfo = {0};
	LONG nResult = Ms_Ipc_GetPortInfo(m_nUserID, &portInfo);
	if(nResult)
		return;
	UpdateData(TRUE);
	_snprintf(sValue, sizeof(sValue)-1, "%d", portInfo.nHttpPort);
	GetDlgItem(IDC_EDIT_HTTP_PORT)->SetWindowText(sValue);
	_snprintf(sValue, sizeof(sValue)-1, "%d", portInfo.nMainRtspPort);
	GetDlgItem(IDC_EDIT_RTSP_PORT)->SetWindowText(sValue);
	UpdateData(FALSE);

}

void CMsSDKTestDlg::OnBtnSetport() 
{
	// TODO: Add your control notification handler code here
	
	char sValue[32] = {0};
	Ms_Ipc_Port portInfo = {0};
	UpdateData(TRUE);
	// avoid empty value
	CString strTemp;
	GetDlgItem(IDC_EDIT_HTTP_PORT)->GetWindowText(strTemp);
	strTemp.TrimLeft();
	strTemp.TrimRight();
	GetDlgItem(IDC_EDIT_HTTP_PORT)->SetWindowText(strTemp);
	GetDlgItem(IDC_EDIT_RTSP_PORT)->GetWindowText(strTemp);
	strTemp.TrimLeft();
	strTemp.TrimRight();
	GetDlgItem(IDC_EDIT_RTSP_PORT)->SetWindowText(strTemp);
	//end

	GetDlgItem(IDC_EDIT_HTTP_PORT)->GetWindowText(sValue, sizeof(sValue));
	portInfo.nHttpPort = atoi(sValue);
	GetDlgItem(IDC_EDIT_RTSP_PORT)->GetWindowText(sValue, sizeof(sValue));
	portInfo.nMainRtspPort = atoi(sValue);
	portInfo.nOnvifPort = portInfo.nHttpPort;
	portInfo.nSubRtspPort = portInfo.nMainRtspPort;
	if(portInfo.nHttpPort < 1 || portInfo.nHttpPort > 65535 || portInfo.nMainRtspPort < 1 || portInfo.nMainRtspPort > 65535)
	{
		OutputTips("Port should between 1 and 65535.");
		return;
	}
	if(portInfo.nHttpPort == portInfo.nMainRtspPort)
	{
		OutputTips("Can't set the same port.");
		return;
	}

	LONG nResult = Ms_Ipc_SetPortInfo(m_nUserID, &portInfo);
	if(nResult){
		OutputTips("Set Port Failed.");
		return;
	}
	OutputTips("Set Port Successfully. Wait for relogin automatically.");
	char sPort[32] = {0};
	GetDlgItem(IDC_EDIT_LOGIN_PORT)->SetWindowText(itoa(portInfo.nHttpPort, sPort, 10));
	
	Sleep(6000);
	char sIP[32] = {0}, sUserName[32] = {0}, sPassword[16] = {0};
	GetDlgItem(IDC_EDIT_LOGIN_IP)->GetWindowText(sIP, sizeof(sIP));
	GetDlgItem(IDC_EDIT_LOGIN_USERNAME)->GetWindowText(sUserName, sizeof(sUserName));
	GetDlgItem(IDC_EDIT_LOGIN_PASSWORD)->GetWindowText(sPassword, sizeof(sPassword));
	m_nUserID = Ms_Ipc_Login(sIP, sIP, portInfo.nHttpPort, sUserName, sPassword, NULL);
	if(m_nUserID == -1){
		AfxMessageBox("Relogin Failed.");
		return;
	}
	OutputTips("Relogin Successfully.");
	CRegOp regObj;
	regObj.WriteReg(HKEY_CURRENT_USER, REG_KEY, REG_SUB_KEY_PORT, sPort, strlen(sPort), REG_SZ);
}

void CMsSDKTestDlg::OnButtonDbgTest() 
{
	// TODO: Add your control notification handler code here
	Ms_Ipc_Alarm alarmInfo = {0};
	Ms_Ipc_MotionConfig AlarmCfg_motion = {0};
	Ms_Ipc_Schedule_Week AlarmCfg_scheWeek = {0};
	alarmInfo.alarmEvent.pMotionConfig = &AlarmCfg_motion;
	alarmInfo.alarmEvent.pScheduleWeek = &AlarmCfg_scheWeek;
	alarmInfo.nAlarmType = IPC_ALARM_EVENT_TYPE_MOTION;
	Ms_Ipc_GetAlarmConfig(m_nUserID, &alarmInfo);
	alarmInfo.nAlarmType = IPC_ALARM_EVENT_TYPE_AUDIO_IN;
	Ms_Ipc_GetAlarmConfig(m_nUserID, &alarmInfo);
	alarmInfo.nAlarmType = IPC_ALARM_EVENT_TYPE_DINPUT;
	Ms_Ipc_GetAlarmConfig(m_nUserID, &alarmInfo);
	alarmInfo.nAlarmType = IPC_ALARM_EVENT_TYPE_TAMPER;
	Ms_Ipc_GetAlarmConfig(m_nUserID, &alarmInfo);
// 	Ms_Ipc_SetAlarmConfig

	Ms_Ipc_MotionConfig motionCfg = {0};
	Ms_Ipc_GetMotionConifg(m_nUserID, &motionCfg);
// 	Ms_Ipc_SetMotionConifg

	Ms_Ipc_Schedule_Week scheWeek = {0};
	scheWeek.nScheduleType = IPC_SCHEDULE_TYPE_MOTION;
	Ms_Ipc_GetSchedule(m_nUserID, &scheWeek);
	scheWeek.nScheduleType = IPC_SCHEDULE_TYPE_AUDIO_IN;
	Ms_Ipc_GetSchedule(m_nUserID, &scheWeek);
	scheWeek.nScheduleType = IPC_SCHEDULE_TYPE_DI;
	Ms_Ipc_GetSchedule(m_nUserID, &scheWeek);
	scheWeek.nScheduleType = IPC_SCHEDULE_TYPE_PIR;
	Ms_Ipc_GetSchedule(m_nUserID, &scheWeek);
//	Ms_Ipc_SetSchedule
}

void CMsSDKTestDlg::Test() 
{
//	Ms_Ipc_Schedule_Week schWeek = {0};
//	schWeek.nScheduleType = SCHEDULE_TYPE_MOTION;
//	schWeek.schedule[0].bEnable = 1;
//	schWeek.schedule[0].nWeekDay = 7;
//	schWeek.schedule[0].tStart[0].nHour = 5;
//	schWeek.schedule[0].tStart[0].nMinute = 30;
//	schWeek.schedule[0].tStop[0].nHour= 8;
//	schWeek.schedule[0].tStop[0].nMinute = 40;
//	schWeek.schedule[0].tStart[1].nHour = 9;
//	schWeek.schedule[0].tStart[1].nMinute = 00;
//	schWeek.schedule[0].tStop[1].nHour= 11;
//	schWeek.schedule[0].tStop[1].nMinute = 20;
//	Ms_Ipc_SetSchedule(m_nUserID, &schWeek);

// 	Ms_Ipc_Record_Config recordConfig = {0};
// 	Ms_Ipc_GetRecordConfig(m_nUserID, &recordConfig);
// 	recordConfig.nStorageType = IPC_RECORD_TYPE_SD;
// 	recordConfig.nSdFileSize = 222;
// 	recordConfig.nSdFrameType = 1;
// 	Ms_Ipc_SetRecordConfig(m_nUserID, &recordConfig);
// 	recordConfig.nStorageType = IPC_RECORD_TYPE_NAS;
// 	recordConfig.nNasFileSize = 22;
// 	recordConfig.nNasFrameType = 0;
// 	Ms_Ipc_SetRecordConfig(m_nUserID, &recordConfig);

// 	Ms_Ipc_DDNS ddns = {0};
// 	Ms_Ipc_GetDDNS(m_nUserID, &ddns);

// 	Ms_Ipc_VideoConfig video = {0};
// 	video.nStreamIndex = IPC_STREAM_TYPE_THIRD;
// 	Ms_Ipc_GetVideoConfig(m_nUserID, &video);
}
