#pragma once
#include "NetSDKDLL.h"
#include "afxcmn.h"
#include "BCMenu.h"

#define MAX_PLAYER_NUM 32

#define OPEN_OK 0			// 0 打开成功
#define IN_WORKING 1		//       1 视频已开启
#define OPEN_FAILED -1		//		-1 打开失败
#define LOSS_DEVICE -2		//		-2 未找到设备
#define NO_LOGIN -3			//		-3 设备未登录
#define WND_BUSY -4			//      -4 窗口被占用
#define INVALIDATE_DEV -5   //		-5 该设备无法进行视频播放
#define WND_INVALIDATE -6	//      -6 窗口不可用

// CDevListDlg 对话框


class CDevListDlg : public CDialog
{
	DECLARE_DYNAMIC(CDevListDlg)

public:
	CDevListDlg(unsigned int iW, unsigned int iH, CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CDevListDlg();

// 对话框数据
	enum { IDD = IDD_DLG_DEVLIST };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnInitDialog();

	BOOL ADDIPC(IPC_ENTRY &entry);
private:
	CRITICAL_SECTION m_csDevListEvent;
	CList<CSDKEvent *> m_clEvent; // 设备列表消息队列

public:
	int             m_nAVParamLen;
	CTreeCtrl		m_ctlDevList;
	CImageList*		m_pImageList;
	CDevInfo*		m_pDevInfo;
	
	CRITICAL_SECTION		m_csSectionTItem;
	CList<HTREEITEM>		m_lsTreeItem;
	HANDLE m_hMSGProc;
	unsigned int m_uiMSGProc;
	static unsigned int __stdcall DevListMsgProc(void *pUser);

	void		PTZCtrl(PTZ_CMD_TYPE PtzCmd, int iPanSpeed, int iTiltSpeed);
	void		PresetCtrl(PTZ_PRESET_TYPE PresetCmd, int iPresetNum);
	void		XMLCtrl(char *pStrXML);
	int			OpenMedia(LPCTSTR strKey, HWND hPlayWnd);
	int			OpenMediaEx(LPCTSTR strKey, HWND hPlayWnd);
	
	int			LoginMedia(LPCTSTR strKey);
	int			LogoutMedia(LPCTSTR strKey);
	int			ChangeState(CString strKey);
	HTREEITEM	FindTreeItem(HTREEITEM item,CString& strText);
	void		DClickTree();
	long		playDevi(CString& strKey);
	long		playDevi(CString& strKey, HWND hWnd);
	long		LoginDevi(CString& strKey);
	long		LoginDevi(CDevInfo* pDevInfo);
	long		CloseMedia(LPCTSTR strKey);
	long		CloseMediaInfo(CDevInfo* pDevInfo);
	
	void		ReflashTreeImage();


	void LoopPlay(BOOL bLoop, HWND hLoopWnd, INT IElapse);
	HWND m_hLoopWnd;
	int m_iElapse;
private:
	HANDLE m_hLoopThread;
	unsigned int m_uiLoopThreadID;
	unsigned int m_iWidth, m_iHeight;
	long m_lLastIPCCount;
	
	BCMenu m_menu;
	HTREEITEM m_hDevice;
	CRect m_rcClient;
	
	void TravelItem(HTREEITEM hItem, int iStatus, char *pStrIP, BOOL bChild = FALSE);
	afx_msg void OnNMRclickTreeDevlist(NMHDR *pNMHDR, LRESULT *pResult);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnNMDblclkTreeDevlist(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnMenu132775Openvideo();
	afx_msg void OnMenu132776Closevideo();

	static LONG __stdcall RealDataCallBackFunc(LONG lRealHandle,DWORD dwDataType,BYTE *pBuffer,DWORD dwBufSize,LPFRAME_EXTDATA  pExtData);
	static LONG __stdcall RealDataCallBackFuncDevi(LONG lRealHandle,DWORD dwDataType,BYTE *pBuffer,DWORD dwBufSize,LPFRAME_EXTDATA  pExtData);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnMenu132789Autoreconnect();
	afx_msg void OnNMClickTreeDevlist(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTvnSelchangedTreeDevlist(NMHDR *pNMHDR, LRESULT *pResult);

	afx_msg void OnMenu1StartCtrl();
	afx_msg void OnMenu1StopCtrl();
	afx_msg void OnMenu32831Substream();
	afx_msg void OnMenu32830Mainstream();
	afx_msg void OnMenu132844Delete();


	afx_msg void OnMenu132852Adddvr();
	afx_msg void OnMenu132854Tcp();
	afx_msg void OnMenuRemCfg();
};
