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

#include "stdafx.h"
#include "NetSDKDemo.h"
#include "NetSDKDemoDlg.h"
#include "NetSDKDLL.h"
#include "DevSearchDlg.h"
#include "DevListDlg.h"
#include "DeviceAttributeDlg.h"

const int g_iMaxAlarmEvent=21;
char *g_pstrAlarmEvent[]=
{
	_T("未知类型"),//0
	_T("设备下线"),//1
	_T("设备上线"),//2
	_T("USB接上"),//3
	_T("USB拔出"),//4
	_T("SD卡1接上"),//5
	_T("SD卡1拔出"),//6
	_T("SD卡2接上"),//7
	_T("SD卡2拔出"),//8
	_T("储空间不足"),//9
	_T("储空间不足"),//10
	_T("储空间不足"),//11
	_T("视频丢失"),//12
	_T("视频遮挡"),//13
	_T("移动告警"),//14
	_T("IO告警"),//15
	_T("IO告警"),//16
	_T("空间不足"),//17
	_T("录像启动"),//18
	_T("录像结束"),//19
	_T("录像失败"),//20
	NULL
};
#include <process.h>
struct ErrCode
{
	int iCode;
	CString strDescribe;
};

static const int g_iMaxCodeNum = 41;
static ErrCode g_strErrCode[41] =
{
	{ERR_NOT_FIND_DEVICE, _T("未找对应的设备")},
	{ERR_OPEN_AUDIOCAPTURE_FAIL, _T("打开音频采集设备失败，可能是声卡采集被占用")},
	{ERR_START_AUDIOCAPTURE_FAIL, _T("启动音频采集失败，可能是参数错误")},
	{ERR_AUDIO_PARAM_ERROR, _T("当前设备未启动对讲，或是参数不相同")},
	{ERR_AUDIO_NOT_START, _T("当前设备不是处于对讲状态")},
	{ERR_DEV_NOT_CONNECTED, _T("设备未连接")},
	{ERR_DEV_NOT_LOGIN, _T("设备未登录成功")},
	{ERR_MSGTYPE_ERROR, _T("消息类型有误")},
	{ERR_OUTOFF_MEMORY, _T("内存不足")},
	{ERR_INIT_SOCKET_ERROR, _T("表示初始化Socket失败")},
	{ERR_PARAM_ERROR, _T("非法参数")},
	{ERR_NOT_DEV_EXIST, _T("没有设备退出")},
	{ERR_START_THREADERROR, _T("启动线程失败")},
	{ERR_NOT_FIND_STREAM, _T("流句柄错误")},
	{ERR_ISUPLOADING_ERROR, _T("正在上传中")},
	{ERR_ISDOWNLOADING_ERROR, _T("正在下载中")},
	{ERR_IS_STARTAUDIO_ERROR, _T("正在对讲中，不允许下载")},
	{ERR_ISFINISH_ERROR, _T("当前没有在下载文件或是下载已完成")},
	{ERR_NOT_DOWNLOAD_MODE_ERROR, _T("当前不是在下载中")},
	{ERR_PTZCMD_ACTION_ERROR, _T("云台命令错误")},
	{ERR_LOC_FILE_ERROR, _T("文件参数有误")},
	{ERR_NOT_REPLAY_MODE_ERROR, _T("当前不是处于回放模式")},
	{ERR_PLAY_ACTION_ERROR, _T("播放操作有误")},
	{ERR_NOT_ALLOW_REPLAY_ERROR, _T("不支持回放或是未读取未获取是否支持回放")},
	{ERR_MEMORY_SIZE_ERROR, _T("所需内存太小")},
	{ERR_XML_FORMAT_ERROR, _T("XML格式错误")},
	{ERR_CREATE_SOCKET_ERROR, _T("创建Socket时失败")},
	{ERR_SEND_MODIFYCMD_ERROR, _T("发送失败")},
	{ERR_NOT_STARTTALK_MODE_ERROR, _T("当前未初始化广播参数，要先调用IP_NET_DVR_StartTalk设置相关参数")},
	{ERR_RECORD_MEDIA_PARAM_ERROR, _T("视频参数错误")},
	{ERR_RECORD_CREATEERROR, _T("创建录像失败")},
	{ERR_RECORD_ISRECORDING, _T("当前正在录像中，要求先停止录像，才能再开始")},
	{ERR_RECORD_FILEMAXSECONDS_ERROR, _T("可用值应该是10至1800")},
	{ERR_RECORD_ALLRECORDSECONDS_ERROR, _T("必须为大于0")},
	{ERR_RECORD_NOTRUNNING, _T("此流没有在录像或已停止")},
	{ERR_RECORD_STREAMPARAM_ERROR, _T("录像流参数配置有误")},
	{ERR_RECORD_WRITETEMPBUFFER_ERROR, _T("写入缓存失败")},
	{ERR_RECORD_ISNOTRECORDSTREAM_MODE, _T("当前句柄是实时流模式，不允许调用此函数")},
	{ERR_RECORD_NOTINPUTSTREAM_MODE, _T("当前不是外部输流录像模式")},
	{ERR_RECORD_FILEPATH_ERROR, _T("文件目录有误")},
	{NULL, NULL}
};


struct NetSatateEvent
{
	int iEvent;
	CString strDescribe;
};

static const int g_iMaxEvent = 51;
static NetSatateEvent g_strEvent[51] =
{
	{EVENT_CONNECTING, _T("连接中")},
	{EVENT_CONNECTOK, _T("连接成功")},
	{EVENT_CONNECTFAILED, _T("连接失败")},
	{EVENT_SOCKETERROR, _T("sock失败")},
	{EVENT_LOGINOK, _T("登录成功")},
	{EVENT_LOGINFAILED, _T("登录失败")},
	{EVENT_STARTAUDIOOK, _T("对讲启动成功")},
	{EVENT_STARTAUDIOFAILED, _T("对讲启动失败")},
	{EVENT_STOPAUDIOOK, _T("停止对讲成功")},
	{EVENT_STOPAUDIOFAILED, _T("停止对讲失败")},
	{EVENT_SENDPTZOK, _T("发送云台控制命令成功")},
	{EVENT_SENDPTZFAILED, _T("发送云台控制命令失败")},
	{EVENT_SENDAUXOK, _T("发送辅助通道成功")},
	{EVENT_SENDAUXFAILED, _T("发送辅助通道失败")},
	{EVENT_UPLOADOK, _T("上传文件成功")},
	{EVENT_UPLOADFAILED, _T("上传文件失败")},
	{EVENT_DOWNLOADOK , _T("下载成功")},
	{EVENT_DOWNLOADFAILED , _T("下载失败")},
	{EVENT_REMOVEOK , _T("删除文件成功")},
	{EVENT_REMOVEFAILED , _T("删除文件失败")},
	{EVENT_SENDPTZERROR , _T("云台操作失败")},
	{EVENT_PTZPRESETINFO, _T("预置点信息")},
	{EVNET_PTZNOPRESETINFO, _T("没有预置点")},
	{EVENT_PTZALARM, _T("告警信息")},
	{EVENT_RECVVIDEOPARAM, _T("视频参数返回")},
	{EVENT_RECVAUDIOPARAM, _T("音频参数返回")},
	{EVENT_CONNECTRTSPERROR, _T("请求实时视频失败")},
	{EVENT_CONNECTRTSPOK, _T("读求媒体流成功")},
	{EVENT_RTSPTHREADEXIT, _T("媒体流线程退出")},
	{EVENT_URLERROR, _T("解释连接媒体流URL时失败")},
	{EVENT_RECVVIDEOAUDIOPARAM, _T("收到音视频参数")},
	{EVENT_LOGIN_USERERROR, _T("登录用户或密码错误")},
	{EVENT_LOGOUT_FINISH, _T("登录线程已退出主循环")},
	{EVENT_LOGIN_RECONNECT, _T("进行重新登录")},
	{EVENT_LOGIN_HEARTBEAT_LOST, _T("心跳丢失")},
	{EVENT_STARTAUDIO_ISBUSY, _T("设备对讲被占用")},
	{EVENT_STARTAUDIO_PARAMERROR, _T("对讲音频参数错误")},
	{EVENT_STARTAUDIO_AUDIODDISABLED, _T("设备不支持对讲")},
	{EVENT_CONNECT_RTSPSERVER_ERROR, _T("连接错误，可能是IP或端口错误")},
	{EVENT_CREATE_RTSPCLIENT_ERROR, _T("创建rtsp客户端错误")},
	{EVENT_GET_RTSP_CMDOPTION_ERROR, _T("连接rtsp服务器，返回错误")},
	{EVENT_RTSP_AUTHERROR, _T("认证失败，可能是用户或密码错误")},
	{EVNET_RECORD_FILEBEGIN, _T("开始录一个文件")},
	{EVENT_RECORD_FILEEND, _T("录完一个文件")},
	{EVENT_RECORD_TASKEND, _T("所有录像已完成，录像将停止")},
	{EVENT_RECORD_DISKFREESPACE_TOOLOW, _T("硬盘可用空间太小,此时并不会进入录像，而一直在等待有足够的空间")},
	{EVNET_RECORD_FILEBEGIN_ERROR, _T("创建文件时出错")},
	{EVNET_RECORD_WRITE_FILE_ERROR, _T("写入文件时出错")},
	{EVENT_RECORD_INITAVIHEAD_ERROR, _T("写入文件头时出错")},
	{EVENT_RECORD_MEDIA_PARAM_ERROR, _T("视频参数错误，可能是视频流请求失败")},
	{-1, NULL}
};

// CDevSearch 对话框

IMPLEMENT_DYNAMIC(CDevSearch, CDialog)

CDevSearch::CDevSearch(CRect rcWnd, CWnd* pParent /*=NULL*/)
	: CDialog(CDevSearch::IDD, pParent)
	,m_rcClient(CRect(0,0, rcWnd.Width(), rcWnd.Height()))
{
	m_bSearch = FALSE;
	m_lLastIPCCount = 0;
	InitializeCriticalSection(&m_csAlarmEvent);
}

CDevSearch::~CDevSearch()
{
	EnterCriticalSection(&m_csAlarmEvent);
	m_listAlarmEvent.RemoveAll();
	LeaveCriticalSection(&m_csAlarmEvent);
	m_IPCList.RemoveAll();
	DestroyWindow();
	DeleteCriticalSection(&m_csAlarmEvent);
}

void CDevSearch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_DEVICE, m_ctlDeviceList);
	DDX_Control(pDX, IDC_BTN_SEARCH, m_ctlBTNSearch);
	DDX_Control(pDX, IDC_LIST_ALARMEVENT, m_ctlAlarmList);
	DDX_Control(pDX, IDC_CK_ALARMEVENT, m_ctlCKAlarm);
	DDX_Control(pDX, IDC_CK_DEVSEARCH, m_ctlCKSearch);
	DDX_Control(pDX, IDC_BTN_ADD, m_ctlDEVAdd);
}


BEGIN_MESSAGE_MAP(CDevSearch, CDialog)
	ON_BN_CLICKED(IDC_BTN_SEARCH, &CDevSearch::OnBnClickedBtnSearch)
	ON_BN_CLICKED(IDC_BTN_ADD, &CDevSearch::OnBnClickedBtnAdd)
	ON_WM_TIMER()
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_DEVICE, &CDevSearch::OnNMDblclkListDevice)
	ON_BN_CLICKED(IDC_CK_DEVSEARCH, &CDevSearch::OnBnClickedCkDevsearch)
	ON_BN_CLICKED(IDC_CK_ALARMEVENT, &CDevSearch::OnBnClickedCkAlarmevent)
END_MESSAGE_MAP()


// CDevSearch 消息处理程序

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

	// TODO:  在此添加额外的初始化
	m_ctlDeviceList.MoveWindow(CRect(0, 0, m_rcClient.Width()-150, m_rcClient.Height()));
	m_ctlAlarmList.MoveWindow(CRect(0, 0, m_rcClient.Width()-150, m_rcClient.Height()));

	DWORD dwStyle = GetWindowLong(m_ctlDeviceList.m_hWnd, GWL_STYLE);
	dwStyle &=~(LVS_TYPEMASK);
	dwStyle &=~(LVS_EDITLABELS);

	SetWindowLong(m_ctlDeviceList.m_hWnd, GWL_STYLE, dwStyle|LVS_REPORT|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);
	DWORD dwStyles = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES;
	m_ctlDeviceList.SetExtendedStyle( m_ctlDeviceList.GetExtendedStyle()|dwStyles);

	int i = m_ctlDeviceList.InsertColumn(0, _T("IP地址"),LVCFMT_CENTER,120);
	m_ctlDeviceList.InsertColumn(1, _T("物理地址"), LVCFMT_LEFT, 120);
	m_ctlDeviceList.InsertColumn(2, _T("默认网关"), LVCFMT_LEFT, 100);
	m_ctlDeviceList.InsertColumn(3, _T("子网掩码"), LVCFMT_LEFT, 100);
	m_ctlDeviceList.InsertColumn(4, _T("设备类型"), LVCFMT_LEFT, 120);
	m_ctlDeviceList.InsertColumn(5, _T("序列号"), LVCFMT_LEFT, 120);
		
	dwStyle = GetWindowLong(m_ctlAlarmList.m_hWnd, GWL_STYLE);
	dwStyle &=~(LVS_TYPEMASK);
	dwStyle &=~(LVS_EDITLABELS);

	SetWindowLong(m_ctlAlarmList.m_hWnd, GWL_STYLE, dwStyle|LVS_REPORT|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);
	dwStyles = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES ;
	m_ctlAlarmList.SetExtendedStyle( m_ctlAlarmList.GetExtendedStyle()|dwStyles);
	
	int iLenMax = m_rcClient.Width()-150;
	i = m_ctlAlarmList.InsertColumn(0, _T("告警时间"),LVCFMT_LEFT,iLenMax/4);
	m_ctlAlarmList.InsertColumn(1, _T("告警信息"), LVCFMT_LEFT, iLenMax/2);
	m_ctlAlarmList.InsertColumn(2, _T("告警设备"), LVCFMT_LEFT, iLenMax/4);
	
	m_ctlAlarmList.ShowWindow(SW_HIDE);
	

	m_ctlCKSearch.SetCheck(1);
	m_ctlCKAlarm.SetCheck(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

BOOL CDevSearch::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	if (pMsg->message == WM_StatusEvent)
	{
		if (pMsg->wParam == EVENT_PTZALARM)
		{
			while (!m_listAlarmEvent.IsEmpty())
			{
				EnterCriticalSection(&m_csAlarmEvent);
				AlarmInfo aItem = m_listAlarmEvent.RemoveHead();
				LeaveCriticalSection(&m_csAlarmEvent);

				CString strIP = "";
				{
					CMapAutoLock Lock;
					POSITION pos = theApp.m_DevList.GetStartPosition();
					CString strKey;
					while (pos)
					{
						CDevInfo *pDevInfo = NULL;
						theApp.m_DevList.GetNextAssoc(pos, strKey, pDevInfo);
						if (pDevInfo->iUserID == aItem.iUserID)
						{
							strIP.Format("%s", strKey);
							break;	
						}
					}
				}
				
				CString strAlarmTime = "";
				strAlarmTime.Format("%02d-%02d-%02d %02d:%02d:%02d", aItem.Alarm.time.year, aItem.Alarm.time.month, 
					aItem.Alarm.time.day, aItem.Alarm.time.hour, aItem.Alarm.time.minute, aItem.Alarm.time.second);
				CString strAlarmType = "";
				if (aItem.Alarm.code > 0 && aItem.Alarm.code < g_iMaxAlarmEvent)
				{
					strAlarmType.Format("%s", g_pstrAlarmEvent[aItem.Alarm.code]);
				}
				if ( strAlarmTime.IsEmpty() || strAlarmType.IsEmpty() || strIP.IsEmpty())
					continue;
				int iItem = m_ctlAlarmList.InsertItem(0, strAlarmTime);
				m_ctlAlarmList.SetItemText(iItem, 1, strAlarmType);
				m_ctlAlarmList.SetItemText(iItem, 2, strIP);
			}
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}


void CDevSearch::OnBnClickedBtnSearch()
{
	// TODO: 在此添加控件通知处理程序代码
	
	CNetSDKDemoDlg *pSDKDemoDLg = (CNetSDKDemoDlg *)GetParent();
	
	if (m_bSearch)
	{
		IPCSearch(OFF);
		m_ctlBTNSearch.SetWindowText(_T("搜索"));
		m_bSearch = FALSE;
	}
	else
	{
		m_IPCList.RemoveAll();
		m_ctlDeviceList.DeleteAllItems();
		m_lLastIPCCount = 0;
		long lRet = IPCSearch(ON);
		if (lRet == 0)
		{
			m_ctlBTNSearch.SetWindowText(_T("停止"));
			m_bSearch = TRUE;
		}	
	}

}

void CDevSearch::OnBnClickedBtnAdd()
{
	// TODO: 在此添加控件通知处理程序代码
	CNetSDKDemoDlg *pNetSDKDemoDlg = (CNetSDKDemoDlg *)GetParent();
	CDevListDlg *pDevListDlg = (CDevListDlg *)pNetSDKDemoDlg->m_pWndDevList;

	int iItemCount = m_ctlDeviceList.GetItemCount();

	for (int i=0; i<iItemCount; i++)
	{
		if (m_ctlDeviceList.GetCheck(i))
		{

			CString strIP = m_ctlDeviceList.GetItemText(i, 0);

			IPC IPCInfo;

			int key ;
			POSITION pos = m_IPCList.GetStartPosition();
			while(pos)
			{

				m_IPCList.GetNextAssoc(pos, key, IPCInfo);
				//if (strIP == IPCInfo.m_IPCEntry.lanCfg.IPAddress)
				if (0 == strcmp(strIP.GetBuffer(), IPCInfo.m_IPCEntry.lanCfg.IPAddress))
				{
					pDevListDlg->ADDIPC(IPCInfo.m_IPCEntry);
					break;
				}
			}


		}
	}

	((CNetSDKDemoDlg *)theApp.m_pMainWnd)->m_pWndDevList->ReflashTreeImage();
	UpdateWindow();
	int a = 0;
	
	
}

int CDevSearch::IPCSearch(BOOL bSearch)
{
	if (bSearch)
	{
		long lRet = IP_NET_DVR_StartSearchIPC();
		OutputDebugString("Func:IP_NET_DVR_StartSearchIPC....\n");
		if (lRet != 0)
		{
			AfxMessageBox("[IP_NET_DVR_StartSearchIPC]启动搜索线程失败");
			return lRet;
		}

		SetTimer(WM_TIMEID, 1000, NULL);

		return lRet;
	}
	else
	{
		KillTimer(WM_TIMEID);

		IP_NET_DVR_StopSearchIPC();
		return 0;
	}
}

BOOL CDevSearch::FlushDevList()
{
	CString strDevType;

	long lCount = IP_NET_DVR_GetSearchIPCCount();


	lCount -= m_lLastIPCCount;
	if (lCount <=  0) return TRUE;

	for (int iIndex=m_lLastIPCCount; iIndex<(lCount+m_lLastIPCCount); iIndex++)
	{
		IPC_ENTRY DevInfo;
		long lRet = IP_NET_DVR_GetIPCInfo(iIndex, &DevInfo);
		if (lRet != 0) continue;

		int iItemCount = m_ctlDeviceList.GetItemCount();
		int iItem = m_ctlDeviceList.InsertItem(iItemCount, DevInfo.lanCfg.IPAddress);
		m_ctlDeviceList.SetItemText(iItem, 1, DevInfo.lanCfg.MACAddress);
		m_ctlDeviceList.SetItemText(iItem, 2, DevInfo.lanCfg.gateWay);
		m_ctlDeviceList.SetItemText(iItem, 3, DevInfo.lanCfg.netMask);
		m_ctlDeviceList.SetItemText(iItem, 4, DevInfo.deviceType);
		m_ctlDeviceList.SetItemText(iItem, 5, DevInfo.ipc_sn);
		IPC IPCInfo;
		IPCInfo.m_iIndex = iIndex; 
		memcpy(&IPCInfo.m_IPCEntry, &DevInfo, sizeof(IPC_ENTRY));
		
		m_IPCList.SetAt(iItemCount, IPCInfo);
	}
	m_lLastIPCCount += lCount;

	return 0;

}
void CDevSearch::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nIDEvent == WM_TIMEID)
	{
		FlushDevList();
	}
	CDialog::OnTimer(nIDEvent);
}
extern CNetSDKDemoApp theApp;

HTREEITEM FindTreeItem(CTreeCtrl& tree, HTREEITEM item, CString& strText)   
{   
	HTREEITEM   hFind;   
	if(item == NULL)   
		return  NULL;  

	while(item!=NULL)   
	{   
		if(tree.GetItemText(item) == strText)   
			return item;  

		if(tree.ItemHasChildren(item))   
		{   
			item = tree.GetChildItem(item);   
			hFind = FindTreeItem(tree, item,strText);   
			if(hFind)   
			{   
				return hFind;   
			}   
			else   
				item= tree.GetNextSiblingItem(tree.GetParentItem(item));   
		}   
		else   
		{   
			item = tree.GetNextSiblingItem(item);   
			if(item == NULL)   
				return NULL;   
		}   
	}  

	return   item;   
}

void CDevSearch::OnNMDblclkListDevice(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;

	if (!m_bSearch)
	{
		return;
	}

	NMHEADER *pp = (NMHEADER *)pNMHDR;

	if (pp->iItem < 0) return ;


	CString strIP = m_ctlDeviceList.GetItemText(pp->iItem, 0);

	IPC IPCInfo = {0};
	BOOL bFound = FALSE;
	int key ;

	POSITION pos = m_IPCList.GetStartPosition();
	while(pos)
	{

		m_IPCList.GetNextAssoc(pos, key, IPCInfo);
		if (0 == strcmp(strIP.GetBuffer(), IPCInfo.m_IPCEntry.lanCfg.IPAddress))
		{
			bFound = TRUE;
			break;
		}
	}

	if (bFound)
	{
		
		CTreeCtrl&	treeCtrl = ((CNetSDKDemoDlg*)theApp.m_pMainWnd)->m_pWndDevList->m_ctlDevList;

		if (FindTreeItem(treeCtrl, treeCtrl.GetRootItem(), CString( IPCInfo.m_IPCEntry.lanCfg.IPAddress)))
		{
			MessageBox(_T("该设备已添加, 不能修改设备属性"), _T("提示"), MB_OK);
			return;
		}

		CDeviceAttribute dlgDevAttr(&IPCInfo, this);
		dlgDevAttr.DoModal();
	}
}

void CDevSearch::OnBnClickedCkDevsearch()
{
	// TODO: 在此添加控件通知处理程序代码
	if (m_ctlCKSearch.GetCheck() > 0)
	{	
		m_ctlCKSearch.SetCheck(1);
		m_ctlCKAlarm.SetCheck(0);
	}
	else
	{
		m_ctlCKSearch.SetCheck(1);
	}
	if (m_ctlCKSearch.GetCheck()>0)
	{
		m_ctlAlarmList.ShowWindow(SW_HIDE);
		m_ctlDeviceList.ShowWindow(SW_SHOW);
		m_ctlBTNSearch.ShowWindow(SW_SHOW);
		m_ctlDEVAdd.ShowWindow(SW_SHOW);
	}
}

void CDevSearch::OnBnClickedCkAlarmevent()
{
	// TODO: 在此添加控件通知处理程序代码
	if (m_ctlCKAlarm.GetCheck() > 0)
	{
		m_ctlCKAlarm.SetCheck(1);
		m_ctlCKSearch.SetCheck(0);
	}
	else
	{
		m_ctlCKAlarm.SetCheck(1);
	}

	if (m_ctlCKAlarm.GetCheck() > 0)
	{
		m_ctlAlarmList.ShowWindow(SW_SHOW);
		m_ctlDeviceList.ShowWindow(SW_HIDE);
		m_ctlBTNSearch.ShowWindow(SW_HIDE);
		m_ctlDEVAdd.ShowWindow(SW_HIDE);
	}
}


LONG __stdcall	CDevSearch::StatusCallBack(LONG lUser,LONG mlStateCode,char *mpResponse,void *pUser)
{	
	switch(mlStateCode)
	{
	case EVENT_PTZALARM:
		{	
			ALARM_ITEM *pai = (ALARM_ITEM *)mpResponse;
			if (pai)
			{
				EnterCriticalSection(&m_csAlarmEvent);
				AlarmInfo aItem;
				aItem.iUserID = lUser;
				memcpy(&aItem.Alarm, pai, sizeof(ALARM_ITEM));
				m_listAlarmEvent.AddTail(aItem);
				LeaveCriticalSection(&m_csAlarmEvent);
				PostMessage(WM_StatusEvent, EVENT_PTZALARM, 0);
			}
		}
		break;
	default:break;
	}
	return 0;
}