// FirmwareUpdate.cpp : 实现文件
//

#include "stdafx.h"
#include "NetSDKDemo.h"
#include "DevConfig.h"
#include "NetSDKDll.h"
#include "NetSDKDemoDlg.h"
#include "SetTime.h"

// CDevConfig 对话框
 #define GET_USER_DATA 1033
 #define SET_USER_DATA 1034

ConfigCMD g_strCMD[] = 
{
	{CMD_GET_SYSTEM_PTZ_CONFIG, CMD_SET_SYSTEM_PTZ_COMMON, _T("云台基本配置")},
	{CMD_GET_SYSTEM_PTZ_CONFIG, CMD_SET_SYSTEM_PTZ_ADVANCE, _T("云台高级配置")},
	{CMD_GET_SYSTEM_USER_CONFIG, CMD_SET_SYSTEM_USER_CONFIG, _T("用户列表")},
	{CMD_GET_SYSTEM_LOG_CONFIG, CMD_SET_SYSTEM_LOG_CONFIG, _T("日志输出配置")},
	{CMD_GET_SYSTEM_MISC_CONFIG, CMD_SET_SYSTEM_MISC_CONFIG, _T("默认语言")},
	{CMD_GET_NETWORK_LAN_CONFIG, CMD_SET_NETWORK_LAN_CONFIG, _T("以太网配置")},
	{CMD_GET_NETWORK_WIFI_CONFIG, CMD_SET_NETWORK_WIFI_CONFIG,  _T("WIFI配置")},
	{CMD_GET_NETWORK_ADSL_CONFIG, CMD_SET_NETWORK_ADSL_CONFIG, _T("ADSL拔号配置")},
	{CMD_GET_NETWORK_DDNS_CONFIG, CMD_SET_NETWORK_DDNS_CONFIG, _T("DDNS配置")},
	{CMD_GET_NETWORK_UPNP_CONFIG, CMD_SET_NETWORK_UPNP_CONFIG, _T("UPNP配置")},
	{CMD_GET_NETWORK_3G_CONFIG, CMD_SET_NETWORK_3G_CONFIG, _T("3G配置")},
	{CMD_SERVER_CONFIG_BASE, CMD_SET_SERVER_CONFIG, _T("FTP&SMTP相关配置")},
	{CMD_GET_SERVER_FTP_CONFIG, CMD_SET_SERVER_FTP_CONFIG, _T("FTP配置")},
	{CMD_GET_SERVER_SMTP_CONFIG, CMD_SET_SERVER_SMTP_CONFIG, _T("SMTP配置")},
	{CMD_MEDIA_CONFIG_BASE, CMD_SET_MEDIA_CONFIG,_T("媒体配置参数")},

	{CMD_GET_MEDIA_VIDEO_CONFIG, CMD_SET_MEDIA_VIDEO_CONFIG, _T("视频参数配置")},
	{CMD_GET_MEDIA_AUDIO_CONFIG, CMD_SET_MEDIA_AUDIO_CONFIG, _T("音频参数配置")},
	{CMD_GET_MEDIA_VIDEO_CONFIG, CMD_SET_MEDIA_VIDEO_ENCODE, _T("视频编码配置")},
	{CMD_GET_MEDIA_VIDEO_CONFIG, CMD_SET_MEDIA_VIDEO_CAPTURE, _T("视频采集配置")},
	{CMD_GET_MEDIA_VIDEO_CONFIG, CMD_SET_MEDIA_VIDEO_OSD, _T("时间标题参数配置")},

	{CMD_GET_MEDIA_VIDEO_CONFIG, CMD_SET_PRIVACY_CONFIG, _T("修改隐私遮挡")},

	
	{CMD_MEDIASTREAM_CONFIG_BASE,CMD_SET_MEDIASTREAM_CONFIG, _T("流媒体参数")},
	{CMD_RECORD_CONFIG_BASE, CMD_SET_RECORD_CONFIG, _T("存储设置参数")},
	{CMD_ALARM_CONFIG_BASE, CMD_SET_ALARM_CONFIG, _T("告警设置参数")},
	{CMD_GET_ALARM_INPUT_CONFIG, CMD_SET_ALARM_INPUT_CONFIG, _T("IO输入告警参数")},
	{CMD_GET_ALARM_MOTIONDETECT_CONFIG,CMD_SET_ALARM_MOTIONDETECT_CONFIG, _T("移动侦测告警参数")},
	{CMD_GET_ALARM_VIDEOCOVER_CONFIG, CMD_SET_ALARM_VIDEOCOVER_CONFIG, _T("视频遮档告警参数")},
	{CMD_GET_ALARM_VIDEOLOST_CONFIG, CMD_SET_ALARM_VIDEOLOST_CONFIG, _T("视频丢失告警参数")},
	{CMD_GET_ALARM_SF_CONFIG, CMD_SET_ALARM_SF_CONFIG, _T("存储告警参数")},
	{CMD_GET_SYSTEM_TIME_CONFIG, CMD_SET_SYSTEM_TIME_CONFIG, _T("时间同步配置")},
	{GET_USER_DATA, SET_USER_DATA, _T("用户数据")},
};

//const int g_iCmdCount = 29;
const int g_iCmdCount = sizeof(g_strCMD) / sizeof(g_strCMD[0]);

#if 0
struct ConfigCMD 
{
	int iCmdID;
	CString strCmdDescribe;
};

const int g_iCmdCount = 33;
ConfigCMD g_strCMD[g_iCmdCount] = 
{
	{CMD_SYSTEM_CONFIG_BASE, _T("读取系统配置XML")},
	{CMD_GET_SYSTEM_PTZ_CONFIG, _T("获取云台配置")},
 	{CMD_GET_SYSTEM_USER_CONFIG, _T("读取用户列表")},
 	{CMD_GET_SYSTEM_LOG_CONFIG, _T("读取设备日志输出配置")},
 	{CMD_GET_SYSTEM_MISC_CONFIG, _T("读取设备默认语言")},
 	{CMD_NETWORK_CONFIG_BASE, _T("读取网络配置")},
 	{CMD_GET_NETWORK_LAN_CONFIG, _T("读取以太网配置")},
 	{CMD_GET_NETWORK_WIFI_CONFIG, _T("读取WIFI配置")},
 	{CMD_GET_NETWORK_ADSL_CONFIG, _T("读取ADSL拔号配置")},
 	{CMD_GET_NETWORK_DDNS_CONFIG, _T("读取DDNS配置")},
 	{CMD_GET_NETWORK_UPNP_CONFIG, _T("读取UPNP配置")},
 	{CMD_GET_NETWORK_G3_CONFIG, _T("读取3G配置")},
 	{CMD_SERVER_CONFIG_BASE, _T("读取FTP&SMTP相关配置")},
 	{CMD_GET_SERVER_FTP_CONFIG, _T("读取FTP配置")},
 	{CMD_GET_SERVER_SMTP_CONFIG, _T("读取SMTP配置")},
	{CMD_MEDIA_CONFIG_BASE, _T("读取媒体配置参数")},
 	{CMD_GET_MEDIA_VIDEO_CONFIG, _T("读取视频参数配置")},
 	{CMD_GET_MEDIA_AUDIO_CONFIG, _T("读取音频参数配置")},
 	{CMD_MEDIASTREAM_CONFIG_BASE, _T("读取流媒体参数")},
 	{CMD_RECORD_CONFIG_BASE, _T("读取存储设置参数")},
 	{CMD_ALARM_CONFIG_BASE, _T("读告警设置参数")},
 	{CMD_GET_ALARM_INPUT_CONFIG, _T("读取IO输入告警参数")},
 	{CMD_GET_ALARM_MOTIONDETECT_CONFIG, _T("读取移动侦测告警参数")},
 	{CMD_GET_ALARM_VIDEOCOVER_CONFIG, _T("读取视频遮档告警参数")},
 	{CMD_GET_ALARM_VIDEOLOST_CONFIG, _T("读取视频丢失告警参数")},
 	{CMD_GET_ALARM_SF_CONFIG, _T("读取存储告警参数")},
 	{CMD_GET_SYSTEM_VERSION_INFO, _T("读取版本信息")},
	{CMD_GET_SYSTEMCONTROLSTRING, _T("取得系统能力集")},
	{CMD_GET_SYSTEM_TIME_CONFIG, _T("读取时间同步配置")},
	{CMD_SET_SYSTEM_TIME_CONFIG, _T("修改时间同步方式")},
	{GET_USER_DATA, _T("读取用户数据")},
	{SET_USER_DATA, _T("设置用户数据")},
	{-1, NULL}
};

#endif

IMPLEMENT_DYNAMIC(CDevConfig, CDialog)

CDevConfig::CDevConfig(CRect rcWnd, CWnd* pParent /*=NULL*/)
	: CDialog(CDevConfig::IDD, pParent)
	,m_rcClient(0, 0, rcWnd.Width(), rcWnd.Height())
	, m_strIP(_T(""))
{
	m_iCurAction = 0;
	m_iCurUserID = 0;
}

CDevConfig::~CDevConfig()
{
	DestroyWindow();
}

void CDevConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_GROUP, m_ctlGroup);
	DDX_Control(pDX, IDC_ED_CONFIGTEXT, m_ctlEDConfig);
	DDX_Control(pDX, IDC_CB_CFG_CMD, m_ctlCBCfgCmd);
	DDX_Control(pDX, IDC_STATIC_IPPPP, m_ctlIP);
	DDX_Text(pDX, IDC_STATIC_IPPPP, m_strIP);
}


BEGIN_MESSAGE_MAP(CDevConfig, CDialog)
	ON_BN_CLICKED(IDC_BTN_GET, &CDevConfig::OnBnClickedBtnGet)
	ON_BN_CLICKED(IDC_BTN_SET, &CDevConfig::OnBnClickedBtnSet)
	ON_CBN_SELCHANGE(IDC_CB_CFG_CMD, &CDevConfig::OnCbnSelchangeCbCfgCmd)
	ON_MESSAGE(WM_DEV_AUX, &CDevConfig::OnDevAux)
END_MESSAGE_MAP()


// CDevConfig 消息处理程序

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

	// TODO:  在此添加额外的初始化
	m_ctlGroup.MoveWindow(CRect(m_rcClient.left+2, m_rcClient.top,m_rcClient.Width()-2, m_rcClient.Height()-2));
	
	m_ctlEDConfig.MoveWindow(CRect(m_rcClient.left+2, m_rcClient.top+15, m_rcClient.Width()-4, m_rcClient.Height()-100));
	
	int iMaxLen = 0;
	CDC *pDC= GetDC();
	m_ctlCBCfgCmd.ResetContent();
	for (int i=0;i<g_iCmdCount; i++)
	{
		
		m_ctlCBCfgCmd.InsertString(i, g_strCMD[i].strCmdDescribe);
		CSize szText = pDC->GetTextExtent(g_strCMD[i].strCmdDescribe);
		iMaxLen = max(iMaxLen, szText.cx);
		
	}
	m_ctlCBCfgCmd.SetDroppedWidth(iMaxLen);
	ReleaseDC(pDC);
	pDC = NULL;

	m_ctlCBCfgCmd.SetCurSel(0);

	m_ctlIP.SetWindowText("");

	//GetDlgItem(IDC_BTN_GET)->ShowWindow(SW_HIDE);
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CDevConfig::OnBnClickedBtnGet()
{
	// TODO: 在此添加控件通知处理程序代码
	OnCbnSelchangeCbCfgCmd();
#if 0
	m_ctlEDConfig.SetWindowText(_T(""));
	CString strKey;
	//m_ctlIP.GetWindowText(strKey);

	int iSel = m_ctlCBCfgCmd.GetCurSel();
	
	int iUserID = 0;

	CTreeCtrl* devTree = &((CNetSDKDemoDlg *)theApp.m_pMainWnd)->m_pWndDevList->m_ctlDevList;
	HTREEITEM selectItem = devTree->GetSelectedItem();
	if (devTree->ItemHasChildren(selectItem))
	{
		return;
	}

	strKey = devTree->GetItemText(selectItem);
	if (-1 != strKey.Find("Stream"))
	{
		HTREEITEM parent = devTree->GetParentItem(selectItem);
		CString csTxtParent = devTree->GetItemText(parent);
		csTxtParent += ':';
		csTxtParent += strKey;

		strKey = csTxtParent;
	}

	
	CDevInfo *pDevInfo = NULL;
	CMapAutoLock Lock;
	BOOL bFound = theApp.m_DevList.Lookup(strKey, pDevInfo);	
	if (bFound)
	{
		iUserID = pDevInfo->iUserID;
	}
		
	if (iUserID != 0)
	{
		m_iCurAction = g_strCMD[iSel].iCmdID;
		m_iCurUserID = iUserID;
		if (g_strCMD[iSel].iCmdID == GET_USER_DATA)
		{
			int maxcount=102400;
			char buffer[102400];
			IP_NET_DVR_GetUserData(iUserID, buffer, &maxcount);
			m_ctlEDConfig.Clear();
			m_ctlEDConfig.SetWindowText(buffer);
			TRACE("IP_NET_DVR_GetUserData buffer = %s\n", buffer);
		}
		else
		{
			int iRet = IP_NET_DVR_GetDVRConfig(iUserID, g_strCMD[iSel].iCmdID, 0, NULL, 0, 0);

			if (iRet == ERR_NOT_FIND_DEVICE)
			{
				AfxMessageBox("句柄错误");
				return ;
			}

			else if (iRet == ERR_DEV_NOT_CONNECTED)
			{
				AfxMessageBox("设备未连接");
				return ;
			}

			else if (iRet == ERR_DEV_NOT_LOGIN)
			{
				AfxMessageBox("设备未登录成功");
				return ;
			}

			else if (iRet == ERR_OUTOFF_MEMORY)
			{
				AfxMessageBox("内存不足");
				return ;
			}
		}

		
	}
	else
	{
		AfxMessageBox("指定设备未登录!!!");
	}
#endif

}

void CDevConfig::OnBnClickedBtnSet()
{
	// TODO: 在此添加控件通知处理程序代码

	CString strXML;
	m_ctlEDConfig.GetWindowText(strXML);
	
	CString strKey;
	m_ctlIP.GetWindowText(strKey);

	int iSel = m_ctlCBCfgCmd.GetCurSel();
	if (iSel < 0 || iSel >= g_iCmdCount)
	{
		return;
	}

	int iUserID = 0;
		
	CDevInfo *pDevInfo = NULL;
	{
		CMapAutoLock Lock;
		theApp.m_DevList.Lookup(strKey, pDevInfo);
		if (NULL == pDevInfo)
		{
			return;
		}
	}
	
	iUserID = pDevInfo->iUserID;

	if (iUserID != 0)
	{
		m_iCurAction = g_strCMD[iSel].iSetCMD;
		m_iCurUserID = iUserID;
		if (g_strCMD[iSel].iSetCMD == SET_USER_DATA)
		{
			IP_NET_DVR_SetUserData(iUserID, strXML.GetBuffer(), strXML.GetLength());
		}
		else
		{

			CString strTmp;
			BOOL isManual = FALSE;


			//修改时间同步方式
			if (CMD_SET_SYSTEM_TIME_CONFIG == g_strCMD[iSel].iSetCMD && 
				strXML.Find("TimeMode=\"NTP\"") < 0 && strXML.Find("TimeMode=\"MANUAL\"") >= 0)
			{
				SYSTEMTIME time = {0};
				GetLocalTime(&time);
				strTmp.Format("<REQUEST_PARAM\r\nTime=\"%04d%02d%02d %02d:%02d:%02d\"\r\nTimeZone=\"4800\"\n/>", time.wYear, 
								time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
				CSetTime dlg(strTmp);
				if (IDOK == dlg.DoModal())
				{
					isManual = TRUE;
				}
			}


			int iRet = IP_NET_DVR_SetDVRConfig(iUserID, g_strCMD[iSel].iSetCMD, 0, strXML.GetBuffer(), strXML.GetLength());

			if (iRet != 0)
			{
				AfxMessageBox("设置失败");
				return;
			}

			if (isManual)
			{
				long lRet = IP_NET_DVR_SystemControl(iUserID, CMD_SET_SYSTEM_TIME, 0, strTmp.GetBuffer());
			}

			//所有针对网络配置的修改，都需要发送CMD_CONFIG_NETWORK命令后才能生效。
			if (CMD_SET_NETWORK_LAN_CONFIG == g_strCMD[iSel].iSetCMD  ||
				CMD_SET_NETWORK_WIFI_CONFIG == g_strCMD[iSel].iSetCMD ||
				CMD_SET_NETWORK_ADSL_CONFIG == g_strCMD[iSel].iSetCMD ||
				CMD_SET_NETWORK_DDNS_CONFIG == g_strCMD[iSel].iSetCMD ||
				CMD_SET_NETWORK_UPNP_CONFIG == g_strCMD[iSel].iSetCMD ||
				CMD_SET_NETWORK_3G_CONFIG == g_strCMD[iSel].iSetCMD   ||
				CMD_SET_SERVER_CONFIG == g_strCMD[iSel].iSetCMD       ||
				CMD_SET_SERVER_FTP_CONFIG == g_strCMD[iSel].iSetCMD   ||
				CMD_SET_SERVER_SMTP_CONFIG == g_strCMD[iSel].iSetCMD )
			{
				long lRet = IP_NET_DVR_SystemControl(iUserID, CMD_CONFIG_NETWORK, 0, strTmp.GetBuffer());
			}

		}
		
	}

}

void CDevConfig::SetSelIP(CString &strIP)
{
	m_ctlIP.SetWindowText(strIP);
}

BOOL CDevConfig::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类

	if (pMsg->message == WM_KEYDOWN)
	{
		if(pMsg->wParam == 13)
			return TRUE;
 		if (pMsg->wParam == 27)
		{
			::PostMessage(GetParent()->m_hWnd, WM_KEYDOWN, 27, 0);
 			return TRUE;
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}


void CDevConfig::OnCbnSelchangeCbCfgCmd()
{
	// TODO: 在此添加控件通知处理程序代码
	CString str;
	int iSel = m_ctlCBCfgCmd.GetCurSel();

	m_ctlEDConfig.Clear();

	CTreeCtrl* devTree = &((CNetSDKDemoDlg *)theApp.m_pMainWnd)->m_pWndDevList->m_ctlDevList;
	HTREEITEM selectItem = devTree->GetSelectedItem();
	if (devTree->ItemHasChildren(selectItem))
	{
		return;
	}

	CString strKey = devTree->GetItemText(selectItem);
	if (-1 != strKey.Find("Stream"))
	{
		HTREEITEM parent = devTree->GetParentItem(selectItem);
		CString csTxtParent = devTree->GetItemText(parent);
		csTxtParent += ':';
		csTxtParent += strKey;

		strKey = csTxtParent;
	}


	CDevInfo *pDevInfo = NULL;
	
	theApp.m_DevList.Lookup(strKey, pDevInfo);	
	if (NULL == pDevInfo)
	{
		return;
	}

	if (0 == pDevInfo->iUserID)
	{
		AfxMessageBox("请先登陆该设备");
	}
	
	m_iCurAction = g_strCMD[iSel].iGetCMD;
	m_iCurUserID = pDevInfo->iUserID;

	if (g_strCMD[iSel].iGetCMD == GET_USER_DATA)
	{
		int maxcount = 102400;
		char buffer[102400] = {0};
		long lRet = IP_NET_DVR_GetUserData(pDevInfo->iUserID, buffer, &maxcount);
		m_ctlEDConfig.SetWindowText(buffer);
	}
	else
	{
		int iRet = IP_NET_DVR_GetDVRConfig(pDevInfo->iUserID, g_strCMD[iSel].iGetCMD, 0, NULL, 0, 0);

		if (iRet == ERR_NOT_FIND_DEVICE)
		{
			AfxMessageBox("句柄错误");
			return ;
		}

		else if (iRet == ERR_DEV_NOT_CONNECTED)
		{
			AfxMessageBox("设备未连接");
			return ;
		}

		else if (iRet == ERR_DEV_NOT_LOGIN)
		{
			AfxMessageBox("设备未登录成功");
			return ;
		}

		else if (iRet == ERR_OUTOFF_MEMORY)
		{
			AfxMessageBox("内存不足");
			return ;
		}
	}
}

HRESULT CDevConfig::OnDevAux(WPARAM wParam, LPARAM lParam)
{
	CSDKEvent *pSDKEvent = theApp.m_MSGConfig.Event_RemoveHead();
	while (pSDKEvent)
	{
		int nEv = pSDKEvent->nStateCode & 0x00ffffff;
		if (nEv != m_iCurAction || m_iCurUserID != wParam)
		{
			SAFE_DELETE(pSDKEvent);
			break;
		}


		CString strErr;
		for (int i=0; i<g_iCmdCount; i++)
		{
			if (g_strCMD[i].iSetCMD == nEv)
			{
				strErr.Format("设置%s", g_strCMD[i].strCmdDescribe);

				if ( (pSDKEvent->nStateCode & 0xff000000) == 0)
				{
					strErr += _T("成功");
				}
				else
				{
					strErr += _T("失败");
				}
				AfxMessageBox(strErr);

				break;
			}
			else if (g_strCMD[i].iGetCMD == nEv)
			{
				if (pSDKEvent->pResponse && strlen(pSDKEvent->pResponse) > 0)
				{
					int iSel = m_ctlCBCfgCmd.GetCurSel();
					if (iSel < 0 || iSel >= g_iCmdCount)
					{
						return -1;
					}
					
					if (CMD_SET_SYSTEM_PTZ_COMMON == g_strCMD[iSel].iSetCMD) //云台基本配置
					{
						CString strTmp(pSDKEvent->pResponse);
						int begin = strTmp.Find("<PTZConfig");
						if (begin < 0)
						{
							return -2;
						}

						int end = strTmp.Find("<AdvanceConfig", begin);
						if (begin >= 0 && end > begin)
						{
							CString encode = strTmp.Mid(begin, end - begin + strlen("<AdvanceConfig"));
							encode += "/>";
							encode += "\r\n";
							encode += "</PTZConfig>";
							m_ctlEDConfig.SetWindowText(encode);
						}
					}

					else if (CMD_SET_SYSTEM_PTZ_ADVANCE == g_strCMD[iSel].iSetCMD)//云台高级配置
					{
						CString strTmp(pSDKEvent->pResponse);
						int begin = strTmp.Find("<AdvanceConfig>");
						if (begin < 0)
						{
							return -3;
						}
						int end = strTmp.Find("</AdvanceConfig>", begin);
						if (begin >= 0 && end > begin)
						{
							CString encode = "<PTZConfig>\r\n";
							encode += strTmp.Mid(begin, end - begin + strlen("</AdvanceConfig>"));
							encode += "\r\n</PTZConfig>";
							m_ctlEDConfig.SetWindowText(encode);
						}
					}

					else if (CMD_SET_MEDIA_VIDEO_ENCODE == g_strCMD[iSel].iSetCMD) //视频编码配置
					{
						CString strTmp(pSDKEvent->pResponse);
						int begin = strTmp.Find("<Encode>");
						if (begin < 0)
						{
							return -4;
						}
						int end = strTmp.Find("</Encode>", begin);
						if (begin >= 0 && end > begin)
						{
							CString encode = strTmp.Mid(begin, end - begin + strlen("</Encode>"));
							m_ctlEDConfig.SetWindowText(encode);
						}
					}
					else if (CMD_SET_MEDIA_VIDEO_CAPTURE == g_strCMD[iSel].iSetCMD)//视频采集配置
					{
						CString strTmp(pSDKEvent->pResponse);

						int begin = strTmp.Find("<Capture");
						if (begin < 0)
						{
							return -5;
						}

						int end = strTmp.Find("/>", begin);
						if (begin >= 0 && end > begin)
						{
							//CString Mid(int iFirst,int nCount) const;
							CString encode = strTmp.Mid(begin, end - begin + strlen("/>"));
							m_ctlEDConfig.SetWindowText(encode);
						}
						
					}
					else if (CMD_SET_MEDIA_VIDEO_OSD == g_strCMD[iSel].iSetCMD)//时间标题参数配置
					{
						CString strTmp(pSDKEvent->pResponse);

						int begin = strTmp.Find("<Overlay");
						if (begin < 0)
						{
							return -6;
						}

						int end = strTmp.Find("</Overlay>", begin);
						if (begin >= 0 && end > begin)
						{
							CString encode = strTmp.Mid(begin, end - begin + strlen("</Overlay>"));
							m_ctlEDConfig.SetWindowText(encode);
						}
					}

					else if (CMD_SET_PRIVACY_CONFIG == g_strCMD[iSel].iSetCMD)//修改隐私遮挡
					{
						CString strTmp(pSDKEvent->pResponse);

						int begin = strTmp.Find("<Mask>");
						if (begin < 0)
						{
							return -6;
						}

						int end = strTmp.Find("</Mask>", begin);
						if (begin >= 0 && end > begin)
						{
							CString encode = strTmp.Mid(begin, end - begin + strlen("</Mask>"));
							m_ctlEDConfig.SetWindowText(encode);
						}
					}
					else
					{
						m_ctlEDConfig.SetWindowText(pSDKEvent->pResponse);
					}
				}
				break;
			}
		}
		

		SAFE_DELETE(pSDKEvent);
		pSDKEvent = theApp.m_MSGConfig.Event_RemoveHead();
	}

	return 0l;
}