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

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


// CPlayCtrl 对话框

char *g_strZoomRect[] = 
{
	_T("关闭缩放"),
	_T("放大模式"),
	_T("缩小模式"),
	_T("拖动模式"),
	NULL
};

IMPLEMENT_DYNAMIC(CPlayCtrl, CDialog)

CPlayCtrl::CPlayCtrl(CRect rcClient, CWnd* pParent /*=NULL*/)
	: CDialog(CPlayCtrl::IDD, pParent)
	,m_rcClient(0, 0, rcClient.Width(), rcClient.Height())
{

}

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

void CPlayCtrl::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_GROUPX, m_ctlGroup);
	DDX_Control(pDX, IDC_CB_ZOOMRECT, m_ctlZoomRect);
	DDX_Control(pDX, IDC_CK_FULLSCREEN, m_ctlCKFullScreen);
}


BEGIN_MESSAGE_MAP(CPlayCtrl, CDialog)
	ON_BN_CLICKED(IDC_BUTTON1, &CPlayCtrl::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BTN_ZOOMRECT_GET, &CPlayCtrl::OnBnClickedBtnZoomrectGet)
	ON_BN_CLICKED(IDC_BTN_ZOOMRECT_SET, &CPlayCtrl::OnBnClickedBtnZoomrectSet)
	ON_BN_CLICKED(IDC_CK_FULLSCREEN, &CPlayCtrl::OnBnClickedCkFullscreen)
	ON_BN_CLICKED(IDC_BTN_SETFULLSCREEN, &CPlayCtrl::OnBnClickedBtnSetfullscreen)
END_MESSAGE_MAP()


// CPlayCtrl 消息处理程序

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

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

	// TODO:  在此添加额外的初始化
	m_ctlGroup.MoveWindow(m_rcClient.left+2, m_rcClient.top,m_rcClient.Width()-2, m_rcClient.Height()-2);
	m_ctlZoomRect.ResetContent();
	for (int i=0; g_strZoomRect[i] != NULL; i++)
	{
		m_ctlZoomRect.InsertString(i, g_strZoomRect[i]);
	}
	m_ctlZoomRect.SetCurSel(0);
	m_ctlGroup.Invalidate(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CPlayCtrl::OnBnClickedBtnZoomrectGet()
{
	// TODO: 在此添加控件通知处理程序代码
#if 1
	HWND hWnd = ((CNetSDKDemoDlg *)GetParent())->GetCurSelWnd();
	CString strKey = ((CNetSDKDemoDlg *)GetParent())->GetWndUser(hWnd);
	BOOL bFound =  FALSE;
	long lPlayID = 0;
	{
		CDevInfo *pDevInfo = NULL;
		bFound = theApp.m_DevList.Lookup(strKey, pDevInfo);
		if (bFound)
		{
			lPlayID = pDevInfo->lPlayerID;
		}
	}

	if (lPlayID <= 0)
	{
		AfxMessageBox("请选择开启视频播放的窗口!!!");
		return ;
	}

	int iStatus = IP_TPS_GetZoomRectStatus(lPlayID);
	if (iStatus == ERR_PLY_VIDEOCHANNELID_ERROR)
	{
		AfxMessageBox("视频通道端口nPort错误!!!");
		return ;
	}
	else if (iStatus == ERR_PLAY_NOTPLAYMODE_ERROR)
	{
		AfxMessageBox("请选择正在播放的视频!!!");
		return ;
	}
	else
	{
		m_ctlZoomRect.SetCurSel(iStatus);
		m_ctlZoomRect.Invalidate(FALSE);
	}
#endif
}

void CPlayCtrl::OnBnClickedBtnZoomrectSet()
{
	// TODO: 在此添加控件通知处理程序代码
	HWND hWnd = ((CNetSDKDemoDlg *)GetParent())->GetCurSelWnd();
	CString strKey = ((CNetSDKDemoDlg *)GetParent())->GetWndUser(hWnd);
	BOOL bFound =  FALSE;
	long lPlayID = 0;
	{
		CDevInfo *pDevInfo = NULL;
		bFound = theApp.m_DevList.Lookup(strKey, pDevInfo);
		if (bFound)
		{
			lPlayID = pDevInfo->lPlayerID;
		}
	}

	if (lPlayID <= 0)
	{
		AfxMessageBox("请选择开启视频播放的窗口!!!");
		return ;
	}
	
	int iSel = m_ctlZoomRect.GetCurSel();
	int iRet = IP_TPS_SetZoomRectOn(lPlayID, iSel);
	if (iRet == ERR_PLY_VIDEOCHANNELID_ERROR)
	{
		AfxMessageBox("视频通道端口nPort错误!!!");
		return ;
	}
	else if (iRet == ERR_PLAY_NOTPLAYMODE_ERROR)
	{
		AfxMessageBox("请选择播放的窗口!!!");
		return ;
	}
	else
	{
		if (iSel == 0)
			((CNetSDKDemoDlg *)GetParent())->OpenDigitZoom(FALSE, 0);
		else
			((CNetSDKDemoDlg *)GetParent())->OpenDigitZoom(TRUE, lPlayID);
	}
}

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

}

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

	if (pMsg->message == WM_KEYDOWN)
	{
		if (pMsg->wParam == 13)
			return TRUE;
		if (pMsg->wParam == 27)
		{
			//EndFullScreen();

			return TRUE;
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CPlayCtrl::OnBnClickedBtnSetfullscreen()
{
	// TODO: 在此添加控件通知处理程序代码
	HWND hWnd = ((CNetSDKDemoDlg *)GetParent())->GetCurSelWnd();
	CString strKey = ((CNetSDKDemoDlg *)GetParent())->GetWndUser(hWnd);
	BOOL bFound =  FALSE;
	long lPlayID = 0;
	{
		CDevInfo *pDevInfo = NULL;
		bFound = theApp.m_DevList.Lookup(strKey, pDevInfo);
		if (bFound)
		{
			lPlayID = pDevInfo->lPlayerID;
		}
	}

	if (lPlayID <= 0)
	{
		AfxMessageBox("请选择开启视频播放的窗口!!!");
		return ;
	}

	if (m_ctlCKFullScreen.GetCheck() > 0)
		IP_TPS_SetFullFillStatus(lPlayID, TRUE);
	else
		IP_TPS_SetFullFillStatus(lPlayID, FALSE);

}
