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

#include "stdafx.h"
#include "By5000Asiplay Demo.h"
#include "CurVideoDlg.h"
#include ".\curvideodlg.h"
#include "By5000asiplay.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CCurVideoDlg 对话框

IMPLEMENT_DYNAMIC(CCurVideoDlg, CDialog)
CCurVideoDlg::CCurVideoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCurVideoDlg::IDD, pParent)
	, m_uiCardNumber(0),m_bEnableSetDvdInfo(FALSE),m_bEnableSetAudioInfo(FALSE),uiLastDvdsubnum(0),uiLastDvdaudionum(0)
{
}

CCurVideoDlg::~CCurVideoDlg()
{
	//KillTimer(m_IDTimer);
}

void CCurVideoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SCROLLBAR_MEDIA_CONTRAST, m_scrollbar_contrast);
	DDX_Control(pDX, IDC_SCROLLBAR_MEDIA_LIGHT, m_scrollbar_light);
	DDX_Control(pDX, IDC_SCROLLBAR_MEDIA_HUE, m_scrollbar_hue);
	DDX_Control(pDX, IDC_SCROLLBAR_MEDIA_SATUATION, m_scrollbar_satuation);
}


BEGIN_MESSAGE_MAP(CCurVideoDlg, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_WM_TIMER()
	
	/*ON_BN_CLICKED(IDC_BUTTON_WINPOS_SET, &CCurVideoDlg::OnBnClickedButtonWinposSet)
	ON_BN_CLICKED(IDC_BUTTON_SET_SEEK, &CCurVideoDlg::OnBnClickedButtonSetSeek)
	ON_BN_CLICKED(IDC_BUTTON_SET_MOSAIC, &CCurVideoDlg::OnBnClickedButtonSetMosaic)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR_MOSAIC, &CCurVideoDlg::OnBnClickedButtonClearMosaic)
	ON_BN_CLICKED(IDC_BUTTON_FADEOUT, &CCurVideoDlg::OnBnClickedButtonFadeout)
	ON_BN_CLICKED(IDC_BUTTON_SET_BACKGROUND_PICTURE, &CCurVideoDlg::OnBnClickedButtonSetBackgroundPicture)
	ON_BN_CLICKED(IDC_BUTTON_RECORDER_PLAYBACK_PIC, &CCurVideoDlg::OnBnClickedButtonRecorderPlaybackPic)
	ON_BN_CLICKED(IDC_BUTTON_CG_SWITCH, &CCurVideoDlg::OnBnClickedButtonCgSwitch)*/
	
	ON_BN_CLICKED(IDC_BUTTON_WINPOS_SET, OnBnClickedButtonWinposSet)
	ON_BN_CLICKED(IDC_BUTTON_SET_SEEK, OnBnClickedButtonSetSeek)
	ON_BN_CLICKED(IDC_BUTTON_SET_MOSAIC, OnBnClickedButtonSetMosaic)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR_MOSAIC, OnBnClickedButtonClearMosaic)
	ON_BN_CLICKED(IDC_BUTTON_FADEOUT, OnBnClickedButtonFadeout)
	ON_BN_CLICKED(IDC_BUTTON_SET_BACKGROUND_PICTURE, OnBnClickedButtonSetBackgroundPicture)
	ON_BN_CLICKED(IDC_BUTTON_RECORDER_PLAYBACK_PIC, OnBnClickedButtonRecorderPlaybackPic)
	ON_BN_CLICKED(IDC_BUTTON_CG_SWITCH, OnBnClickedButtonCgSwitch)
	ON_CBN_SELCHANGE(IDC_COMBO_VIDEO_LAYER_OVERLAY, OnCbnSelchangeComboVideoLayerOverlay)
	ON_WM_HSCROLL()
	//ON_BN_CLICKED(IDC_BUTTON_SUBPICTURE_INDEX2, OnBnClickedButtonSubpictureIndex2)
	//ON_BN_CLICKED(IDC_BUTTON_DVD_AUDIO_INDEX, OnBnClickedButtonDvdAudioIndex)
	ON_CBN_SELCHANGE(IDC_EDIT_SUBPICTURE_INDEX2, OnCbnSelchangeEditSubpictureIndex2)
	ON_CBN_SELCHANGE(IDC_EDIT_DVD_AUDIO_INDEX, OnCbnSelchangeEditDvdAudioIndex)
	ON_BN_CLICKED(IDC_BUTTON_FRONT_FRAME, OnBnClickedButtonFrontFrame)
	ON_BN_CLICKED(IDC_BUTTON_NEXT_FRAME, OnBnClickedButtonNextFrame)
END_MESSAGE_MAP()

// CCurVideoDlg 消息处理程序

void CCurVideoDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
//	OnOK();
}

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


	// TODO:  Add extra initialization here
	m_bEnableCgOverlay = TRUE;
	((CComboBox *)GetDlgItem(IDC_COMBO_VIDEO_LAYER_OVERLAY))->AddString(_T("MediaOverCapture"));
	((CComboBox *)GetDlgItem(IDC_COMBO_VIDEO_LAYER_OVERLAY))->AddString(_T("CaptureOverMedia"));
	((CComboBox *)GetDlgItem(IDC_COMBO_VIDEO_LAYER_OVERLAY))->SetCurSel(0);


	((CComboBox *)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->SetCurSel(0);
	UINT uiTemp;
	Seekfit_By5000asiplay_GetVideoMode(uiTemp, m_uiCardNumber);
	m_uiVideoMode = uiTemp;

	((CEdit *)GetDlgItem(IDC_EDIT_SRCX))->SetWindowText(_T("0"));
	((CEdit *)GetDlgItem(IDC_EDIT_SRCY))->SetWindowText(_T("0"));
	((CEdit *)GetDlgItem(IDC_EDIT_SRC_WIDTH))->SetWindowText(_T("0"));
	if (m_uiVideoMode == VIDEO_MODE_PAL)
		((CEdit *)GetDlgItem(IDC_EDIT_SRC_HEIGHT))->SetWindowText(_T("0"));
	else 
		((CEdit *)GetDlgItem(IDC_EDIT_SRC_HEIGHT))->SetWindowText(_T("0"));
	((CEdit *)GetDlgItem(IDC_EDIT_DSTX))->SetWindowText(_T("0"));
	((CEdit *)GetDlgItem(IDC_EDIT_DSTY))->SetWindowText(_T("0"));
	((CEdit *)GetDlgItem(IDC_EDIT_DST_WIDTH))->SetWindowText(_T("720"));
	if (m_uiVideoMode == VIDEO_MODE_PAL)
		((CEdit *)GetDlgItem(IDC_EDIT_DST_HEIGHT))->SetWindowText(_T("576"));
	else
		((CEdit *)GetDlgItem(IDC_EDIT_DST_HEIGHT))->SetWindowText(_T("480"));

	SetDlgItemText(IDC_EDIT_SUBPICTURE_INDEX2, _T("0"));
	SetDlgItemText(IDC_EDIT_DVD_AUDIO_INDEX, _T("0"));

	SetDlgItemText(IDC_EDIT_SEEK_IN_HOUR, _T("00"));
	SetDlgItemText(IDC_EDIT_SEEK_IN_MINUTE, _T("00"));
	SetDlgItemText(IDC_EDIT_SEEK_IN_SECOND, _T("00"));
	SetDlgItemText(IDC_EDIT_SEEK_IN_FRAME, _T("00"));

	SetDlgItemText(IDC_EDIT_SEEK_OUT_HOUR, _T("00"));
	SetDlgItemText(IDC_EDIT_SEEK_OUT_MINUTE, _T("00"));
	SetDlgItemText(IDC_EDIT_SEEK_OUT_SECOND, _T("00"));
	SetDlgItemText(IDC_EDIT_SEEK_OUT_FRAME, _T("00"));

	SetDlgItemText(IDC_EDIT_MOSAIC_XSTART, _T("50"));
	SetDlgItemText(IDC_EDIT_MOSAIC_YSTART, _T("50"));
	SetDlgItemText(IDC_EDIT_MOSAIC_WIDTH, _T("150"));
	SetDlgItemText(IDC_EDIT_MOSAIC_HEIGHT, _T("100"));
	SetDlgItemText(IDC_EDIT_MOSAIC_PARTICLE_SIZE, _T("30"));

	CString strItem;
	UINT pos=128;
	m_scrollbar_contrast.SetScrollRange( 0, CONTRAST_RANGE - 1);
	m_scrollbar_contrast.SetScrollPos( pos );
	strItem.Format(_T("C:%d"),pos);
	GetDlgItem(IDC_STATIC_CONTRAST)->SetWindowText(strItem);

	m_scrollbar_light.SetScrollRange( 0, CONTRAST_RANGE - 1);
	m_scrollbar_light.SetScrollPos( pos );
	strItem.Format(_T("L:%d"),pos);
	GetDlgItem(IDC_STATIC_LIGHT)->SetWindowText(strItem);

	m_scrollbar_hue.SetScrollRange( 0, CONTRAST_RANGE - 1);
	m_scrollbar_hue.SetScrollPos( pos );
	strItem.Format(_T("H:%d"),pos);
	GetDlgItem(IDC_STATIC_HUE)->SetWindowText(strItem);

	m_scrollbar_satuation.SetScrollRange( 0, CONTRAST_RANGE - 1);
	m_scrollbar_satuation.SetScrollPos( pos );
	strItem.Format(_T("S:%d"),pos);
	GetDlgItem(IDC_STATIC_SATUATION)->SetWindowText(strItem);


	SetTimer(1,20,NULL);

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

void CCurVideoDlg::OnBnClickedButtonWinposSet()
{
	// TODO: Add your control notification handler code here
	CString strText;
	UINT uiXStart,uiYStart,uiWidth,uiHeight;
	uiXStart=uiYStart=uiWidth=uiHeight = 0;

	Seekfit_By5000asiplay_MediaEnablePlaybackDve(m_uiCardNumber);
	((CEdit *)GetDlgItem(IDC_EDIT_SRCX))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiXStart);

#else
	sscanf_s(strText,_T("%d"),&uiXStart);
#endif
	((CEdit *)GetDlgItem(IDC_EDIT_SRCY))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiYStart);

#else
	sscanf_s(strText,_T("%d"),&uiYStart);
#endif
	((CEdit *)GetDlgItem(IDC_EDIT_SRC_WIDTH))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiWidth);

#else
	sscanf_s(strText,_T("%d"),&uiWidth);
#endif
	((CEdit *)GetDlgItem(IDC_EDIT_SRC_HEIGHT))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiHeight);

#else
	sscanf_s(strText,_T("%d"),&uiHeight);
#endif
	Seekfit_By5000asiplay_MediaSetDveSourceWindow(uiXStart,uiYStart,uiWidth,uiHeight,m_uiCardNumber);

	((CEdit *)GetDlgItem(IDC_EDIT_DSTX))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiXStart);

#else
	sscanf_s(strText,_T("%d"),&uiXStart);
#endif
	((CEdit *)GetDlgItem(IDC_EDIT_DSTY))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiYStart);

#else
	sscanf_s(strText,_T("%d"),&uiYStart);
#endif
	((CEdit *)GetDlgItem(IDC_EDIT_DST_WIDTH))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiWidth);

#else
	sscanf_s(strText,_T("%d"),&uiWidth);
#endif
	((CEdit *)GetDlgItem(IDC_EDIT_DST_HEIGHT))->GetWindowText(strText);
#ifdef _UNICODE
	swscanf_s(strText,_T("%d"),&uiHeight);

#else
	sscanf_s(strText,_T("%d"),&uiHeight);
#endif
	Seekfit_By5000asiplay_MediaSetDveDestWindow(uiXStart,uiYStart,uiWidth,uiHeight,m_uiCardNumber);
}

void CCurVideoDlg::OnBnClickedButtonSetSeek()
{
	// TODO: Add your control notification handler code here
	UINT uiHour;
	UINT uiMinute;
	UINT uiSecond;
	UINT uiFrame;
	ULONG ulSeekIn;
	ULONG ulSeekOut;
	CString str;

	GetDlgItemText(IDC_EDIT_SEEK_IN_HOUR, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiHour);

#else
	sscanf_s(str, _T("%d"), &uiHour);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_MINUTE, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiMinute);

#else
	sscanf_s(str, _T("%d"), &uiMinute);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_SECOND, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiSecond);

#else
	sscanf_s(str, _T("%d"), &uiSecond);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_FRAME, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiFrame);

#else
	sscanf_s(str, _T("%d"), &uiFrame);
#endif

	if (uiHour >= 256 || uiMinute >= 60 || uiSecond >= 60 || uiFrame >= 60)
	{
		AfxMessageBox(_T("请检查参数设置是否正确！"));
		return;
	}

	ulSeekIn = (uiHour << 24) + (uiMinute << 16) + (uiSecond << 8) + uiFrame;

	GetDlgItemText(IDC_EDIT_SEEK_OUT_HOUR, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiHour);

#else
	sscanf_s(str, _T("%d"), &uiHour);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_MINUTE, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiMinute);

#else
	sscanf_s(str, _T("%d"), &uiMinute);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_SECOND, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiSecond);

#else
	sscanf_s(str, _T("%d"), &uiSecond);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_FRAME, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiFrame);

#else
	sscanf_s(str, _T("%d"), &uiFrame);
#endif

	if (uiHour >= 256 || uiMinute >= 60 || uiSecond >= 60 || uiFrame >= 60)
	{
		AfxMessageBox(_T("请检查参数设置是否正确！"));
		return;
	}

	ulSeekOut = (uiHour << 24) + (uiMinute << 16) + (uiSecond << 8) + uiFrame;

	//	Seekfit_By5000asiplay_MediaPause(m_uiCardNumber);
	Seekfit_By5000asiplay_MediaSeek(ulSeekIn, ulSeekOut, m_uiCardNumber);
	//	Seekfit_By5000asiplay_MediaPlay(m_uiCardNumber);

}

void CCurVideoDlg::OnBnClickedButtonSetMosaic()
{
	// TODO: Add your control notification handler code here
	CString str = _T("");
	UINT uiStartX;
	UINT uiStartY;
	UINT uiWidth;
	UINT uiHeight;
	UINT uiParticleSize;
	struct MOSAIC_RECTANGLE Mosaic;

	GetDlgItemText(IDC_EDIT_MOSAIC_XSTART, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiStartX);

#else
	sscanf_s(str, _T("%d"), &uiStartX);
#endif
	GetDlgItemText(IDC_EDIT_MOSAIC_YSTART, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiStartY);

#else
	sscanf_s(str, _T("%d"), &uiStartY);
#endif
	GetDlgItemText(IDC_EDIT_MOSAIC_WIDTH, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiWidth);

#else
	sscanf_s(str, _T("%d"), &uiWidth);
#endif
	GetDlgItemText(IDC_EDIT_MOSAIC_HEIGHT, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiHeight);

#else
	sscanf_s(str, _T("%d"), &uiHeight);
#endif
	GetDlgItemText(IDC_EDIT_MOSAIC_PARTICLE_SIZE, str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &uiParticleSize);

#else
	sscanf_s(str, _T("%d"), &uiParticleSize);
#endif

	Mosaic.uiStartX = uiStartX;
	Mosaic.uiStartY = uiStartY;
	Mosaic.uiWidth = uiWidth;
	Mosaic.uiHeight = uiHeight;
	Mosaic.uiParticleSize = uiParticleSize;

	Seekfit_By5000asiplay_MediaSetMosaicRectangles(&Mosaic, 1, m_uiCardNumber);
}

void CCurVideoDlg::OnBnClickedButtonClearMosaic()
{
	// TODO: Add your control notification handler code here
	Seekfit_By5000asiplay_MediaSetMosaicRectangles(NULL, 0, m_uiCardNumber);
}

void CCurVideoDlg::OnBnClickedButtonFadeout()
{
	// TODO: Add your control notification handler code here
	INT nEffectDur = 0;
	CString str;
	((CEdit *)GetDlgItem(IDC_EDIT_EFFECT_DUR))->GetWindowText(str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &nEffectDur);

#else
	sscanf_s(str, _T("%d"), &nEffectDur);
#endif
	Seekfit_By5000asiplay_VideoStreamSetTransformEffect(TRANSFORM_EFFECT_FADE_IN_OUT, 0);
	Seekfit_By5000asiplay_VideoStreamSetTransformEffectDuration(nEffectDur,0);
	Seekfit_By5000asiplay_VideoStreamTriggerTransform(0);
}

void CCurVideoDlg::OnBnClickedButtonSetBackgroundPicture()
{
	// TODO: Add your control notification handler code here
	CBitmap * pBitmap ;
	pBitmap = new CBitmap;
	CTgaReader tgaReader;
	BITMAP bm;

	CString strFileName;
	POSITION posFile;
	ULONG *pPicture;

	CFileDialog dlg(TRUE,
		NULL,
		_T("*.tga"),
		OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOREADONLYRETURN,
		_T("Picture Files (*.tga) | *.tga | ")
		_T("All Files (*.*) | *.* ||"));

	if ( dlg.DoModal()==IDOK )
	{
		posFile = dlg.GetStartPosition();
		while( posFile)
		{
			strFileName = dlg.GetNextPathName( posFile );
			tgaReader.LoadImage(strFileName,pBitmap);
			pBitmap->GetBitmap(&bm);
			pPicture = new ULONG[ bm.bmWidth*bm.bmHeight ];
			pBitmap ->GetBitmapBits(bm.bmWidth*bm.bmHeight*4,pPicture);

			Seekfit_By5000asiplay_MediaSetBackgroundPicture(pPicture, m_uiCardNumber);
			delete pPicture;
		}
	}

	delete pBitmap;

}

void CCurVideoDlg::OnBnClickedButtonRecorderPlaybackPic()
{
	// TODO: Add your control notification handler code here
	TCHAR exeFullPath[MAX_PATH];
	
	m_strFileName.TrimLeft();
	m_strFileName.TrimRight();
	UINT uistrFileLenght = m_strFileName.ReverseFind('.');
	CString strcc = m_strFileName.Left(uistrFileLenght);
	
	int Where;
	Where = strcc.ReverseFind('\\'); 
	if (Where == -1) 
		Where = strcc.ReverseFind('/'); 
	CString FileTitle = strcc.Right(strcc.GetLength() - 1 - Where);

	FileTitle+= _T(".bmp");

	GetModuleFileName(NULL,exeFullPath,MAX_PATH);
	int unPathLastIndex;
	CString strDir(exeFullPath);
	strDir.TrimLeft();
	strDir.TrimRight();
	unPathLastIndex = strDir.ReverseFind('\\');
	CString strTemp = strDir.Left(unPathLastIndex+1);
	strDir = strTemp;
	strDir += FileTitle;
	Seekfit_By5000asiplay_RecorderPlaybackFrameToFile(strDir,m_uiCardNumber);

}

void CCurVideoDlg::OnBnClickedButtonCgSwitch()
{
	// TODO: Add your control notification handler code here
	if(m_bEnableCgOverlay)
	{
		((CButton *)(GetDlgItem(IDC_BUTTON_CG_SWITCH)))->SetWindowText(_T("使能字幕"));
		Seekfit_By5000asiplay_DisableCgOverlay(m_uiCardNumber);
		m_bEnableCgOverlay = FALSE;
	}
	else
	{
		((CButton *)(GetDlgItem(IDC_BUTTON_CG_SWITCH)))->SetWindowText(_T("取消字幕"));
		Seekfit_By5000asiplay_EnableCgOverlay(m_uiCardNumber);
		m_bEnableCgOverlay = TRUE;
	}

}
void CCurVideoDlg::OnTimer(UINT nIDEvent)
{

	CString str;
	UINT uiHour;
	UINT uiMinute;
	UINT uiSecond;
	UINT uiFrame;
	//ULONG ulTime;

	Seekfit_By5000asiplay_MediaGetFileInformation(m_mfiMediaFileInformation, m_uiCardNumber);
	uiHour = m_mfiMediaFileInformation.ulTimeDuration >> 24;
	uiMinute = (m_mfiMediaFileInformation.ulTimeDuration >> 16) & 0xff;
	uiSecond = (m_mfiMediaFileInformation.ulTimeDuration >> 8) & 0xff;
	uiFrame = (m_mfiMediaFileInformation.ulTimeDuration >> 0) & 0xff;
	str.Format(_T("%02d:%02d:%02d:%02d"), uiHour, uiMinute, uiSecond, uiFrame);
	GetDlgItem(IDC_FILE_TIME_DURATION)->SetWindowText(str);
	str.Format(_T("%d"), m_mfiMediaFileInformation.uiVideoWidth);
	GetDlgItem(IDC_FILE_WIDTH)->SetWindowText(str);
	//GetDlgItem(IDC_EDIT_SRC_WIDTH)->SetWindowText(str);
	str.Format(_T("%d"), m_mfiMediaFileInformation.uiVideoHeight);
	GetDlgItem(IDC_FILE_HEIGHT)->SetWindowText(str);
	//GetDlgItem(IDC_EDIT_SRC_HEIGHT)->SetWindowText(str);

	if (uiLastDvdsubnum !=m_mfiMediaFileInformation.uiDvdSubPictureNumber)
	{
		m_bEnableSetDvdInfo = FALSE;
		((CComboBox *)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->ResetContent();
		uiLastDvdsubnum =m_mfiMediaFileInformation.uiDvdSubPictureNumber;
	}
	if (uiLastDvdaudionum != m_mfiMediaFileInformation.uiDvdAudioNumber)
	{
		m_bEnableSetAudioInfo = FALSE;
		((CComboBox *)GetDlgItem(IDC_EDIT_DVD_AUDIO_INDEX))->ResetContent();
		uiLastDvdaudionum = m_mfiMediaFileInformation.uiDvdAudioNumber;
	}
	if (!m_bEnableSetDvdInfo||!m_bEnableSetAudioInfo)
	{
		if (m_mfiMediaFileInformation.uiDvdSubPictureNumber>0||m_mfiMediaFileInformation.uiDvdAudioNumber>0)
		{
			for(INT i=0;i<m_mfiMediaFileInformation.uiDvdSubPictureNumber;i++)
			{
				str.Format(_T("%d"),i);
				((CComboBox *)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->AddString(str);
			}
			((CComboBox *)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->SetCurSel(0);
			for(INT i=0;i<m_mfiMediaFileInformation.uiDvdAudioNumber;i++)
			{
				str.Format(_T("%d"),i);
				((CComboBox *)GetDlgItem(IDC_EDIT_DVD_AUDIO_INDEX))->AddString(str);
			}
			((CComboBox *)GetDlgItem(IDC_EDIT_DVD_AUDIO_INDEX))->SetCurSel(0);
		} 
		else
		{
			((CComboBox *)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->AddString(_T("0"));
			((CComboBox *)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->SetCurSel(0);
			((CComboBox *)GetDlgItem(IDC_EDIT_DVD_AUDIO_INDEX))->AddString(_T("0"));
			((CComboBox *)GetDlgItem(IDC_EDIT_DVD_AUDIO_INDEX))->SetCurSel(0);
		}
		m_bEnableSetAudioInfo= TRUE;
		m_bEnableSetDvdInfo = TRUE;
	}
	CDialog::OnTimer(nIDEvent);

}

void CCurVideoDlg::OnCbnSelchangeComboVideoLayerOverlay()
{
	// TODO: 在此添加控件通知处理程序代码
	INT nIndex = ((CComboBox*)GetDlgItem(IDC_COMBO_VIDEO_LAYER_OVERLAY))->GetCurSel();
	if(nIndex == 0)
	{
		Seekfit_By5000asiplay_SetVideoOverlayMode(VIDEO_OVERLAY_MEDIA_OVER_CAPTURE, m_uiCardNumber);
	}
	else if(nIndex == 1)
	{
		Seekfit_By5000asiplay_SetVideoOverlayMode(VIDEO_OVERLAY_CAPTURE_OVER_MEDIA, m_uiCardNumber);
	}
}

void CCurVideoDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	int nCustomPos;
	CString str;
	if( pScrollBar ->m_hWnd == m_scrollbar_contrast.m_hWnd )
	{
		nCustomPos = m_scrollbar_contrast.GetScrollPos();
		if( nSBCode == SB_LINELEFT )
			nCustomPos--;
		else
			if( nSBCode == SB_LINERIGHT )
				nCustomPos++;
			else
				if( nSBCode == SB_PAGELEFT )
					nCustomPos -= 10;
				else
					if( nSBCode == SB_PAGERIGHT )
						nCustomPos += 10;

		if( nCustomPos <= 0 )
			nCustomPos = 0;
		else
			if( nCustomPos >= CONTRAST_RANGE - 1 )
				nCustomPos = CONTRAST_RANGE - 1;

		Seekfit_By5000asiplay_MediaSetContrast( nCustomPos, m_uiCardNumber );

		m_scrollbar_contrast.SetScrollPos(nCustomPos);

		str.Format(_T("C:%d"),nCustomPos);

		GetDlgItem(IDC_STATIC_CONTRAST)->SetWindowText(str);

	}
	else if( pScrollBar ->m_hWnd == m_scrollbar_light.m_hWnd )
	{
		nCustomPos = m_scrollbar_light.GetScrollPos();
		if( nSBCode == SB_LINELEFT )
			nCustomPos--;
		else
			if( nSBCode == SB_LINERIGHT )
				nCustomPos++;
			else
				if( nSBCode == SB_PAGELEFT )
					nCustomPos -= 10;
				else
					if( nSBCode == SB_PAGERIGHT )
						nCustomPos += 10;

		if( nCustomPos <= 0 )
			nCustomPos = 0;
		else
			if( nCustomPos >= LIGHT_RANGE - 1 )
				nCustomPos = LIGHT_RANGE - 1;

		Seekfit_By5000asiplay_MediaSetBrightness( nCustomPos, m_uiCardNumber );

		m_scrollbar_light.SetScrollPos(nCustomPos);

		str.Format(_T("L:%d"),nCustomPos);

		GetDlgItem(IDC_STATIC_LIGHT)->SetWindowText(str);

	}
	else if( pScrollBar ->m_hWnd == m_scrollbar_hue.m_hWnd )
	{
		nCustomPos = m_scrollbar_hue.GetScrollPos();
		if( nSBCode == SB_LINELEFT )
			nCustomPos--;
		else
			if( nSBCode == SB_LINERIGHT )
				nCustomPos++;
			else
				if( nSBCode == SB_PAGELEFT )
					nCustomPos -= 10;
				else
					if( nSBCode == SB_PAGERIGHT )
						nCustomPos += 10;

		if( nCustomPos <= 0 )
			nCustomPos = 0;
		else
			if( nCustomPos >= HUE_RANGE - 1 )
				nCustomPos = HUE_RANGE - 1;

		Seekfit_By5000asiplay_MediaSetHue( nCustomPos, m_uiCardNumber );

		m_scrollbar_hue.SetScrollPos(nCustomPos);

		str.Format(_T("H:%d"),nCustomPos);

		GetDlgItem(IDC_STATIC_HUE)->SetWindowText(str);

	}
	else if( pScrollBar ->m_hWnd == m_scrollbar_satuation.m_hWnd )
	{
		nCustomPos = m_scrollbar_satuation.GetScrollPos();
		if( nSBCode == SB_LINELEFT )
			nCustomPos--;
		else
			if( nSBCode == SB_LINERIGHT )
				nCustomPos++;
			else
				if( nSBCode == SB_PAGELEFT )
					nCustomPos -= 10;
				else
					if( nSBCode == SB_PAGERIGHT )
						nCustomPos += 10;

		if( nCustomPos <= 0 )
			nCustomPos = 0;
		else
			if( nCustomPos >= SATUATION_RANGE - 1 )
				nCustomPos = SATUATION_RANGE - 1;

		Seekfit_By5000asiplay_MediaSetSaturation( nCustomPos, m_uiCardNumber );

		m_scrollbar_satuation.SetScrollPos(nCustomPos);

		str.Format(_T("S:%d"),nCustomPos);

		GetDlgItem(IDC_STATIC_SATUATION)->SetWindowText(str);

	}
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

// void CCurVideoDlg::OnBnClickedButtonSubpictureIndex2()
// {
// 	// TODO: 在此添加控件通知处理程序代码
// 	CString str = _T("");
// 	UINT index=0 ;
// 	((CEdit *)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->GetWindowText(str);
// 	sscanf_s(str,_T("%d"),&index);
// 	Seekfit_By5000asiplay_MediaSetDvdSubPictureIndex(index, m_uiCardNumber);
// }
// 
// void CCurVideoDlg::OnBnClickedButtonDvdAudioIndex()
// {
// 	// TODO: 在此添加控件通知处理程序代码
// 	CString str = _T("");
// 	UINT index=0 ;
// 	((CEdit *)GetDlgItem(IDC_EDIT_DVD_AUDIO_INDEX))->GetWindowText(str);
// 	sscanf_s(str,_T("%d"),&index);
// 	Seekfit_By5000asiplay_MediaSetDvdAudioIndex(index, m_uiCardNumber);
// }

void CCurVideoDlg::OnCbnSelchangeEditSubpictureIndex2()
{
	// TODO: 在此添加控件通知处理程序代码
	INT nIndex = ((CComboBox*)GetDlgItem(IDC_EDIT_SUBPICTURE_INDEX2))->GetCurSel();
	Seekfit_By5000asiplay_MediaSetDvdSubPictureIndex(nIndex, m_uiCardNumber);
	
}

void CCurVideoDlg::OnCbnSelchangeEditDvdAudioIndex()
{
	// TODO: 在此添加控件通知处理程序代码
	INT nIndex = ((CComboBox*)GetDlgItem(IDC_EDIT_DVD_AUDIO_INDEX))->GetCurSel();
	Seekfit_By5000asiplay_MediaSetDvdAudioIndex(nIndex, m_uiCardNumber);
}


void CCurVideoDlg::OnBnClickedButtonFrontFrame()
{
	// TODO: 在此添加控件通知处理程序代码
	UINT uiHour;
	UINT uiMinute;
	UINT uiSecond;
	INT uiFrame;
	ULONG ulSeekIn;
	ULONG ulSeekOut;
	CString str;

	GetDlgItemText(IDC_EDIT_SEEK_IN_HOUR, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiHour);

#else
	sscanf_s(str,_T("%d"),&uiHour);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_MINUTE, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiMinute);

#else
	sscanf_s(str,_T("%d"),&uiMinute);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_SECOND, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiSecond);

#else
	sscanf_s(str,_T("%d"),&uiSecond);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_FRAME, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiFrame);

#else
	sscanf_s(str,_T("%d"),&uiFrame);
#endif

	if (uiHour >= 256 || uiMinute >= 60 || uiSecond >= 60 || uiFrame >= 60)
	{
		AfxMessageBox(_T("请检查参数设置是否正确！"));
		return;
	}
	uiFrame--;
	if (uiFrame <0)
	{
		uiSecond-=1;
		uiFrame = 24;
		ulSeekIn = (uiHour << 24) + (uiMinute << 16) + (uiSecond << 8) + uiFrame;
	}
	else
	{
		ulSeekIn = (uiHour << 24) + (uiMinute << 16) + (uiSecond << 8) + uiFrame;
	}
	str.Format(_T("%d"),uiHour);
	SetDlgItemText(IDC_EDIT_SEEK_IN_HOUR, str);
	str.Format(_T("%d"),uiMinute);
	SetDlgItemText(IDC_EDIT_SEEK_IN_MINUTE, str);
	str.Format(_T("%d"),uiSecond);
	SetDlgItemText(IDC_EDIT_SEEK_IN_SECOND, str);
	str.Format(_T("%d"),uiFrame);
	SetDlgItemText(IDC_EDIT_SEEK_IN_FRAME, str);
	//sscanf_s(str, _T("%d"), &uiFrame);

	GetDlgItemText(IDC_EDIT_SEEK_OUT_HOUR, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiHour);

#else
	sscanf_s(str,_T("%d"),&uiHour);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_MINUTE, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiMinute);

#else
	sscanf_s(str,_T("%d"),&uiMinute);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_SECOND, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiSecond);

#else
	sscanf_s(str,_T("%d"),&uiSecond);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_FRAME, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiFrame);

#else
	sscanf_s(str,_T("%d"),&uiFrame);
#endif
	
	if (uiHour >= 256 || uiMinute >= 60 || uiSecond >= 60 || uiFrame >= 25)
	{
		AfxMessageBox(_T("请检查参数设置是否正确！"));
		return;
	}
	ulSeekOut = (uiHour << 24) + (uiMinute << 16) + (uiSecond << 8) + uiFrame;

	//	Seekfit_By5000asiplay_MediaPause(m_uiCardNumber);
	Seekfit_By5000asiplay_MediaSeek(ulSeekIn, ulSeekOut, m_uiCardNumber);
	//	Seekfit_By5000asiplay_MediaPlay(m_uiCardNumber);

}



void CCurVideoDlg::OnBnClickedButtonNextFrame()
{
	// TODO: 在此添加控件通知处理程序代码
	UINT uiHour;
	UINT uiMinute;
	UINT uiSecond;
	INT uiFrame;
	ULONG ulSeekIn;
	ULONG ulSeekOut;
	CString str;

	GetDlgItemText(IDC_EDIT_SEEK_IN_HOUR, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiHour);

#else
	sscanf_s(str,_T("%d"),&uiHour);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_MINUTE, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiMinute);

#else
	sscanf_s(str,_T("%d"),&uiMinute);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_SECOND, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiSecond);

#else
	sscanf_s(str,_T("%d"),&uiSecond);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_IN_FRAME, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiFrame);

#else
	sscanf_s(str,_T("%d"),&uiFrame);
#endif
	if (uiHour >= 256 || uiMinute >= 60 || uiSecond >= 60 || uiFrame >= 60)
	{
		AfxMessageBox(_T("请检查参数设置是否正确！"));
		return;
	}
	uiFrame++;
	if (uiFrame >25)
	{
		uiSecond+=1;
		uiFrame%=25;
		ulSeekIn = (uiHour << 24) + (uiMinute << 16) + ((uiSecond) << 8) + uiFrame;
	}
	else
	{
		ulSeekIn = (uiHour << 24) + (uiMinute << 16) + (uiSecond << 8) + uiFrame;
	}
	str.Format(_T("%d"),uiHour);
	SetDlgItemText(IDC_EDIT_SEEK_IN_HOUR, str);
	str.Format(_T("%d"),uiMinute);
	SetDlgItemText(IDC_EDIT_SEEK_IN_MINUTE, str);
	str.Format(_T("%d"),uiSecond);
	SetDlgItemText(IDC_EDIT_SEEK_IN_SECOND, str);
	str.Format(_T("%d"),uiFrame);
	SetDlgItemText(IDC_EDIT_SEEK_IN_FRAME, str);
	//sscanf_s(str, _T("%d"), &uiFrame);


	GetDlgItemText(IDC_EDIT_SEEK_OUT_HOUR, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiHour);

#else
	sscanf_s(str,_T("%d"),&uiHour);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_MINUTE, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiMinute);

#else
	sscanf_s(str,_T("%d"),&uiMinute);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_SECOND, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiSecond);

#else
	sscanf_s(str,_T("%d"),&uiSecond);
#endif
	GetDlgItemText(IDC_EDIT_SEEK_OUT_FRAME, str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&uiFrame);

#else
	sscanf_s(str,_T("%d"),&uiFrame);
#endif

	if (uiHour >= 256 || uiMinute >= 60 || uiSecond >= 60 || uiFrame >= 25)
	{
		AfxMessageBox(_T("请检查参数设置是否正确！"));
		return;
	}
	ulSeekOut = (uiHour << 24) + (uiMinute << 16) + (uiSecond << 8) + uiFrame;

	//	Seekfit_By5000asiplay_MediaPause(m_uiCardNumber);
	Seekfit_By5000asiplay_MediaSeek(ulSeekIn, ulSeekOut, m_uiCardNumber);
	//	Seekfit_By5000asiplay_MediaPlay(m_uiCardNumber);
}
