// FECDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PlayDemo_VC.h"
#include "FECDlg.h"
#include "PlayDemo_VCDlg.h"
#include <Shlwapi.h>


#define FEC_DISENABLE		0
#define FEC_ENABLE			1

#define INVALID_ID			-1

#define DEFAULT_PTZ_X_POSITIOM		3000
#define DEFAULT_PTZ_Y_POSITIOM		7000
#define DEFAULT_PTZ_ZOOM_POSITIOM	10000
#define DEFAULT_PTZ_RST_WIDTH		512
#define DEFAULT_PTZ_RST_HEIGHT		512
#define DEFAULT_DEGREE		90

CPlayDemo_VCDlg* m_pMainDlg = NULL;

// CLS_FECDlg dialog

IMPLEMENT_DYNAMIC(CLS_FECDlg, CDialog)

CLS_FECDlg::CLS_FECDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLS_FECDlg::IDD, pParent)
{
	m_iPlayerID = INVALID_ID;
	for (int i = 0; i < MAX_FEC_WINDOWS_COUNT; i++)
	{
		m_tFecWindowPara[i].iFecSubID = INVALID_ID;
		m_tFecWindowPara[i].blOpen = false;
	}
	m_iSelectSubId = INVALID_ID;
	m_blStartTrack = false;
}

CLS_FECDlg::~CLS_FECDlg()
{
}

void CLS_FECDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_FISHEYE_VIDEO, m_stcFishEyeVideo);
	DDX_Control(pDX, IDC_STATIC_360_VIDEO, m_stc360Video);
	DDX_Control(pDX, IDC_STATIC_180_VIDEO, m_stc180Video);
	DDX_Control(pDX, IDC_STATIC_PTZ_VIDEO1, m_stcPtzVideo1);
	DDX_Control(pDX, IDC_STATIC_PTZ_VIDEO2, m_stcPtzVideo2);
	DDX_Control(pDX, IDC_COMBO_FEC_PLACE_TYPE, m_cboFecPlaceType);
	DDX_Control(pDX, IDC_EDIT_FEC_RadiusLeft, m_edtRadiusLeft);
	DDX_Control(pDX, IDC_EDIT_FEC_RadiusRight, m_edtRadiusRight);
	DDX_Control(pDX, IDC_EDIT_FEC_RadiusTop, m_edtRadiusTop);
	DDX_Control(pDX, IDC_EDIT_FEC_RadiusBottom, m_edtRadiusBottom);
	DDX_Control(pDX, IDC_EDIT_FEC_WideScanOffset, m_edtWideScanOffset);
	DDX_Control(pDX, IDC_EDIT_FEC_PTZPositionX, m_edtPtzPositionX);
	DDX_Control(pDX, IDC_EDIT_FEC_PTZPositionY, m_edtPtzPositionY);
}


BEGIN_MESSAGE_MAP(CLS_FECDlg, CDialog)	
	ON_WM_CLOSE()
	ON_STN_CLICKED(IDC_STATIC_FISHEYE_VIDEO, &CLS_FECDlg::OnStnClickedStaticFisheyeVideo)
	ON_STN_CLICKED(IDC_STATIC_360_VIDEO, &CLS_FECDlg::OnStnClickedStatic360Video)
	ON_STN_CLICKED(IDC_STATIC_180_VIDEO, &CLS_FECDlg::OnStnClickedStatic180Video)
	ON_STN_CLICKED(IDC_STATIC_PTZ_VIDEO1, &CLS_FECDlg::OnStnClickedStaticPtzVideo1)
	ON_STN_CLICKED(IDC_STATIC_PTZ_VIDEO2, &CLS_FECDlg::OnStnClickedStaticPtzVideo2)
	ON_BN_CLICKED(IDC_BUTTON_SET_CYCLE_PARA, &CLS_FECDlg::OnBnClickedButtonSetCyclePara)
	ON_BN_CLICKED(IDC_BUTTON_SET_WideScanOffset, &CLS_FECDlg::OnBnClickedButtonSetWidescanoffset)
	ON_BN_CLICKED(IDC_BUTTON_SET_PTZ_POSITION, &CLS_FECDlg::OnBnClickedButtonSetPtzPosition)
	ON_STN_DBLCLK(IDC_STATIC_FISHEYE_VIDEO, &CLS_FECDlg::OnStnDblclickStaticFisheyeVideo)
	ON_STN_DBLCLK(IDC_STATIC_360_VIDEO, &CLS_FECDlg::OnStnDblclickStatic360Video)
	ON_STN_DBLCLK(IDC_STATIC_180_VIDEO, &CLS_FECDlg::OnStnDblclickStatic180Video)
	ON_STN_DBLCLK(IDC_STATIC_PTZ_VIDEO1, &CLS_FECDlg::OnStnDblclickStaticPtzVideo1)
	ON_STN_DBLCLK(IDC_STATIC_PTZ_VIDEO2, &CLS_FECDlg::OnStnDblclickStaticPtzVideo2)
	ON_BN_CLICKED(IDC_BUTTON_FEC_CAPTURE_BMP, &CLS_FECDlg::OnBnClickedButtonFecCaptureBmp)
	ON_BN_CLICKED(IDC_BUTTON_FEC_CAPTURE_JPG, &CLS_FECDlg::OnBnClickedButtonFecCaptureJpg)
	ON_BN_CLICKED(IDC_BUTTON_FEC_DISENABLE, &CLS_FECDlg::OnBnClickedButtonFecDisenable)
	ON_BN_CLICKED(IDC_BUTTON_FEC_TRACK, &CLS_FECDlg::OnBnClickedButtonFecTrack)
END_MESSAGE_MAP()


// CLS_FECDlg message handlers

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

	// TODO:  Add extra initialization here

	m_cboFecPlaceType.AddString("壁装方式");
	m_cboFecPlaceType.AddString("地面安装");
	m_cboFecPlaceType.AddString("顶装方式");
	m_cboFecPlaceType.SetCurSel(2);

	m_edtRadiusLeft.SetLimitText(LEN_16);
	m_edtRadiusRight.SetLimitText(LEN_16);
	m_edtRadiusTop.SetLimitText(LEN_16);
	m_edtRadiusBottom.SetLimitText(LEN_16);
	m_edtWideScanOffset.SetLimitText(LEN_16);
	m_edtPtzPositionX.SetLimitText(LEN_16);
	m_edtPtzPositionY.SetLimitText(LEN_16);

	SetDlgItemInt(IDC_EDIT_FEC_RadiusLeft, DEFAULT_CYCLE_RADIUS_LEFT);
	SetDlgItemInt(IDC_EDIT_FEC_RadiusRight, DEFAULT_CYCLE_RADIUS_RIGHT);
	SetDlgItemInt(IDC_EDIT_FEC_RadiusTop, DEFAULT_CYCLE_RADIUS_TOP);
	SetDlgItemInt(IDC_EDIT_FEC_RadiusBottom, DEFAULT_CYCLE_RADIUS_BOTTOM);
	SetDlgItemInt(IDC_EDIT_FEC_WideScanOffset, DEFAULT_DEGREE);
	SetDlgItemInt(IDC_EDIT_FEC_PTZPositionX, DEFAULT_PTZ_X_POSITIOM);
	SetDlgItemInt(IDC_EDIT_FEC_PTZPositionY, DEFAULT_PTZ_Y_POSITIOM);
	SetDlgItemInt(IDC_EDIT_FEC_PTZ_ZOOM, DEFAULT_PTZ_ZOOM_POSITIOM);
	SetDlgItemInt(IDC_EDIT_PTZ_PTZRstWidth, DEFAULT_PTZ_RST_WIDTH);
	SetDlgItemInt(IDC_EDIT_FEC_PTZRstHeight, DEFAULT_PTZ_RST_HEIGHT);

	m_uiSelectVideoRectID = IDC_STATIC_FISHEYE_VIDEO;

	m_pMainDlg = (CPlayDemo_VCDlg*)AfxGetMainWnd();//获得主窗口的实例指针
	if (NULL == m_pMainDlg)
	{
		return FALSE;
	}

	m_iPlayerID = m_pMainDlg->m_iCurPlayNum;		//设置当前播放的ID
	if (INVALID_ID == m_iPlayerID)
	{
		return FALSE;
	}

	HWND hWnd = ::GetDlgItem(this->GetSafeHwnd(), IDC_STATIC_FISHEYE_VIDEO);
	m_pMainDlg->m_PlaySDK.ResetPlayWnd(m_pMainDlg->m_iCurPlayNum, hWnd);	

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CLS_FECDlg::OnClose()
{
	// TODO: Add your message handler code here and/or call default
	for(int i = WINDOW_FISHEYE; i < WINDOW_MAX; i++)
	{
		if (INVALID_ID == m_tFecWindowPara[i].iFecSubID)
		{
			continue;
		}
		
		m_pMainDlg->m_PlaySDK.DeleteFishEyeCorrect(m_iPlayerID, m_tFecWindowPara[i].iFecSubID);
		m_tFecWindowPara[i].iFecSubID = INVALID_ID;
		m_tFecWindowPara[i].blOpen = false;
	}

	m_pMainDlg->m_PlaySDK.SetFishEyeCorrectEnable(m_iPlayerID, 0, NULL);

	m_blStartTrack = false;

	CDialog::OnClose();
}

void CLS_FECDlg::OnStnClickedStaticFisheyeVideo()
{
	DrawRectangleByVideoRect(IDC_STATIC_FISHEYE_VIDEO);
	m_iSelectSubId = m_tFecWindowPara[WINDOW_FISHEYE].iFecSubID;
}

void CLS_FECDlg::OnStnClickedStatic360Video()
{
	DrawRectangleByVideoRect(IDC_STATIC_360_VIDEO);
	m_iSelectSubId = m_tFecWindowPara[WINDOW_360].iFecSubID;
}

void CLS_FECDlg::OnStnClickedStatic180Video()
{
	DrawRectangleByVideoRect(IDC_STATIC_180_VIDEO);
	m_iSelectSubId = m_tFecWindowPara[WINDOW_180].iFecSubID;
}

void CLS_FECDlg::OnStnClickedStaticPtzVideo1()
{
	DrawRectangleByVideoRect(IDC_STATIC_PTZ_VIDEO1);
	m_iSelectSubId = m_tFecWindowPara[WINDOW_PTZ1].iFecSubID;
}

void CLS_FECDlg::OnStnClickedStaticPtzVideo2()
{
	DrawRectangleByVideoRect(IDC_STATIC_PTZ_VIDEO2);
	m_iSelectSubId = m_tFecWindowPara[WINDOW_PTZ2].iFecSubID;
}

void CLS_FECDlg::OnBnClickedButtonSetCyclePara()
{
	if (m_iSelectSubId < 0)
	{
		MessageBox("请先开启鱼眼裁剪，并且选中鱼眼窗体！");
		return;
	}

	CorrectCyclePara tCyclePara = {0};
	tCyclePara.iSize = sizeof(CorrectCyclePara);
	tCyclePara.iRadiusLeft = GetDlgItemInt(IDC_EDIT_FEC_RadiusLeft);
	tCyclePara.iRadiusRight = GetDlgItemInt(IDC_EDIT_FEC_RadiusRight);
	tCyclePara.iRadiusTop = GetDlgItemInt(IDC_EDIT_FEC_RadiusTop);
	tCyclePara.iRadiusBottom = GetDlgItemInt(IDC_EDIT_FEC_RadiusBottom);
	m_pMainDlg->m_PlaySDK.SetFishEyeCorrectPara(m_iPlayerID, m_iSelectSubId, CMD_CORRECT_CYCLERADIUS, &tCyclePara, sizeof(CorrectCyclePara));
}

void CLS_FECDlg::OnBnClickedButtonSetWidescanoffset()
{
	if (m_iSelectSubId < 0)
	{
		MessageBox("请先开启360或180矫正，并且选中360或180窗体！");
		return;
	}

	CorrectWideScanPara tWideScanOffset = {0};
	tWideScanOffset.iSize = sizeof(CorrectWideScanPara);
	tWideScanOffset.fWideScanOffset= (float)GetDlgItemInt(IDC_EDIT_FEC_WideScanOffset);
	m_pMainDlg->m_PlaySDK.SetFishEyeCorrectPara(m_iPlayerID, m_iSelectSubId, CMD_CORRECT_WIDESCANOFFSET, &tWideScanOffset, sizeof(CorrectWideScanPara));
}

void CLS_FECDlg::OnBnClickedButtonSetPtzPosition()
{
	if (m_iSelectSubId < 0)
	{
		MessageBox("请先开启PTZ1或PTZ2矫正，并且选中PTZ1或PTZ2窗体！");
		return;
	}

	CorrectPtzPara tPtzPara = {0};
	tPtzPara.iSize = sizeof(CorrectPtzPara);
	tPtzPara.iPTZPositionX = GetDlgItemInt(IDC_EDIT_FEC_PTZPositionX);
	tPtzPara.iPTZPositionY = GetDlgItemInt(IDC_EDIT_FEC_PTZPositionY);
	tPtzPara.iZoom = GetDlgItemInt(IDC_EDIT_FEC_PTZ_ZOOM);
	tPtzPara.iPTZRstWidth = GetDlgItemInt(IDC_EDIT_PTZ_PTZRstWidth);
	tPtzPara.iPTZRstHeight = GetDlgItemInt(IDC_EDIT_FEC_PTZRstHeight);
	tPtzPara.iPTZRetType = PTZ_RET_TYPE_NONE;
	m_pMainDlg->m_PlaySDK.SetFishEyeCorrectPara(m_iPlayerID, m_iSelectSubId, CMD_CORRECT_PTZPARA, &tPtzPara, sizeof(CorrectPtzPara));
}

void CLS_FECDlg::OnStnDblclickStaticFisheyeVideo()
{
	int iFECEnable = INVALID_ID;
	int iPlaceType = m_cboFecPlaceType.GetCurSel() + 1;
	m_pMainDlg->m_PlaySDK.GetFishEyeCorrectEnable(m_iPlayerID, &iFECEnable);
	if (iFECEnable != FEC_ENABLE)
	{
		iFECEnable = FEC_ENABLE;
		HWND hWnd = ::GetDlgItem(this->GetSafeHwnd(), IDC_STATIC_FISHEYE_VIDEO);
		int iPlaceType = m_cboFecPlaceType.GetCurSel() + 1;
		CreateCorrectPara tCreateCorrectPara = {0};
		tCreateCorrectPara.iSize = sizeof(CreateCorrectPara);
		tCreateCorrectPara.iPlaceType = iPlaceType;
		tCreateCorrectPara.tCycleRadius.iSize = sizeof(CorrectCyclePara);
		tCreateCorrectPara.tCycleRadius.iRadiusLeft = GetDlgItemInt(IDC_EDIT_FEC_RadiusLeft);
		tCreateCorrectPara.tCycleRadius.iRadiusRight = GetDlgItemInt(IDC_EDIT_FEC_RadiusRight);
		tCreateCorrectPara.tCycleRadius.iRadiusTop = GetDlgItemInt(IDC_EDIT_FEC_RadiusTop);
		tCreateCorrectPara.tCycleRadius.iRadiusBottom = GetDlgItemInt(IDC_EDIT_FEC_RadiusBottom);
		tCreateCorrectPara.hWnd = hWnd;
		m_tFecWindowPara[WINDOW_FISHEYE].iFecSubID = m_pMainDlg->m_PlaySDK.SetFishEyeCorrectEnable(m_iPlayerID, iFECEnable, &tCreateCorrectPara);
	}
}

void CLS_FECDlg::OnStnDblclickStatic360Video()
{
	if (m_tFecWindowPara[WINDOW_360].blOpen)
	{
		m_pMainDlg->m_PlaySDK.DeleteFishEyeCorrect(m_iPlayerID, m_tFecWindowPara[WINDOW_360].iFecSubID);
		m_tFecWindowPara[WINDOW_360].blOpen = false;
	}
	else
	{
		HWND hWnd = ::GetDlgItem(this->GetSafeHwnd(), IDC_STATIC_360_VIDEO);
		int iPlaceType = m_cboFecPlaceType.GetCurSel() + 1;
		CreateCorrectPara tCreateCorrectPara = {0};
		tCreateCorrectPara.iSize = sizeof(CreateCorrectPara);
		tCreateCorrectPara.iPlaceType = iPlaceType;
		tCreateCorrectPara.iCorrectType = FEC_CORRECT_360;
		tCreateCorrectPara.tWideScanPara.iSize = sizeof(CorrectWideScanPara);
		tCreateCorrectPara.tWideScanPara.fWideScanOffset= (float)GetDlgItemInt(IDC_EDIT_FEC_WideScanOffset);
		tCreateCorrectPara.hWnd = hWnd;
		m_tFecWindowPara[WINDOW_360].iFecSubID = m_pMainDlg->m_PlaySDK.CreateFishEyeCorrect(m_iPlayerID, &tCreateCorrectPara, sizeof(CreateCorrectPara));
		m_tFecWindowPara[WINDOW_360].blOpen = true;
	}
}

void CLS_FECDlg::OnStnDblclickStatic180Video()
{
	if (m_tFecWindowPara[WINDOW_180].blOpen)
	{
		m_pMainDlg->m_PlaySDK.DeleteFishEyeCorrect(m_iPlayerID, m_tFecWindowPara[WINDOW_180].iFecSubID);
		m_tFecWindowPara[WINDOW_180].blOpen = false;
	}
	else
	{
		HWND hWnd = ::GetDlgItem(this->GetSafeHwnd(), IDC_STATIC_180_VIDEO);
		int iPlaceType = m_cboFecPlaceType.GetCurSel() + 1;
		CreateCorrectPara tCreateCorrectPara = {0};
		tCreateCorrectPara.iSize = sizeof(CreateCorrectPara);
		tCreateCorrectPara.iPlaceType = iPlaceType;
		tCreateCorrectPara.iCorrectType = FEC_CORRECT_180;
		tCreateCorrectPara.tWideScanPara.iSize = sizeof(CorrectWideScanPara);
		tCreateCorrectPara.tWideScanPara.fWideScanOffset= (float)GetDlgItemInt(IDC_EDIT_FEC_WideScanOffset);
		tCreateCorrectPara.hWnd = hWnd;
		m_tFecWindowPara[WINDOW_180].iFecSubID = m_pMainDlg->m_PlaySDK.CreateFishEyeCorrect(m_iPlayerID, &tCreateCorrectPara, sizeof(CreateCorrectPara));
		m_tFecWindowPara[WINDOW_180].blOpen = true;

		m_pMainDlg->m_PlaySDK.SetFishEyeCorrectCallBack(m_iPlayerID, m_tFecWindowPara[WINDOW_180].iFecSubID, &CLS_FECDlg::FishEyeCallBack, this);
	}
}

void CLS_FECDlg::OnStnDblclickStaticPtzVideo1()
{
	if (m_tFecWindowPara[WINDOW_PTZ1].blOpen)
	{
		m_pMainDlg->m_PlaySDK.DeleteFishEyeCorrect(m_iPlayerID, m_tFecWindowPara[WINDOW_PTZ1].iFecSubID);
		m_tFecWindowPara[WINDOW_PTZ1].blOpen = false;
	}
	else
	{
		HWND hWnd = ::GetDlgItem(this->GetSafeHwnd(), IDC_STATIC_PTZ_VIDEO1);
		int iPlaceType = m_cboFecPlaceType.GetCurSel() + 1;
		CreateCorrectPara tCreateCorrectPara = {0};
		tCreateCorrectPara.iSize = sizeof(CreateCorrectPara);
		tCreateCorrectPara.iPlaceType = iPlaceType;
		tCreateCorrectPara.iCorrectType = FEC_CORRECT_PTZ;
		tCreateCorrectPara.tPtzPara.iSize = sizeof(CorrectPtzPara);
		tCreateCorrectPara.tPtzPara.iPtzID = 0;
		tCreateCorrectPara.tPtzPara.iPTZPositionX = GetDlgItemInt(IDC_EDIT_FEC_PTZPositionX);
		tCreateCorrectPara.tPtzPara.iPTZPositionY = GetDlgItemInt(IDC_EDIT_FEC_PTZPositionY);
		tCreateCorrectPara.tPtzPara.iZoom = GetDlgItemInt(IDC_EDIT_FEC_PTZ_ZOOM);
		tCreateCorrectPara.tPtzPara.iPTZRstWidth = GetDlgItemInt(IDC_EDIT_PTZ_PTZRstWidth);
		tCreateCorrectPara.tPtzPara.iPTZRstHeight = GetDlgItemInt(IDC_EDIT_FEC_PTZRstHeight);
		tCreateCorrectPara.tPtzPara.iPTZRetType = PTZ_RET_TYPE_NONE;
		tCreateCorrectPara.hWnd = hWnd;
		m_tFecWindowPara[WINDOW_PTZ1].iFecSubID = m_pMainDlg->m_PlaySDK.CreateFishEyeCorrect(m_iPlayerID, &tCreateCorrectPara, sizeof(CreateCorrectPara));
		m_tFecWindowPara[WINDOW_PTZ1].blOpen = true;
	}
}

void CLS_FECDlg::OnStnDblclickStaticPtzVideo2()
{
	if (m_tFecWindowPara[WINDOW_PTZ2].blOpen)
	{
		m_pMainDlg->m_PlaySDK.DeleteFishEyeCorrect(m_iPlayerID, m_tFecWindowPara[WINDOW_PTZ2].iFecSubID);
		m_tFecWindowPara[WINDOW_PTZ2].blOpen = false;
	}
	else
	{
		HWND hWnd = ::GetDlgItem(this->GetSafeHwnd(), IDC_STATIC_PTZ_VIDEO2);
		int iPlaceType = m_cboFecPlaceType.GetCurSel() + 1;
		CreateCorrectPara tCreateCorrectPara = {0};
		tCreateCorrectPara.iSize = sizeof(CreateCorrectPara);
		tCreateCorrectPara.iPlaceType = iPlaceType;
		tCreateCorrectPara.iCorrectType = FEC_CORRECT_PTZ;
		tCreateCorrectPara.tPtzPara.iSize = sizeof(CorrectPtzPara);
		tCreateCorrectPara.tPtzPara.iPtzID = 1;
		tCreateCorrectPara.tPtzPara.iPTZPositionX = GetDlgItemInt(IDC_EDIT_FEC_PTZPositionX);
		tCreateCorrectPara.tPtzPara.iPTZPositionY = GetDlgItemInt(IDC_EDIT_FEC_PTZPositionY);
		tCreateCorrectPara.tPtzPara.iZoom = GetDlgItemInt(IDC_EDIT_FEC_PTZ_ZOOM);
		tCreateCorrectPara.tPtzPara.iPTZRstWidth = GetDlgItemInt(IDC_EDIT_PTZ_PTZRstWidth);
		tCreateCorrectPara.tPtzPara.iPTZRstHeight = GetDlgItemInt(IDC_EDIT_FEC_PTZRstHeight);
		tCreateCorrectPara.tPtzPara.iPTZRetType = PTZ_RET_TYPE_NONE;
		tCreateCorrectPara.hWnd = hWnd;
		m_tFecWindowPara[WINDOW_PTZ2].iFecSubID = m_pMainDlg->m_PlaySDK.CreateFishEyeCorrect(m_iPlayerID, &tCreateCorrectPara, sizeof(CreateCorrectPara));
		m_tFecWindowPara[WINDOW_PTZ2].blOpen = true;
	}
}

void CLS_FECDlg::DrawRectangleByVideoRect(unsigned int _uiRectID)
{
	//清除前一个窗口的边框
	HWND hPreWnd = ::GetDlgItem(this->GetSafeHwnd(), m_uiSelectVideoRectID);
	HDC hPreDC = ::GetDC(hPreWnd);	//获得窗口画图的HDC对象	
	HPEN hPrePen = CreatePen(PS_ALTERNATE, 1, RGB(255, 255, 255));//创建画笔	
	SelectObject(hPreDC, hPrePen);//选择画笔
	RECT fRect = {0};
	::GetClientRect(hPreWnd, &fRect);//获得绘图区域
	OffsetRect(&fRect, -fRect.left, -fRect.top);//进行区域偏移
	//进行矩形绘制
	fRect.left -= 1;
	fRect.top -= 1;
	MoveToEx(hPreDC, fRect.left, fRect.top, NULL);
	LineTo(hPreDC, fRect.right, fRect.top);
	LineTo(hPreDC, fRect.right, fRect.bottom);
	LineTo(hPreDC, fRect.left, fRect.bottom);
	LineTo(hPreDC, fRect.left, fRect.top);
	DeleteObject(hPrePen);//销毁画笔对象
	::ReleaseDC(GetSafeHwnd(), hPreDC);//释放画图对象hDC


	m_uiSelectVideoRectID = _uiRectID;
	//为当前窗口添加新边框
	HWND hCurWnd = ::GetDlgItem(this->GetSafeHwnd(), _uiRectID);
	HDC hCurDC = ::GetDC(hCurWnd);	//获得窗口画图的HDC对象	
	HPEN hCurPen = CreatePen(PS_ALTERNATE, 1, RGB(255,0,0));//创建红色画笔	
	SelectObject(hCurDC, hCurPen);//选择画笔
	memset(&fRect, 0, sizeof(fRect));
	::GetClientRect(hCurWnd, &fRect);//获得绘图区域
	OffsetRect(&fRect, -fRect.left, -fRect.top);//进行区域偏移
	//进行矩形绘制
	fRect.left -= 1;
	fRect.top -= 1;
	MoveToEx(hCurDC, fRect.left, fRect.top,NULL);
	LineTo(hCurDC, fRect.right, fRect.top);
	LineTo(hCurDC, fRect.right, fRect.bottom);
	LineTo(hCurDC, fRect.left, fRect.bottom);
	LineTo(hCurDC, fRect.left, fRect.top);
	DeleteObject(hCurPen);//销毁画笔对象
	::ReleaseDC(GetSafeHwnd(), hCurDC);//释放画图对象hDC
}

void CLS_FECDlg::OnBnClickedButtonFecCaptureBmp()
{
	if (m_iPlayerID < 0 || m_iSelectSubId < 0)
	{
		return;
	}

	time_t timer = time(NULL);
	struct tm *tblock = localtime(&timer);
	int iYear = tblock->tm_year+1900;
	int iMonth = tblock->tm_mon+1;
	int iDay = tblock->tm_mday;
	int iHour = tblock->tm_hour;
	int iMin = tblock->tm_min;
	int iSec = tblock->tm_sec;

	char cFilePath[LEN_128] = {0};
	char cFileName[LEN_256] = {0};
	sprintf(cFilePath, "D:\\PlayDemo_Capture");
	sprintf(cFileName, "D:\\PlayDemo_Capture\\%04d-%02d-%02d-%02d-%02d-%02d.bmp", iYear, iMonth, iDay, iHour, iMin, iSec);
	if (!PathIsDirectory(cFilePath))
	{
		CreateDirectory(cFilePath, NULL);
	}

	int iRet = m_pMainDlg->m_PlaySDK.CapturePictureEx(m_iPlayerID, CAPTURE_PICTURE_TYPE_FEC_BMP, m_iSelectSubId, cFileName);
	if (iRet > 0)
	{
		MessageBox("FEC Capture BMP success!");
	}
	else
	{
		MessageBox("FEC Capture BMP failed!");
	}
}

void CLS_FECDlg::OnBnClickedButtonFecCaptureJpg()
{
	if (m_iPlayerID < 0 || m_iSelectSubId < 0)
	{
		return;
	}

	time_t timer = time(NULL);
	struct tm *tblock = localtime(&timer);
	int iYear = tblock->tm_year+1900;
	int iMonth = tblock->tm_mon+1;
	int iDay = tblock->tm_mday;
	int iHour = tblock->tm_hour;
	int iMin = tblock->tm_min;
	int iSec = tblock->tm_sec;

	char cFilePath[LEN_128] = {0};
	char cFileName[LEN_256] = {0};
	sprintf(cFilePath, "D:\\PlayDemo_Capture");
	sprintf(cFileName, "D:\\PlayDemo_Capture\\%04d-%02d-%02d-%02d-%02d-%02d.jpg", iYear, iMonth, iDay, iHour, iMin, iSec);
	if (!PathIsDirectory(cFilePath))
	{
		CreateDirectory(cFilePath, NULL);
	}

	int iRet = m_pMainDlg->m_PlaySDK.CapturePictureEx(m_iPlayerID, CAPTURE_PICTURE_TYPE_FEC_JPG, m_iSelectSubId, cFileName);
	if (iRet > 0)
	{
		MessageBox("FEC Capture JPG success!");
	}
	else
	{
		MessageBox("FEC Capture JPG failed!");
	}
}

void CLS_FECDlg::FishEyeCallBack(int _iID, int _iSubID, HDC _pvDC, unsigned int _uiWidth, unsigned int _uiHeight, void* _pvUsrData)
{
	CLS_FECDlg* pThis = (CLS_FECDlg*)_pvUsrData;;
	char cInfo[LEN_512] = {0};
	sprintf(cInfo, "ID(%d)-SubID(%d)-DC(%0x)-Width(%d)-Height(%d)-UData(%0x)\n", _iID, _iSubID, _pvDC, _uiWidth, _uiHeight, pThis);
	//OutputDebugString(cInfo);
}

void CLS_FECDlg::OnBnClickedButtonFecDisenable()
{
	int iFECEnable = INVALID_ID;
	m_pMainDlg->m_PlaySDK.GetFishEyeCorrectEnable(m_iPlayerID, &iFECEnable);
	if (iFECEnable != FEC_DISENABLE)
	{

		iFECEnable = FEC_DISENABLE;
		 m_pMainDlg->m_PlaySDK.SetFishEyeCorrectEnable(m_iPlayerID, iFECEnable, NULL);

		for (int i = 0; i < MAX_FEC_WINDOWS_COUNT; i++)
		{
			m_tFecWindowPara[i].iFecSubID = INVALID_ID;
			m_tFecWindowPara[i].blOpen = false;
		}
		m_iSelectSubId = INVALID_ID;
	}
}

void CLS_FECDlg::OnBnClickedButtonFecTrack()
{
	int iRet = -1;
	if (!m_blStartTrack)
	{
		FECTrackInfo tTrack = {0};
		tTrack.iSize = sizeof(FECTrackInfo);
		tTrack.iWindowCount = 2;
		tTrack.iPtzSubID[0] = m_tFecWindowPara[WINDOW_PTZ1].iFecSubID;
		tTrack.iPtzSubID[1] = m_tFecWindowPara[WINDOW_PTZ2].iFecSubID;
		iRet = m_pMainDlg->m_PlaySDK.StartFECTrack(m_iPlayerID, &tTrack, sizeof(FECTrackInfo), -1);
		if (iRet < 0)
		{
			MessageBox("开启跟踪失败!");
			return;
		}
		m_blStartTrack = true;
		GetDlgItem(IDC_BUTTON_FEC_TRACK)->SetWindowText("关闭跟踪");
	}
	else
	{
		iRet = m_pMainDlg->m_PlaySDK.StopFECTrack(m_iPlayerID);
		if (iRet < 0)
		{
			MessageBox("停止跟踪失败!");
			return;
		}
		m_blStartTrack = false;
		GetDlgItem(IDC_BUTTON_FEC_TRACK)->SetWindowText("开启跟踪");
	}
}
