// DlgCfgVout.cpp : implementation file
//

#include "stdafx.h"
#include "NetSdkDemo.h"
#include "DlgCfgVout.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static const char* s_szVoutlist[] = {
	"PAL",			// 0
	"NTSC",			// 1
	"1080P24",		// 2
	"1080P25",		// 3
	"1080P30", 		// 4
	"720P50",		// 5
	"720P60",		// 6
	"1080I50",		// 7
	"1080I60",		// 8
	"1080P50",		// 9
	"1080P60",		// 10
	"576P50",		// 11
	"480P60",		// 12
	"800x600_60",	// 13
	"1024x768_60",	// 14
	"1280x1024_60",// 15
	"1366x768_60",	// 16
	"1440x900_60",	// 17
	"1280x800_60", // 18
	"640x480_60",	// 19
	"1080P59.94",	// 20
	"1080I59.94",	// 21
	"1080P29.97",	// 22
	"720P59.94",	// 23
	"720P29.97",	// 24
	"720P25",		// 25
	"720P30",		// 26
	"720P15"		// 27
};
/////////////////////////////////////////////////////////////////////////////
// CDlgCfgVout dialog


CDlgCfgVout::CDlgCfgVout(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgCfgVout::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgCfgVout)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bGetParam = FALSE;
}


void CDlgCfgVout::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgCfgVout)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgCfgVout, CDialog)
	//{{AFX_MSG_MAP(CDlgCfgVout)
	ON_BN_CLICKED(IDC_BTN_SAVE, OnBtnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgCfgVout message handlers
BOOL CDlgCfgVout::GetEnvParam()
{
	int i, iRet;
	//if(m_bGetParam)
	//	return TRUE;
	iRet = librmconfc_env_get(g_envDev.szIP, g_envDev.wPort, g_envDev.szUserName, g_envDev.szPassword, NULL,
		MRCONFC_ENVCMD_VIDEOOUT, sizeof(MRCONFC_VIDEOOUT_CFG), &m_stVideoOut);
	if(iRet)
	{
		AfxMessageBox("获得参数失败!");
		return FALSE;
	}
	((CComboBox*)GetDlgItem(IDC_CMB_FORMAT))->ResetContent();
	for(i=0; i<m_stVideoOut.nFormatLists; i++)
	{
		((CComboBox*)GetDlgItem(IDC_CMB_FORMAT))->AddString(s_szVoutlist[m_stVideoOut.byFormatList[i]]);
		((CComboBox*)GetDlgItem(IDC_CMB_FORMAT))->SetItemData(i, m_stVideoOut.byFormatList[i]);
	}
	for(i=0; i<m_stVideoOut.nFormatLists; i++)
	{
		if(m_stVideoOut.emVoutFormat == m_stVideoOut.byFormatList[i])
		{
			((CComboBox*)GetDlgItem(IDC_CMB_FORMAT))->SetCurSel(i);
			break;
		}
	}
	m_bGetParam = TRUE;
	return TRUE;
}

void CDlgCfgVout::OnBtnSave() 
{
	int iRet, nSel;
	if(!m_bGetParam)
		return;
	nSel = ((CComboBox*)GetDlgItem(IDC_CMB_FORMAT))->GetCurSel();
	m_stVideoOut.emVoutFormat = ((CComboBox*)GetDlgItem(IDC_CMB_FORMAT))->GetItemData(nSel);
	iRet = librmconfc_env_set(g_envDev.szIP, g_envDev.wPort, g_envDev.szUserName, g_envDev.szPassword, NULL,
		MRCONFC_ENVCMD_VIDEOOUT, sizeof(MRCONFC_VIDEOOUT_CFG), &m_stVideoOut);
	if(iRet)
	{
		AfxMessageBox("保存参数失败!");
		return;
	}
}
