// NetPlayXCtl.cpp : Implementation of the CNetPlayXCtrl ActiveX Control class.

#include "stdafx.h"
#include "NetPlayX.h"
#include "NetPlayXCtl.h"
#include "NetPlayXPpg.h"
#include "lauplaym4.h"
#include "DlgFull.h"
#include "DlgCutStartpos.h"
#include "DlgDownloadFile.h"
#include "DlgDownload.h"
#include "DlgSharppenStrength.h"

#include "lauplaym4.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define TIMERID_CONVT		9
#define TIMERID_SEARCH		10
#define TIMERID_DOWNLOAD	11
#define TIMERID_PLAYBACK	12
#define TIMERID_PLAYSTAY	13

#define MYTIMER_KILL(id)	if(id) {KillTimer(id); id = 0;}
#define PLAYEVENT_MSG		(WM_USER + 200)



typedef struct
{
	char   m_sername[40];
	int    m_chno;
	char   m_filetime[20];
	int    m_filesize;
	char   m_filename[MAX_PATH];
}FILESEARCHITEM;

typedef struct
{
	char   m_sername[40];
	int    m_chno;
	char   m_filetime[20];
	int    m_filesize;
	char   m_filename[MAX_PATH];
	int	   m_islocked;
	int    m_reverseA;
	char   m_reverseB[64];
}FILESEARCHITEM_EX;

/*
typedef struct
{
	char   m_sername[40];
	int    m_chno;
	char   m_filetime[20];
	int    m_filesize;
	char   m_filename[MAX_PATH];
	int	   m_disktype;//5: 录像盘，6: 冗余盘
}FILESEARCHITEM_EX;*/


static void TimeToString(DWORD nAllTime,DWORD nNowTime, char *lpstr)
{
	struct tm *all,*now;
	char   lpstring[30];
	nNowTime = nNowTime / 1000;
	now = gmtime( (time_t*)&nNowTime);
	sprintf(lpstring,"%02d:%02d:%02d/",
		now->tm_hour,now->tm_min,now->tm_sec);
	nAllTime = nAllTime / 1000;
	all = gmtime( (time_t*)&nAllTime);
	sprintf(lpstr,"%s%02d:%02d:%02d",
		lpstring,all->tm_hour,all->tm_min,all->tm_sec);
}

static void DownTimeToString(DWORD nNowTime,char *lpstr)
{
	struct tm *now;
	nNowTime = nNowTime / 1000;
	now = gmtime( (time_t*)&nNowTime);
	sprintf(lpstr,"download %02d:%02d:%02d",
		now->tm_hour,now->tm_min,now->tm_sec);
}

static void TimeToTime(LONG nFileCreateTime,DWORD nAllTime,DWORD nNowTime,COleDateTime *lpAllTime,COleDateTime *lpNowDate,COleDateTime *lpNowTime)
{
	struct tm *all,*now;
	nNowTime = nFileCreateTime + nNowTime / 1000;
	now = localtime( (time_t*)&nNowTime);
	lpNowDate->SetDate(1900+now->tm_year,1+now->tm_mon,now->tm_mday);
	lpNowTime->SetDateTime(1900+now->tm_year,1+now->tm_mon,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec);

	nAllTime = nFileCreateTime + nAllTime / 1000;
	all = localtime( (time_t*)&nAllTime);
	lpAllTime->SetDateTime(1900+all->tm_year,1+all->tm_mon,all->tm_mday,all->tm_hour,all->tm_min,all->tm_sec);
}

#if 0
static void WINAPI searchnotifycallback(char *sername,int  m_channel,char *sFileName,
										CPLAY_NETTIME *pStartTime,CPLAY_NETTIME *pStopTime,
										DWORD dwFileSize,CNetPlayXCtrl *pPlayCtrl)
{
	int iRet;
	FILESEARCHITEM pFileItem;
	memset(&pFileItem,0,sizeof(pFileItem));
	if(sername) strcpy(pFileItem.m_sername,sername);
	pFileItem.m_chno = m_channel;

	sprintf(pFileItem.m_filetime,"%04d-%02d-%02d %02d:%02d:%02d",
		pStartTime->m_year,
		pStartTime->m_month,
		pStartTime->m_day,
		pStartTime->m_hour,
		pStartTime->m_minute,
		pStartTime->m_second);

	pFileItem.m_filesize = dwFileSize;
	strcpy(pFileItem.m_filename,sFileName);
	if(pPlayCtrl->s_FilePage)
	{
		iRet = fwrite(&pFileItem,sizeof(FILESEARCHITEM),1,pPlayCtrl->s_FilePage);
	}
}
#else
static void WINAPI searchnotifycallback(NDVRFILE_FILEINFO *pfileinfo,void *userdata)
{
	int iRet;
	FILESEARCHITEM_EX pFileItem;
	memset(&pFileItem,0,sizeof(pFileItem));
	CNetPlayXCtrl *pPlayCtrl = (CNetPlayXCtrl*)userdata;
	
	strcpy(pFileItem.m_sername, pfileinfo->sername);
	pFileItem.m_chno = pfileinfo->channel;
	sprintf(pFileItem.m_filetime,"%04d-%02d-%02d %02d:%02d:%02d",
		pfileinfo->StartTime.m_year,
		pfileinfo->StartTime.m_month,
		pfileinfo->StartTime.m_day,
		pfileinfo->StartTime.m_hour,
		pfileinfo->StartTime.m_minute,
		pfileinfo->StartTime.m_second);
	pFileItem.m_islocked = pfileinfo->dwIsLocked;
	
	pFileItem.m_filesize = pfileinfo->dwFileSize;
	strcpy(pFileItem.m_filename, pfileinfo->sFileName);
	if(pPlayCtrl->s_FilePage)
	{
		iRet = fwrite(&pFileItem,sizeof(FILESEARCHITEM_EX),1,pPlayCtrl->s_FilePage);
	}
}
#endif

static void CALLBACK MyButtonEvent(UINT ID,UINT MouesEven,UINT nFlag,void *pParentWnd,CPoint point)
{
	((CNetPlayXCtrl*)pParentWnd)->MyBtnEvent(ID,MouesEven,nFlag);	
}

IMPLEMENT_DYNCREATE(CNetPlayXCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CNetPlayXCtrl, COleControl)
	//{{AFX_MSG_MAP(CNetPlayXCtrl)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_MESSAGE(PLAYEVENT_MSG,OnPlayEvent)
	ON_WM_HSCROLL()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CNetPlayXCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CNetPlayXCtrl)
	DISP_PROPERTY_NOTIFY(CNetPlayXCtrl, "password", m_password, OnPasswordChanged, VT_BSTR)
	DISP_PROPERTY_NOTIFY(CNetPlayXCtrl, "url", m_url, OnUrlChanged, VT_BSTR)
	DISP_PROPERTY_NOTIFY(CNetPlayXCtrl, "username", m_username, OnUsernameChanged, VT_BSTR)
	DISP_PROPERTY_NOTIFY(CNetPlayXCtrl, "wServerPort", m_wServerPort, OnWServerPortChanged, VT_I2)
	DISP_PROPERTY_NOTIFY(CNetPlayXCtrl, "Islocalfile", m_islocalfile, OnIslocalfileChanged, VT_I2)
	DISP_FUNCTION(CNetPlayXCtrl, "NetFileDownload", NetFileDownload, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BOOL)
	DISP_FUNCTION(CNetPlayXCtrl, "NetFileFindStart", NetFileFindStart, VT_EMPTY, VTS_BSTR VTS_I2 VTS_BOOL VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I4 VTS_I4)
	DISP_FUNCTION(CNetPlayXCtrl, "NetFileFindStop", NetFileFindStop, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "NetFileStopDownload", NetFileStopDownload, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "NetStartPlay", NetStartPlay, VT_EMPTY, VTS_BSTR VTS_VARIANT)
	DISP_FUNCTION(CNetPlayXCtrl, "GetFindFileNum", GetFindFileNum, VT_I2, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "ReadFindFile", ReadFindFile, VT_I2, VTS_I2 VTS_I2)
	DISP_FUNCTION(CNetPlayXCtrl, "SetNetStayTime", SetNetStayTime, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CNetPlayXCtrl, "GetSaveFileName", GetSaveFileName, VT_BSTR, VTS_BSTR VTS_BSTR VTS_I2)
	DISP_FUNCTION(CNetPlayXCtrl, "GetSaveDirectory", GetSaveDirectory, VT_BSTR, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "GetSaveFileNameEx", GetSaveFileNameEx, VT_BSTR, VTS_BSTR VTS_BSTR VTS_I2)
	DISP_FUNCTION(CNetPlayXCtrl, "JumpAt", JumpAt, VT_EMPTY, VTS_BSTR)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnPlay", BtnPlay, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnPause", BtnPause, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnStop", BtnStop, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnStep", BtnStep, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnFast", BtnFast, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnSlow", BtnSlow, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnTurn", BtnTurn, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CNetPlayXCtrl, "BtnAudio", BtnAudio, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CNetPlayXCtrl, "ShowBtns", ShowBtns, VT_EMPTY, VTS_BOOL)
	DISP_FUNCTION(CNetPlayXCtrl, "NetSchSetDiskType", NetSchSetDiskType, VT_EMPTY, VTS_I2)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CNetPlayXCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()

#ifdef L_IMPL_OBJECTSAFETY 

BEGIN_INTERFACE_MAP(CNetPlayXCtrl, COleControl) 
	INTERFACE_PART(CNetPlayXCtrl, IID_IObjectSafety, ObjectSafety) 
END_INTERFACE_MAP() 

#endif // L_IMPL_OBJECTSAFETY

/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CNetPlayXCtrl, COleControl)
	//{{AFX_EVENT_MAP(CNetPlayXCtrl)
	EVENT_CUSTOM("NetFileDownloadEvent", FireNetFileDownloadEvent, VTS_I4)
	EVENT_CUSTOM("NetFileFindEvent", FireNetFileFindEvent, VTS_I4)
	EVENT_CUSTOM("PlayBackEvent", FirePlayBackEvent, VTS_I4)
	EVENT_CUSTOM("PlayBackPosEvent", FirePlayBackPosEvent, VTS_I4)
	EVENT_CUSTOM("PlayBufferPosEvent", FirePlayBufferPosEvent, VTS_I4)
	EVENT_CUSTOM("SearchFileNotify", FireSearchFileNotify, VTS_BSTR  VTS_I2  VTS_BSTR  VTS_BSTR  VTS_I4)
	EVENT_CUSTOM("ClickSel", FireClickSel, VTS_NONE)
	EVENT_CUSTOM("LButtonDblClk", FireLButtonDblClk, VTS_NONE)
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CNetPlayXCtrl, 1)
	PROPPAGEID(CNetPlayXPropPage::guid)
END_PROPPAGEIDS(CNetPlayXCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CNetPlayXCtrl, "NETPLAYX.NetPlayXCtrl.1",
	0x359bc4f0, 0xc02, 0x4fd1, 0xaf, 0x70, 0xbe, 0xf3, 0x85, 0xf5, 0xc2, 0xbd)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CNetPlayXCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DNetPlayX =
		{ 0x6528b2e8, 0x986d, 0x4a18, { 0xbe, 0xa, 0x10, 0x54, 0xe8, 0x70, 0x77, 0x8b } };
const IID BASED_CODE IID_DNetPlayXEvents =
		{ 0x7a2e4c17, 0x2eed, 0x4e94, { 0xa7, 0x3f, 0x5b, 0xdd, 0xf3, 0xa, 0xbd, 0xaa } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwNetPlayXOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CNetPlayXCtrl, IDS_NETPLAYX, _dwNetPlayXOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl::CNetPlayXCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CNetPlayXCtrl

BOOL CNetPlayXCtrl::CNetPlayXCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_NETPLAYX,
			IDB_NETPLAYX,
			afxRegApartmentThreading,
			_dwNetPlayXOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl::CNetPlayXCtrl - Constructor

CNetPlayXCtrl::CNetPlayXCtrl()
{
	InitializeIIDs(&IID_DNetPlayX, &IID_DNetPlayXEvents);

	m_netschdisktype = 0;
	m_hConvHandle = NULL;
	s_hPlayHandle = NULL;
	m_hFindHandle = NULL;
	m_hDownHandle = NULL;

	m_convTimer    = 0;
	m_downTimer    = 0;
	m_searchTimer  = 0;
	m_playTimer    = 0;
	m_playstaytimer = 0;
	m_filetime     = 0;
	s_FilePage    = NULL;
	m_bsliderpos  = FALSE;
	m_playfilename = _T("");

	m_ButtonPlay = NULL;
	m_ButtonPause = NULL;
	m_ButtonStop = NULL;
	m_ButtonStep = NULL;
	m_ButtonFast = NULL;
	m_ButtonSlow = NULL;
	m_ButtonAudio = NULL;
	m_ButtonFull  = NULL;
	m_ButtonCut   = NULL;
	m_ButtonSave  = NULL;
	m_ButtonDownload = NULL;
	m_ButtonGo	  = NULL;
	m_ButtonSharppen = NULL;

	/////////////////////////
	m_ButtonTurn = NULL;

	m_videownd    = NULL;
	m_sliderpos   = NULL;
	m_slideraudio = NULL;
	m_statusplay  = NULL;  
	m_statuspos   = NULL;

	m_staytime = 10;//默认缓冲10秒
	m_bdownconvertASF = FALSE;
	memset(m_downtmpfile,'\0',MAX_PATH);
	memset(m_searchindexfile,'\0',MAX_PATH);
	memset(m_seavedownfile,'\0',MAX_PATH);
	memset(m_cutfilename,'\0',MAX_PATH);

	m_language		= TRUE;
	m_bOnCutFile	= FALSE;
	m_islocalfile	= 0;
	m_bDownloadFile = m_bDownloadStart = FALSE;
	m_downStartTime = m_downEndTime   = 0;
	m_filecreatetime= 0;
	m_dlgDownload.m_pParent = this;

    m_filenum       = 1;
    m_curfilenum    = 0;

    m_playinfo.fastslow = 0;
    m_playinfo.turn = FALSE;
    m_playinfo.full = FALSE;
    m_isCountTime   = FALSE;
    m_fulldlg       = NULL;
	m_iSharppenStrength = -1;
}

/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl::~CNetPlayXCtrl - Destructor

CNetPlayXCtrl::~CNetPlayXCtrl()
{
#define MYBTN_DEL(btn) if(btn) {delete btn; btn = NULL;}
	MYBTN_DEL(m_ButtonPlay);
	MYBTN_DEL(m_ButtonPause);
	MYBTN_DEL(m_ButtonStop);
	MYBTN_DEL(m_ButtonStep);
	MYBTN_DEL(m_ButtonFast);
	MYBTN_DEL(m_ButtonSlow);
	MYBTN_DEL(m_ButtonAudio);
	MYBTN_DEL(m_ButtonFull);
	MYBTN_DEL(m_ButtonCut);
	MYBTN_DEL(m_ButtonSave);

	MYBTN_DEL(m_videownd);
	MYBTN_DEL(m_sliderpos);
	MYBTN_DEL(m_slideraudio);
	MYBTN_DEL(m_statusplay);
	MYBTN_DEL(m_statuspos);
	MYBTN_DEL(m_ButtonDownload);
	MYBTN_DEL(m_ButtonGo);
	MYBTN_DEL(m_ButtonSharppen);

	/////////////////////////////////
	MYBTN_DEL(m_ButtonTurn);
    MYBTN_DEL(m_fulldlg);
}


/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl::OnDraw - Drawing function

void CNetPlayXCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	LOGBRUSH LogBrush;
	LogBrush.lbColor=RGB(212,208,200);
	LogBrush.lbStyle=BS_SOLID; 

	CRect button(rcBounds.left,rcBounds.top + 50,rcBounds.right,rcBounds.bottom);
	pdc->FillRect(&button, CBrush::FromHandle(CreateBrushIndirect(&LogBrush)));

	CRect text(rcBounds.left,rcBounds.bottom - 30,rcBounds.right,rcBounds.bottom);
	pdc->FillRect(&text, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
}


/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl::DoPropExchange - Persistence support

void CNetPlayXCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);
}


/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl::OnResetState - Reset control to default state

void CNetPlayXCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl::AboutBox - Display an "About" box to the user

void CNetPlayXCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_NETPLAYX);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CNetPlayXCtrl message handlers

int CNetPlayXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	CString lpstr;
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;

#ifdef LANG_CH
	m_language = GetOEMCP() == 936 ? TRUE : FALSE;
#else
	m_language = FALSE;
#endif
	RECT rect;
	GetClientRect(&rect);

	m_sliderpos = new CMySliderCtrl();
	m_sliderpos->Create(WS_VISIBLE | TBS_HORZ | TBS_BOTH | TBS_NOTICKS,
		CRect(rect.left ,rect.bottom - 70,rect.right,rect.bottom - 50),
		this,IDC_SLIDER_POS);
	m_sliderpos->m_parent = this;
	m_sliderpos->EnableWindow(FALSE);
	m_sliderpos->SetPos(0);
	if(m_language)
		lpstr.LoadString(IDS_STRING201);
	else
		lpstr.LoadString(IDS_STRING202);
	m_sliderpos->UpdateTipTool(lpstr);

	m_slideraudio = new CMySliderCtrl();
	m_slideraudio->Create(WS_VISIBLE | TBS_HORZ | TBS_BOTH | TBS_NOTICKS,
		CRect(rect.right - 50,rect.bottom - 50,rect.right,rect.bottom - 30),
		this,IDC_SLIDER_AUDIO);
	m_slideraudio->SetLineSize(0X1000);
	m_slideraudio->SetPageSize(0X1000);
	m_slideraudio->SetRange(0,0XFFFF);
	m_slideraudio->SetPos(0XA000);
	m_slideraudio->m_parent = this;
	if(m_language)
		lpstr.LoadString(IDS_STRING203);
	else
		lpstr.LoadString(IDS_STRING204);
	m_slideraudio->UpdateTipTool(lpstr);

	m_videownd = new CStaticVideoWnd();
	m_videownd->Create("",WS_CHILD | WS_VISIBLE | WS_EX_STATICEDGE,
		CRect(rect.left,rect.top,rect.right,rect.bottom - 78),
		this,IDC_STATIC_WND);
	m_videownd->m_pchhanle   = &s_hPlayHandle;


	m_statusplay = new CColorStatic();
	m_statusplay->Create("stoped",WS_CHILD | WS_VISIBLE,
		CRect(rect.left + 2,rect.bottom - 20,rect.left + 140,rect.bottom),
		this,IDC_STATIC_STATUS);
	m_statusplay->SetBkColor(RGB(0,0,0));
	m_statusplay->SetTextColor(RGB(255,255,255));

	m_statuspos = new CColorStatic();
	m_statuspos->Create("",WS_CHILD | WS_VISIBLE,
		CRect(rect.right - 105,rect.bottom - 20,rect.right,rect.bottom),
		this,IDC_STATIC_PLAYPOS);
	m_statuspos->SetBkColor(RGB(0,0,0));
	m_statuspos->SetTextColor(RGB(255,255,255));

	m_font.DeleteObject();

    LOGFONT logFont;
	ZeroMemory((void*)&logFont,sizeof(logFont));
	strcpy(logFont.lfFaceName,"宋体");
	logFont.lfHeight = -12;
	logFont.lfWeight = 400;
	logFont.lfCharSet = GB2312_CHARSET;
	logFont.lfOutPrecision = 3;
	logFont.lfClipPrecision = 2; 
	logFont.lfQuality = 1;
	logFont.lfPitchAndFamily = 2;
	m_font.CreateFontIndirect(&logFont);
	m_statusplay->SetFont(&m_font);
	m_statuspos->SetFont(&m_font);

	m_ButtonPlay = new CMyFourButton();
	m_ButtonPlay->Create(IDC_BTN_PLAY,this,MyButtonEvent);
	m_ButtonPlay->LoadBitmaps(16,16,IDB_BITMAP_PLAY,IDB_BITMAP_PLAYPUSH,IDB_BITMAP_PLAYON,IDB_BITMAP_PLAYDISABLE);
	m_ButtonPlay->EnableWindow(TRUE);
	if(m_language)
		lpstr.LoadString(IDS_STRING205);
	else
		lpstr.LoadString(IDS_STRING206);
	m_ButtonPlay->UpdateTipTool(lpstr);

	m_ButtonPause = new CMyFourButton();
	m_ButtonPause->Create(IDC_BTN_PAUSE,this,MyButtonEvent);
	m_ButtonPause->LoadBitmaps(16,16,IDB_BITMAP_PAUSE,IDB_BITMAP_PAUSEPUSH,IDB_BITMAP_PAUSEON,IDB_BITMAP_PAUSEDISABLE);
	m_ButtonPause->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING207);
	else
		lpstr.LoadString(IDS_STRING208);
	m_ButtonPause->UpdateTipTool(lpstr);

	m_ButtonStop = new CMyFourButton();
	m_ButtonStop->Create(IDC_BTN_STOP,this,MyButtonEvent);
	m_ButtonStop->LoadBitmaps(16,16,IDB_BITMAP_STOP,IDB_BITMAP_STOPPUSH,IDB_BITMAP_STOPON,IDB_BITMAP_STOPDISABLE);
	m_ButtonStop->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING209);
	else
		lpstr.LoadString(IDS_STRING210);
	m_ButtonStop->UpdateTipTool(lpstr);
	
	m_ButtonStep = new CMyFourButton();
	m_ButtonStep->Create(IDC_BTN_STEP,this,MyButtonEvent);
	m_ButtonStep->LoadBitmaps(16,16,IDB_BITMAP_STEP,IDB_BITMAP_STEPPUSH,IDB_BITMAP_STEPON,IDB_BITMAP_STEPDISABLE);
	m_ButtonStep->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING211);
	else
		lpstr.LoadString(IDS_STRING212);
	m_ButtonStep->UpdateTipTool(lpstr);
	
	m_ButtonFast = new CMyFourButton();
	m_ButtonFast->Create(IDC_BTN_FAST,this,MyButtonEvent);
	m_ButtonFast->LoadBitmaps(16,16,IDB_BITMAP_FAST,IDB_BITMAP_FASTPUSH,IDB_BITMAP_FASTON,IDB_BITMAP_FASTDISABLE);
	m_ButtonFast->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING213);
	else
		lpstr.LoadString(IDS_STRING214);
	m_ButtonFast->UpdateTipTool(lpstr);
	
	m_ButtonSlow = new CMyFourButton();
	m_ButtonSlow->Create(IDC_BTN_SLOW,this,MyButtonEvent);
	m_ButtonSlow->LoadBitmaps(16,16,IDB_BITMAP_SLOW,IDB_BITMAP_SLOWPUSH,IDB_BITMAP_SLOWON,IDB_BITMAP_SLOWDISABLE);
	m_ButtonSlow->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING215);
	else
		lpstr.LoadString(IDS_STRING216);
	m_ButtonSlow->UpdateTipTool(lpstr);

	m_ButtonAudio = new CMyFourButton();
	m_ButtonAudio->Create(IDC_BTN_AUDIO,this,MyButtonEvent);
	m_ButtonAudio->LoadBitmaps(16,16,IDB_BITMAP_AUDIO,IDB_BITMAP_AUDIOPUSH,IDB_BITMAP_AUDIOON,IDB_BITMAP_AUDIODISABLE);
	m_ButtonAudio->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING221);
	else
		lpstr.LoadString(IDS_STRING222);
	m_ButtonAudio->UpdateTipTool(lpstr);

	m_ButtonFull = new CMyFourButton();
	m_ButtonFull->Create(IDC_BTN_FULL,this,MyButtonEvent);
	m_ButtonFull->LoadBitmaps(16,16,IDB_BITMAP_FULL,IDB_BITMAP_FULLPUSH,IDB_BITMAP_FULLON);
	m_ButtonFull->EnableWindow(TRUE);
	if(m_language)
		lpstr.LoadString(IDS_STRING219);
	else
		lpstr.LoadString(IDS_STRING220);
	m_ButtonFull->UpdateTipTool(lpstr);

	m_ButtonCut = new CMyFourButton();
	m_ButtonCut->Create(IDC_BTN_CUT,this,MyButtonEvent);
	m_ButtonCut->LoadBitmaps(16,16,IDB_BITMAP_CUT,IDB_BITMAP_CUTPUSH,IDB_BITMAP_CUTON,IDB_BITMAP_CUTDISABLE);
	m_ButtonCut->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING223);
	else
		lpstr.LoadString(IDS_STRING224);
	m_ButtonCut->UpdateTipTool(lpstr);

	m_ButtonSave = new CMyFourButton();
	m_ButtonSave->Create(IDC_BTN_SAVE,this,MyButtonEvent);
	m_ButtonSave->LoadBitmaps(16,16,IDB_BITMAP_SAVE,IDB_BITMAP_SAVEPUSH,IDB_BITMAP_SAVEON,IDB_BITMAP_SAVEDISABLE);
	m_ButtonSave->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING225);
	else
		lpstr.LoadString(IDS_STRING226);
	m_ButtonSave->UpdateTipTool(lpstr);

	m_ButtonDownload = new CMyFourButton();
	m_ButtonDownload->Create(IDC_BTN_DOWNLOAD,this,MyButtonEvent);
	m_ButtonDownload->LoadBitmaps(16,16,IDB_BITMAP_DOWNLOAD,IDB_BITMAP_DOWNLOADPUSH,IDB_BITMAP_DOWNLOADPUSH,IDB_BITMAP_DOWNLOADDISABLE);
	m_ButtonDownload->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING236);
	else
		lpstr.LoadString(IDS_STRING237);
	m_ButtonDownload->UpdateTipTool(lpstr);


	m_ButtonGo = new CMyFourButton();
	m_ButtonGo->Create(IDC_BTN_GO,this,MyButtonEvent);
	m_ButtonGo->LoadBitmaps(16,16,IDB_BITMAP_GO,IDB_BITMAP_GO,IDB_BITMAP_GO,IDB_BITMAP_GODISABLE);
	m_ButtonGo->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING253);
	else
		lpstr.LoadString(IDS_STRING254);
	m_ButtonGo->UpdateTipTool(lpstr);

	///////////////////////////////////////
	m_ButtonTurn = new CMyFourButton();
	m_ButtonTurn->Create(IDC_BTN_TURN, this, MyButtonEvent);
	m_ButtonTurn->LoadBitmaps(16,16,IDB_BITMAP_TURN,IDB_BITMAP_TURN,IDB_BITMAP_TURN,IDB_BITMAP_TURNDISABLE);
	m_ButtonTurn->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING231);
	else
		lpstr.LoadString(IDS_STRING232);
	m_ButtonTurn->UpdateTipTool(lpstr);

	m_ButtonSharppen = new CMyFourButton();
	m_ButtonSharppen->Create(IDC_BTN_SHARPPEN, this, MyButtonEvent);
	m_ButtonSharppen->LoadBitmaps(16, 16, IDB_BITMAP_SHARPPEN, IDB_BITMAP_SHARPPEN, IDB_BITMAP_SHARPPENDISABLE);
	m_ButtonSharppen->EnableWindow(FALSE);
	if(m_language)
		lpstr.LoadString(IDS_STRING267);
	else
		lpstr.LoadString(IDS_STRING268);
	m_ButtonSharppen->UpdateTipTool(lpstr);

	LCPLAYM4_InitPlayer();	

	m_ButtonDownload->ShowWindow(SW_HIDE);
	m_ButtonGo->ShowWindow(SW_HIDE);
	return 0;
}
void CNetPlayXCtrl::MyBtnEvent(UINT ID, UINT MouesEven, UINT nFlag)
{
	if(MouesEven != MOUSE_LEFT_UP) return;
	switch(ID)
	{
	case IDC_BTN_PLAY:
        if ( m_filenames.GetSize() )
        {
            m_playfilename = m_filenames.GetAt( m_curfilenum );
            if ( !m_playTimer )
            {
                m_playTimer = SetTimer(TIMERID_PLAYBACK,1000,0);
            }
			m_playinfo.fastslow = 0;
            PlayStart();
        }
		break;
	case IDC_BTN_PAUSE:
		if(s_hPlayHandle == NULL) return;
		LCPLAYM4_Pause(s_hPlayHandle);
		m_ButtonPlay->EnableWindow(TRUE);
		m_ButtonPause->EnableWindow(FALSE);
		break;
	case IDC_BTN_STOP:
		PlayStop();
        m_curfilenum = 0;
        m_playinfo.fastslow = 0;
		break;
	case IDC_BTN_STEP:
		if(s_hPlayHandle == NULL) return;
		LCPLAYM4_OneByOne(s_hPlayHandle);
		m_ButtonPlay->EnableWindow(TRUE);
		m_ButtonPause->EnableWindow(FALSE);
		break;
	case IDC_BTN_FAST:
		if(s_hPlayHandle == NULL) return;
		LCPLAYM4_Fast(s_hPlayHandle);
		m_ButtonPlay->EnableWindow(FALSE);
		m_ButtonPause->EnableWindow(TRUE);
        m_playinfo.fastslow++;
		break;
	case IDC_BTN_SLOW:
		if(s_hPlayHandle == NULL) return;
		LCPLAYM4_Slow(s_hPlayHandle);
		m_ButtonPlay->EnableWindow(FALSE);
		m_ButtonPause->EnableWindow(TRUE);
        m_playinfo.fastslow--;
		break;
	case IDC_BTN_AUDIO:
		m_ButtonAudio->SetState(!m_ButtonAudio->GetState());
		CheckAudio(m_ButtonAudio->GetState());
		FireClickSel();
		break;
	case IDC_BTN_FULL:
		{
            m_playinfo.full = TRUE;
            m_fulldlg = new CDlgFull;
			m_fulldlg->m_parent  = this;
            m_fulldlg->DoModal();
            if ( m_fulldlg ) 
            {
                delete m_fulldlg;
                m_fulldlg = NULL;
            }
            LCPLAYM4_PlaySetWnd(s_hPlayHandle,m_videownd->m_hWnd);
            LCPLAYM4_RefreshDisplay(s_hPlayHandle);
        }
		break;
	case IDC_BTN_CUT:
		OnBtnCut();
		break;
	case IDC_BTN_SAVE:
		OnBtnSavecut();
		break;
	case IDC_BTN_DOWNLOAD:
		OnBtnDownload();
		break;
	case IDC_BTN_GO:
		OnBtnGo();
		break;
	///////////////////////////////////////
	case IDC_BTN_TURN:
		if(s_hPlayHandle == NULL) return;
		LCPLAYM4_FlipVideo(s_hPlayHandle);
        m_playinfo.turn = !m_playinfo.turn;
		break;
	case IDC_BTN_SHARPPEN:
		{
			CDlgSharppenStrength dlg(m_language ? IDD_DLG_SHARPPENSTRENGTH : IDD_DLG_SHARPPENSTRENGTH_EN);
			dlg.m_iSharppenStrength = m_iSharppenStrength;
			if (dlg.DoModal() == IDOK)
			{
				m_iSharppenStrength = dlg.m_iSharppenStrength;
				LCPLAYM4_SharpeVideo(s_hPlayHandle, m_iSharppenStrength);
			}
		}
		break;
	default:
		break;
	}
}

void CNetPlayXCtrl::PlayStart() 
{
	char lpstr[40],file[MAX_PATH],username[40],password[40];
	sprintf(lpstr,"%s",m_url);
	sprintf(username,"%s",m_username);
	sprintf(password,"%s",m_password);
	sprintf(file,"%s",m_playfilename);
	if(s_hPlayHandle != NULL) 
	{
		LCPLAYM4_Play(s_hPlayHandle,m_videownd->m_hWnd);
		m_ButtonPlay->EnableWindow(FALSE);
		m_ButtonPause->EnableWindow(TRUE);
		return;
	}

    m_ButtonCut->EnableWindow(FALSE);
    m_ButtonGo->EnableWindow(FALSE);

	if(m_islocalfile)
	{
		if(strlen(m_playfilename) == 0) return;
		s_hPlayHandle = LCPLAYM4_OpenFile((char*)(LPCSTR)m_playfilename,FALSE);
		if(s_hPlayHandle != NULL && s_hPlayHandle != -1)
			LCPLAYM4_Play(s_hPlayHandle,m_videownd->m_hWnd);

        DWORD firstGMTTime = 0;
        LCPLAYM4_GetFileTime(s_hPlayHandle, &firstGMTTime);
        if (firstGMTTime > 0)
        {
            m_filecreatetime = firstGMTTime;
            m_ButtonCut->EnableWindow(TRUE);
            m_ButtonGo->EnableWindow(TRUE);
        }
		LCPLAYM4_SharpeVideo(s_hPlayHandle, m_iSharppenStrength);
	}
	else
	{
        m_filecreatetime = 0;
		if(strlen(m_url) == 0) return;
		s_hPlayHandle = LCPLAYM4_nFilePlayBackByName(lpstr,username,password,file,
			m_videownd->m_hWnd,
			m_wServerPort);
	}
	if(s_hPlayHandle == NULL || s_hPlayHandle == -1)
	{
		s_hPlayHandle = NULL;
		m_statusplay->SetWindowText("play failed");
		return;
	}

	m_ButtonPlay->EnableWindow(FALSE);
	m_ButtonStop->EnableWindow(TRUE);

	LCPLAYM4_RegEventMsgWnd(s_hPlayHandle,m_hWnd,PLAYEVENT_MSG);
	if(m_islocalfile)
	{
		PostMessage(PLAYEVENT_MSG,2,(LPARAM)s_hPlayHandle);
	    m_statusplay->SetWindowText("playing....");
	}
	else
	{
    	m_statusplay->SetWindowText("connecting....");
		LCPLAYM4_nFilePlayBackStayTime(s_hPlayHandle,m_staytime);
	}
	//m_bsliderpos    = FALSE;
	m_bDownloadFile = FALSE;

    if ( !m_isCountTime ) 
    {
        m_sliderpos->SetLineSize(1);
        m_sliderpos->SetPageSize(1);
        m_sliderpos->SetRange(0,m_filetime/1000);
        m_playTimer = SetTimer(TIMERID_PLAYBACK,1000,0);
    }
    if ( m_playinfo.full && m_fulldlg && m_fulldlg->m_hWnd)
    {
        m_fulldlg->m_parent->s_hPlayHandle = s_hPlayHandle;
        LCPLAYM4_PlaySetWnd(s_hPlayHandle,m_videownd->m_hWnd);
        LCPLAYM4_RefreshDisplay(s_hPlayHandle);
    }
}

void CNetPlayXCtrl::PlayStop()
{
	if(m_bDownloadFile)return;

	MYTIMER_KILL(m_playTimer);
	MYTIMER_KILL(m_playstaytimer);

	OnBtnSavecut();
	if(s_hPlayHandle != NULL)
	{
		LCPLAYM4_Stop(s_hPlayHandle);
		s_hPlayHandle = NULL;
        m_playinfo.fastslow = 0;
        m_playinfo.full = FALSE;
        m_playinfo.turn = FALSE;
	}
	m_videownd->Invalidate();
	m_ButtonPlay->EnableWindow(TRUE);
	m_ButtonPause->EnableWindow(FALSE);
	m_ButtonStep->EnableWindow(FALSE);
	m_ButtonFast->EnableWindow(FALSE);
	m_ButtonSlow->EnableWindow(FALSE);
	m_ButtonAudio->EnableWindow(FALSE);
	m_ButtonStop->EnableWindow(FALSE);
	m_ButtonCut->EnableWindow(FALSE);
	m_ButtonSave->EnableWindow(FALSE);
	m_ButtonDownload->EnableWindow(FALSE);
	m_ButtonGo->EnableWindow(FALSE);
	m_ButtonSharppen->EnableWindow(FALSE);
	/////////////////////////////
	m_ButtonTurn->EnableWindow(FALSE);

	m_sliderpos->EnableWindow(FALSE);
	m_sliderpos->SetPos(0);
	m_statuspos->SetWindowText("");
	m_statusplay->SetWindowText("stoped");
	FirePlayBackEvent(0);
	FirePlayBackPosEvent(0);
}

void CNetPlayXCtrl::OnSize(UINT nType, int cx, int cy) 
{
	if(cx < 300 || cy < 90)
	{
		cx = cx < 300 ? 300 : cx;
		cy = cy < 90  ? 90  : cy;
		SetControlSize(cx,cy);
	}
	COleControl::OnSize(nType, cx, cy);
	
	ShowBtns(TRUE);
}

void CNetPlayXCtrl::ShowBtns(BOOL bshow) 
{
	RECT rect;
	GetClientRect(&rect);

	if (bshow)
	{
		m_ButtonPlay->SetPosition(rect.left + 0,rect.bottom - 50);
		m_ButtonPause->SetPosition(rect.left + 20,rect.bottom - 50);
		m_ButtonStop->SetPosition(rect.left + 40,rect.bottom - 50);
		m_ButtonStep->SetPosition(rect.left + 60,rect.bottom - 50);
		m_ButtonFast->SetPosition(rect.left + 80,rect.bottom - 50);
		m_ButtonSlow->SetPosition(rect.left + 100,rect.bottom - 50);
		m_ButtonSharppen->SetPosition(rect.left + 120,rect.bottom - 50);
		m_ButtonCut->SetPosition(rect.left + 140,rect.bottom - 50);
		m_ButtonSave->SetPosition(rect.left + 160,rect.bottom - 50);
		m_ButtonDownload->SetPosition(rect.left + 180,rect.bottom - 50);
		m_ButtonGo->SetPosition(rect.left+200,rect.bottom-50);


		/////////////////////////////////////////////
		m_ButtonTurn->SetPosition( rect.left+220, rect.bottom-50 );
		
		m_ButtonAudio->SetPosition(rect.right - 70,rect.bottom - 50);
		m_ButtonFull->SetPosition(rect.right - 90,rect.bottom - 50);
		m_slideraudio->MoveWindow(CRect(rect.right - 50,rect.bottom - 50,rect.right,rect.bottom - 30));
		
		m_sliderpos->MoveWindow(CRect(rect.left ,rect.bottom - 70,rect.right,rect.bottom - 50));
		m_videownd->MoveWindow(CRect(rect.left,rect.top,rect.right,rect.bottom - 78));
		
		m_statusplay->MoveWindow(CRect(rect.left + 2,rect.bottom - 20,rect.left + 140,rect.bottom));
		m_statuspos->MoveWindow(CRect(rect.right - 105,rect.bottom - 20,rect.right,rect.bottom));

		m_ButtonPlay->ShowWindow(SW_SHOW);
		m_ButtonPause->ShowWindow(SW_SHOW);
		m_ButtonStop->ShowWindow(SW_SHOW);
		m_ButtonStep->ShowWindow(SW_SHOW);
		m_ButtonFast->ShowWindow(SW_SHOW);
		m_ButtonSharppen->ShowWindow(SW_SHOW);
		m_ButtonSlow->ShowWindow(SW_SHOW);
		m_ButtonCut->ShowWindow(SW_SHOW);
		m_ButtonSave->ShowWindow(SW_SHOW);

#ifdef SHOW_CUTBTN
		m_ButtonDownload->ShowWindow(SW_SHOW);
		m_ButtonGo->ShowWindow(SW_SHOW);
#endif

		m_ButtonTurn->ShowWindow(SW_SHOW);
		m_ButtonAudio->ShowWindow(SW_SHOW);
		m_ButtonFull->ShowWindow(SW_SHOW);
		m_slideraudio->ShowWindow(SW_SHOW);
		m_sliderpos->ShowWindow(SW_SHOW);
		m_statusplay->ShowWindow(SW_SHOW);
		m_statuspos->ShowWindow(SW_SHOW);
	}
	else
	{
		m_ButtonPlay->ShowWindow(SW_HIDE);
		m_ButtonPause->ShowWindow(SW_HIDE);
		m_ButtonStop->ShowWindow(SW_HIDE);
		m_ButtonStep->ShowWindow(SW_HIDE);
		m_ButtonFast->ShowWindow(SW_HIDE);
		m_ButtonSlow->ShowWindow(SW_HIDE);
		m_ButtonCut->ShowWindow(SW_HIDE);
		m_ButtonSave->ShowWindow(SW_HIDE);
		m_ButtonDownload->ShowWindow(SW_HIDE);
		m_ButtonGo->ShowWindow(SW_HIDE);
		m_ButtonSharppen->ShowWindow(SW_HIDE);
		/////////////////////////////////////////////
		m_ButtonTurn->ShowWindow(SW_HIDE);
		
		m_ButtonAudio->ShowWindow(SW_HIDE);
		m_ButtonFull->ShowWindow(SW_HIDE);
		m_slideraudio->ShowWindow(SW_HIDE);
		
		m_sliderpos->ShowWindow(SW_HIDE);
		m_videownd->MoveWindow(CRect(rect.left,rect.top,rect.right,rect.bottom));
		
		m_statusplay->ShowWindow(SW_HIDE);
		m_statuspos->ShowWindow(SW_HIDE);
	}
}

void CNetPlayXCtrl::NetFileDownload(LPCTSTR RemoteFile, LPCTSTR SaveFile, BOOL convertASF) 
{
	MYTIMER_KILL(m_downTimer);
	MYTIMER_KILL(m_convTimer);
	if(m_hConvHandle > 0)
	{
		LCPLAYM4_StopASFConvert(m_hConvHandle);
		m_hConvHandle = NULL;
	}
	if(m_hDownHandle > 0)
	{
		LCPLAYM4_nFileStopDownloadFile(m_hDownHandle);
		m_hDownHandle = NULL;
	}
	DeleteFile(m_downtmpfile);
	char serurl[40];
	char username[24],password[24];
	sprintf(serurl,"%s",m_url);
	sprintf(username,"%s",m_username);
	sprintf(password,"%s",m_password);
	m_bdownconvertASF = convertASF;
	if(m_bdownconvertASF)
	{
		GetTempFileName(m_downtmpfile,2);
		sprintf(m_seavedownfile,"%s",SaveFile);
	}
	else
	{
		sprintf(m_seavedownfile,"%s",SaveFile);
	}
	m_hDownHandle = LCPLAYM4_nFileDownLoadFileByName(serurl,username,password,
		(char*)RemoteFile,
		m_bdownconvertASF ? m_downtmpfile : m_seavedownfile,
		m_wServerPort);
	if(m_hDownHandle == -1)
	{
		FireNetFileDownloadEvent(-1);
		m_hDownHandle = NULL;
		return;
	}
	m_downTimer = SetTimer(TIMERID_DOWNLOAD,200,NULL);
}

void CNetPlayXCtrl::NetFileFindStart(LPCTSTR sername, short channel, BOOL bDateLimite, short year_start, short month_start, short day_start, short hour_start, short minute_start, short year_end, short month_end, short day_end, short hour_end, short minute_end, long filetype, long recvtype) 
{
	MYTIMER_KILL(m_searchTimer);
	if(m_hFindHandle > 0)
	{
		LCPLAYM4_nFileFindClose(m_hFindHandle);
		m_hFindHandle = NULL;
	}
	char serurl[40];
	char username[24],password[24];
	char msername[40];
	CPLAY_NETTIME StartTime,StopTime;

	StartTime.m_year   = (int)year_start;
	StartTime.m_month  = (BYTE)month_start;
	StartTime.m_day    = (BYTE)day_start;
	StartTime.m_hour   = (BYTE)hour_start;
	StartTime.m_minute = (BYTE)minute_start;
	StartTime.m_second = 0;
	StopTime.m_year    = (int)year_end;
	StopTime.m_month   = (BYTE)month_end;
	StopTime.m_day     = (BYTE)day_end;
	StopTime.m_hour    = (BYTE)hour_end;
	StopTime.m_minute  = (BYTE)minute_end;
	StopTime.m_second  = 59;

	if(!s_FilePage)
	{
		GetTempFileName(m_searchindexfile,1);
		s_FilePage = fopen(m_searchindexfile,"wb");
		if(s_FilePage == NULL)
		{
			m_netschdisktype = 0;
			FireNetFileFindEvent(-1);
			return;
		}
	}
	msername[0] = '\0';
	if(sername)
		sprintf(msername,"%s",sername);
	sprintf(serurl,"%s",m_url);
	sprintf(username,"%s",m_username);
	sprintf(password,"%s",m_password);

#if 0
	m_hFindHandle = LCPLAYM4_nFileFindFile(serurl,
		msername,channel,
		username,password,
		filetype,recvtype,
		bDateLimite,
		&StartTime,&StopTime,
		(cplaysearchcallback)searchnotifycallback,this,
		m_wServerPort);
#else
	NDVRFILE_FINDINFO findinfo;
	memset(&findinfo,0,sizeof(NDVRFILE_FINDINFO));
	strcpy(findinfo.sername, sername);
	findinfo.channel = channel;
	findinfo.dwFileType = filetype;
	findinfo.dwRecvType = recvtype;
	findinfo.dwIsLocked = 0;
	findinfo.bTimelimite = bDateLimite;
	memcpy(&findinfo.StartTime,&StartTime,sizeof(CPLAY_NETTIME));
	memcpy(&findinfo.StopTime,&StopTime,sizeof(CPLAY_NETTIME));
	findinfo.disktype = m_netschdisktype;
	m_netschdisktype = 0;
	
	m_hFindHandle = LCPLAYM4_nDVRFileFindFile(serurl, username, password, &findinfo
		, searchnotifycallback, this, m_wServerPort);
#endif

	if(m_hFindHandle == -1)
	{
		FireNetFileFindEvent(-1);
		m_hFindHandle = NULL;
		m_netschdisktype = 0;
		return;
	}
	m_searchTimer = SetTimer(TIMERID_SEARCH,200,NULL);
	//fflush(s_FilePage);
	m_netschdisktype = 0;
}

void CNetPlayXCtrl::NetFileFindStop() 
{
	if(s_FilePage)
	{
		fclose(s_FilePage);
		s_FilePage = NULL;
	}
	SortFindResult();
	MYTIMER_KILL(m_searchTimer);
	if(m_hFindHandle > 0)
	{
		LCPLAYM4_nFileFindClose(m_hFindHandle);
		m_hFindHandle = NULL;
	}
}

void CNetPlayXCtrl::NetFileStopDownload() 
{
	MYTIMER_KILL(m_downTimer);
	MYTIMER_KILL(m_convTimer);
	if(m_hConvHandle > 0)
	{
		LCPLAYM4_StopASFConvert(m_hConvHandle);
		m_hConvHandle = NULL;
		FireNetFileDownloadEvent(-1);
	}
	if(m_hDownHandle > 0)
	{
		LCPLAYM4_nFileStopDownloadFile(m_hDownHandle);
		m_hDownHandle = NULL;
		FireNetFileDownloadEvent(-1);
	}
	DeleteFile(m_downtmpfile);
}

void CNetPlayXCtrl::OnPasswordChanged() 
{
	// TODO: Add notification handler code

	SetModifiedFlag();
}

void CNetPlayXCtrl::OnUrlChanged() 
{
	// TODO: Add notification handler code

	SetModifiedFlag();
}

void CNetPlayXCtrl::OnUsernameChanged() 
{
	// TODO: Add notification handler code

	SetModifiedFlag();
}

void CNetPlayXCtrl::OnWServerPortChanged() 
{
	// TODO: Add notification handler code

	SetModifiedFlag();
}

void CNetPlayXCtrl::OnTimer(UINT nIDEvent) 
{
	if(nIDEvent == TIMERID_CONVT)
	{
		int pos;
		pos = LCPLAYM4_GetASFConvertPos(m_hConvHandle);
		if(pos < 0)
		{
			MYTIMER_KILL(m_convTimer);
			if(m_hConvHandle > 0)
			{
				LCPLAYM4_StopASFConvert(m_hConvHandle);
				m_hConvHandle = NULL;
			}
			DeleteFile(m_downtmpfile);
			FireNetFileDownloadEvent(-1);
		}
		else
		{
			FireNetFileDownloadEvent(pos);
		}
		
	}
	else if(nIDEvent == TIMERID_SEARCH)
	{
		int iRet = LCPLAYM4_nFileFindGetState(m_hFindHandle);
		if(iRet == 1)
		{
			MYTIMER_KILL(m_searchTimer);
/*			if(s_FilePage)
			{
				fclose(s_FilePage);
				s_FilePage = NULL;
			}
			SortFindResult();*/
			FireNetFileFindEvent(0);
//			NetFileFindStop();
		}
		else if (iRet < 0)
		{
			MYTIMER_KILL(m_searchTimer);
			FireNetFileFindEvent(iRet);
		}
	}
	else if(nIDEvent == TIMERID_DOWNLOAD)
	{
		int pos;
		pos = LCPLAYM4_nFileGetDownloadPos(m_hDownHandle);
		if(pos < 0)
		{
			MYTIMER_KILL(m_downTimer);
			if(m_bdownconvertASF)
			{
				MYTIMER_KILL(m_downTimer);
				MYTIMER_KILL(m_convTimer);
				if(m_hConvHandle > 0)
				{
					LCPLAYM4_StopASFConvert(m_hConvHandle);
					m_hConvHandle = NULL;
				}
				if(m_hDownHandle > 0)
				{
					LCPLAYM4_nFileStopDownloadFile(m_hDownHandle);
					m_hDownHandle = NULL;
				}
				m_hConvHandle = LCPLAYM4_StartASFConvert(
					m_downtmpfile,m_seavedownfile);
				if(m_hConvHandle < 0)
				{
					m_hConvHandle = NULL;
					FireNetFileDownloadEvent(-1);
					return;
				}
				m_convTimer = SetTimer(TIMERID_CONVT,100,NULL);
			}
			else
			{
				if(pos == -109)
				{
					FireNetFileDownloadEvent(pos);
				}
				FireNetFileDownloadEvent(-1);
			}
		}
		else
		{
			FireNetFileDownloadEvent(pos);
		}
	}	
	else if(nIDEvent == TIMERID_PLAYBACK)
	{
		//TRACE("Time:%d.\n",time(NULL));
		if(!m_bsliderpos)
		{
			char playtime[40];
			DWORD timecc = LCPLAYM4_GetPlayedTime(s_hPlayHandle);
            DWORD temp = timecc;

            //TRACE("Time:%d.\n",time(NULL));
           // TRACE( "%d\n", m_curfilenum );
            
            for(int i=0 ; i<m_curfilenum; i++ )
            {
                timecc += m_filetimes.GetAt(i);
            }
            
			if( m_bDownloadFile )
			{
				DownTimeToString(timecc,playtime);
			}
			else
			{
				TimeToString(m_filetime,timecc,playtime);
			}
			
            if ( temp > 0 )
            {
                m_statuspos->SetWindowText(playtime);
                m_sliderpos->SetPos(timecc / 1000);
            }
			FirePlayBackPosEvent(timecc/m_filetime);

			//正在下载文件
			if( m_bDownloadFile )
			{
				TRACE("timecc:%d startTime:%d endTime:%d\n",timecc,m_downStartTime,m_downEndTime);

				if( !m_bDownloadStart )
				{
					TRACE("Start DownLoad File\n");
					if( timecc >= m_downStartTime && timecc < m_downEndTime )
					{
						if (!LCPLAYM4_SetFileCutStart(s_hPlayHandle,m_szDownloadFile))
						{
							m_bDownloadFile  = FALSE;
							m_bDownloadStart = FALSE;
							m_downStartTime  = m_downEndTime = 0;
							m_sliderpos->EnableWindow(TRUE);
							m_ButtonCut->EnableWindow(TRUE);
							m_ButtonSave->EnableWindow(FALSE);
							m_ButtonDownload->EnableWindow(TRUE);
							m_ButtonGo->EnableWindow(TRUE);
							///////////////////////////////
							//m_ButtonTurn->EnableWindow(TRUE);

							m_dlgDownload.EndDialog(IDCANCEL);
							MYTIMER_KILL(m_playTimer);
							m_playTimer = SetTimer(TIMERID_PLAYBACK,1000,0);

							if(m_language)
								AfxMessageBox(IDS_STRING248);
							else
								AfxMessageBox(IDS_STRING249);

							PlayStart();
						}
						else
						{
							//快进播放，提高下载速度
							for(int i=0;i<4;i++)
								LCPLAYM4_Fast(s_hPlayHandle);

							m_bDownloadStart = TRUE;
						}
					}
				}
				else
				{
					if( timecc >= m_downEndTime )
					{
						TRACE("DownLoad File Finish!\n");
						int ret;
						CString tt;
						m_bDownloadFile  = FALSE;
						m_bDownloadStart = FALSE;
						m_downStartTime  = m_downEndTime = 0;

						m_sliderpos->EnableWindow(TRUE);
						m_ButtonCut->EnableWindow(TRUE);
						m_ButtonSave->EnableWindow(FALSE);
						m_ButtonDownload->EnableWindow(TRUE);
						m_ButtonGo->EnableWindow(TRUE);
						///////////////////////////////////
						m_ButtonTurn->EnableWindow(TRUE);
						
						ret = LCPLAYM4_SetFileCutEnd(s_hPlayHandle);
						LCPLAYM4_Pause(s_hPlayHandle);
						if (ret <=0 )
						{
							DeleteFile(m_szDownloadFile);
						}
						
						//恢复正常速度播放
						PlayStop();

						//MYTIMER_KILL(m_playTimer);
						m_playTimer = SetTimer(TIMERID_PLAYBACK,1000,0);
						PlayStart();
			
						m_dlgDownload.OnFileDownloadFinish();
					}
					else
					{
						TRACE("DownLoad Progress!\n");
						m_dlgDownload.OnFileDownload((float)(timecc-m_downStartTime)/(float)(m_downEndTime-m_downStartTime));
					}
				}
			}
		}
	}
	else if(nIDEvent == TIMERID_PLAYSTAY)
	{
		int ret;
		char lpstr[20];

		ret = LCPLAYM4_nFilePlayBackGetStayPos(s_hPlayHandle);
		if(ret < 0) 
		{
			FirePlayBufferPosEvent(0);
			return;
		}
		FirePlayBufferPosEvent(ret);
		if( m_bDownloadFile )
			sprintf(lpstr,"downdload(buffer%d%%)",ret);
		else
        {
            if (m_filecreatetime == 0)
            {
                DWORD firstGMTTime;
                LCPLAYM4_GetFileTime(s_hPlayHandle, &firstGMTTime);
                if (firstGMTTime != 0)
                {
                    m_filecreatetime = firstGMTTime;
                    m_ButtonCut->EnableWindow(TRUE);
                    m_ButtonGo->EnableWindow(TRUE);
                }
            }
			sprintf(lpstr,"playing(buffer%d%%)",ret);
        }
		m_statusplay->SetWindowText(lpstr);
	}
	COleControl::OnTimer(nIDEvent);
}

void CNetPlayXCtrl::OnDestroy() 
{
	COleControl::OnDestroy();
		
	NetFileFindStop();
	NetFileStopDownload();
	PlayStop();
	LCPLAYM4_FreePlayer();
	if(s_FilePage) fclose(s_FilePage);
	if(m_searchindexfile[0] != '\0')
		DeleteFile(m_searchindexfile);
	if(m_downtmpfile[0] != '\0')
		DeleteFile(m_downtmpfile);
	if(m_cutfilename[0] != '\0')
		DeleteFile(m_cutfilename);
}

void CNetPlayXCtrl::OnPlayEvent(WPARAM wParam, LPARAM lParam)
{
	if(lParam != (LPARAM)s_hPlayHandle)
	{
		return;
	}
	if(wParam == 1) // play end
	{
        if ( m_curfilenum < m_filenum-1 && m_curfilenum >= 0 )
        {
            s_hPlayHandle = NULL;
            m_curfilenum++;
            m_playfilename = m_filenames.GetAt( m_curfilenum );
            if ( m_playinfo.full && m_fulldlg && !m_fulldlg->m_hWnd )
            {
                delete m_fulldlg;
                m_fulldlg = NULL;
                m_playinfo.full = FALSE;
            }
            PlayStart();
        }
        else
        {
            PlayStop();
            FirePlayBackEvent(2);
            m_curfilenum = 0;
            m_playinfo.fastslow = 0;
            if ( m_fulldlg )
            {
                if ( m_fulldlg->m_hWnd ) 
                {
                    m_fulldlg->EndDialog( TRUE );
                }
                m_playinfo.full = FALSE;
            }
        }
	}
	else if(wParam == 2) // net play start
	{
		if ( m_playinfo.turn )//翻转
        {
            LCPLAYM4_FlipVideo(s_hPlayHandle);
        }
		LCPLAYM4_SharpeVideo(s_hPlayHandle, m_iSharppenStrength);
		m_ButtonPause->EnableWindow(TRUE);
		m_ButtonStep->EnableWindow(TRUE);
		m_ButtonFast->EnableWindow(TRUE);
		m_ButtonSlow->EnableWindow(TRUE);
		m_ButtonStop->EnableWindow(TRUE);
		m_sliderpos->EnableWindow(TRUE);
		m_ButtonSharppen->EnableWindow(TRUE);
        if ( m_filenum > 1 )
        {
            m_ButtonCut->EnableWindow( FALSE );
            m_ButtonGo->EnableWindow( FALSE );
            m_ButtonDownload->EnableWindow( FALSE );
        }
        else
        {
            m_ButtonDownload->EnableWindow(TRUE);
            if (m_filecreatetime > 0)
            {
                m_ButtonGo->EnableWindow(TRUE);
                m_ButtonCut->EnableWindow(TRUE);
            }
        }
        m_ButtonSave->EnableWindow(FALSE);
		///////////////////////////
		m_ButtonTurn->EnableWindow(TRUE);
        
        if( m_isCountTime && m_curfilenum < m_filenum )
        {
            DWORD temp;
            temp = LCPLAYM4_GetFileTime(s_hPlayHandle);
            m_filetimes.Add( temp );
            m_filetime += temp;
            LCPLAYM4_Stop( s_hPlayHandle );
            s_hPlayHandle = NULL;
            m_curfilenum++;
            if ( m_curfilenum == m_filenum )
            {
                char filetime[30];

                m_isCountTime = FALSE;
                m_curfilenum = 0;
                m_sliderpos->SetPos(0);
                TimeToString(m_filetime,0,filetime);
                m_statuspos->SetWindowText(filetime);
            }
            m_playfilename = m_filenames.GetAt( m_curfilenum );
            PlayStart();
        }

        if ( m_bsliderpos )
        {
            if(!LCPLAYM4_SetPlayedTime(s_hPlayHandle,m_slidpos))
            {
                DWORD playtime = LCPLAYM4_GetFileTime(s_hPlayHandle);
                if(playtime != 0)
                {
                    float curpos;
                    curpos = (float)m_slidpos / (float)playtime;
                    LCPLAYM4_SetPlayPos(s_hPlayHandle,curpos);
                }
            }
            m_bsliderpos = FALSE;
        }
        TRACE( "%s", m_playfilename );

        int i;
        for( i=0 ; i<m_playinfo.fastslow ; i++ )//快进
        {
            LCPLAYM4_Fast(s_hPlayHandle);
            m_ButtonPlay->EnableWindow(FALSE);
            m_ButtonPause->EnableWindow(TRUE);
        }
        for( i=0 ; i>m_playinfo.fastslow ; i-- )//快退
        {
            LCPLAYM4_Slow(s_hPlayHandle);
            m_ButtonPlay->EnableWindow(FALSE);
            m_ButtonPause->EnableWindow(TRUE);
        }

        if ( m_fulldlg )
        {
            m_fulldlg->DlgPlay( m_playinfo.full );
        }

		if(LCPLAYM4_HaveAudio(s_hPlayHandle))
		{
			m_ButtonAudio->EnableWindow(TRUE);
			LCPLAYM4_PlaySound(s_hPlayHandle);
			LCPLAYM4_SetVolume(s_hPlayHandle,m_slideraudio->GetPos());
		}
		FirePlayBackEvent(1);
		FirePlayBackPosEvent(0);
	}
	else if(wParam == 3) //网络播放正在建立缓冲
	{
		char lpstr[20];
		int ret = 0;
		ret = LCPLAYM4_nFilePlayBackGetStayPos(s_hPlayHandle);
		if(ret < 0) return;
		FirePlayBufferPosEvent(ret);
		m_playstaytimer = SetTimer(TIMERID_PLAYSTAY,500,0);
		sprintf(lpstr,"playing(buffer%d%%)",ret);
		m_statusplay->SetWindowText(lpstr);
	}
	else if(wParam == 4) //停止建立缓冲
	{
		FirePlayBufferPosEvent(0);
	}
	else if(wParam == -109)//没有权限-109
	{
		FirePlayBackEvent(wParam);
	}
}

void CNetPlayXCtrl::CheckAudio(int state)
{
	CString lpstr;
	if(s_hPlayHandle == NULL) return;
	if(!state)
	{
		LCPLAYM4_PlaySound(s_hPlayHandle);
		LCPLAYM4_SetVolume(s_hPlayHandle,m_slideraudio->GetPos());
		if(m_language)
			lpstr.LoadString(IDS_STRING221);
		else
			lpstr.LoadString(IDS_STRING222);
		m_ButtonAudio->UpdateTipTool(lpstr);
	}
	else
	{
		LCPLAYM4_StopSound(s_hPlayHandle);
		if(m_language)
			lpstr.LoadString(IDS_STRING217);
		else
			lpstr.LoadString(IDS_STRING218);
		m_ButtonAudio->UpdateTipTool(lpstr);
	}
}

void CNetPlayXCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	if( (CScrollBar*)m_sliderpos == pScrollBar
		&& s_hPlayHandle != NULL)
	{
		if(nSBCode == TB_THUMBTRACK )//|| nSBCode == SB_THUMBPOSITION)
		{
			char playtime[30];
			DWORD slidpos;
			slidpos = m_sliderpos->GetPos();
			TimeToString(m_filetime,slidpos * 1000,playtime);
			m_statuspos->SetWindowText(playtime);
			m_bsliderpos = TRUE;
		}
		else if(nSBCode == TB_THUMBPOSITION)
		{
			//DWORD slidpos;
            DWORD temp;
			m_slidpos = 1000*m_sliderpos->GetPos();
			int max = 1000 * m_sliderpos->GetRangeMax();
			if(m_slidpos == max)
			{
				BtnStop();
				return;
			}
              
            int i=-1;
            do
            {
                temp = m_slidpos;
                i++;
                m_slidpos -= m_filetimes.GetAt(i);
            } 
            while( m_slidpos < temp );
            
            m_slidpos += m_filetimes.GetAt(i);
            m_curfilenum = i;
            m_playfilename = m_filenames.GetAt( m_curfilenum );
            LCPLAYM4_Stop( s_hPlayHandle );
            s_hPlayHandle = NULL;
            PlayStart();

            /*if(!LCPLAYM4_SetPlayedTime(s_hPlayHandle,slidpos))
			{
				DWORD playtime = LCPLAYM4_GetFileTime(s_hPlayHandle) / 1000;
				if(playtime != 0)
				{
					float curpos;
					curpos = (float)slidpos / (float)playtime;
					LCPLAYM4_SetPlayPos(s_hPlayHandle,curpos);
				}
			}
			m_bsliderpos = FALSE;*/
		}
	}	
	else if((CScrollBar*)m_slideraudio == pScrollBar
		&& s_hPlayHandle != NULL && nSBCode == TB_THUMBPOSITION)
	{
		if(LCPLAYM4_HaveAudio(s_hPlayHandle))
		{
			m_ButtonAudio->EnableWindow(TRUE);
			m_ButtonAudio->SetState(FALSE);
			LCPLAYM4_SetVolume(s_hPlayHandle,m_slideraudio->GetPos());
		}
	}
	COleControl::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CNetPlayXCtrl::NetStartPlay(LPCTSTR filename,const VARIANT FAR& filecreatetime) 
{
	PlayStop();

	if(filename == NULL || strlen(filename) <= 0) return;

    //filename = "/mnt/hd1/2009_07_20/01_20090720_000405.mp4+/mnt/hd1/2009_07_20/01_20090720_001307.mp4+/mnt/hd1/2009_07_20/01_20090720_002208.mp4";
    //filename = "D:\\20090720\\122_1_090042.mp4+D:\\20090720\\DVR-1-视_6_090047.mp4+D:\\20090720\\122_2_090045.mp4+D:\\20090720\\DVR-1-视_2_090050.mp4";
    m_playfilename.Format("%s",filename);

    int pos;
    m_filenames.RemoveAll();

    while ( ( pos=m_playfilename.Find('+') ) != -1 )
    {
        m_filenames.Add( m_playfilename.Left( pos ) );
        m_playfilename.Delete( 0, pos+1 );
    }
    m_filenames.Add( m_playfilename );
    m_playfilename.Empty();
    m_filenum = m_filenames.GetSize();

	if( filecreatetime.vt != VT_ERROR 
		|| filecreatetime.scode != DISP_E_PARAMNOTFOUND )
		m_filecreatetime = filecreatetime.lVal;
// 	else
// 	{
// 		time_t ltime;
// 		m_filecreatetime = time(&ltime);
// 		TRACE("File Create Time %s", ctime( &ltime ) );
// 	}

    LONG filehandle;
    LONG temp;
    
    m_filetime = 0;
    m_filetimes.RemoveAll();
    if (m_islocalfile)
    {
        for (int i=0; i<m_filenum; i++)
        {
            m_playfilename = m_filenames.GetAt(i);
        
            if (strlen(m_playfilename) == 0) return;
            filehandle = LCPLAYM4_OpenFile((char*)(LPCSTR)m_playfilename,FALSE);
                
            if (filehandle != NULL && filehandle != -1)
            {
                temp = LCPLAYM4_GetFileTime(filehandle);
                m_filetimes.Add(temp);
                m_filetime += temp;
                LCPLAYM4_Stop(filehandle);
            }
            filehandle = NULL;
        }
    }
    else
    {
        m_isCountTime = TRUE;
    }
    
    m_playfilename.Empty();
    m_playfilename = m_filenames.GetAt( 0 );
    m_curfilenum = 0;
    
    m_playinfo.fastslow = 0;
    m_playinfo.turn = FALSE;
    m_playinfo.full = FALSE;

    m_sliderpos->SetPos(0);

	PlayStart();
}

short CNetPlayXCtrl::GetFindFileNum() 
{
	FILE *fpFile = NULL;
	int filesize;
	fpFile = fopen(m_searchindexfile,"rb");
	if(fpFile == NULL) return -1;

	fseek(fpFile,0,SEEK_END);
	filesize = ftell(fpFile);
	fclose(fpFile);
	return (filesize / sizeof(FILESEARCHITEM_EX));
}

short CNetPlayXCtrl::ReadFindFile(short beginnumber, short number) 
{
	int i,iRet;
	FILE *fpFile = NULL;
	int filesize;
	int offset = sizeof(FILESEARCHITEM_EX) * beginnumber;

	fpFile = fopen(m_searchindexfile,"rb");
	if(fpFile == NULL) 
	{
		CString info;
		info.Format("open file : %s faild!",m_searchindexfile);
		AfxMessageBox(info);
		return -1;
	}

	fseek(fpFile,0,SEEK_END);
	filesize = ftell(fpFile);
	if(filesize <= offset)
	{
		iRet = -1;
		goto err_exit;
	}
	fseek(fpFile,offset,SEEK_SET);

	FILESEARCHITEM_EX pFileItem;
	for(i=0;i<number;i++)
	{
		if(fread(&pFileItem,1,sizeof(FILESEARCHITEM_EX),fpFile) != sizeof(FILESEARCHITEM_EX)) 
		{
			iRet = -1;
			goto err_exit;
		}
		FireSearchFileNotify(pFileItem.m_sername,pFileItem.m_chno,pFileItem.m_filetime,
			pFileItem.m_filename,pFileItem.m_filesize);
	}
	iRet = 0;
err_exit:
	if(fpFile) fclose(fpFile);
	return iRet;
}
#ifdef L_IMPL_OBJECTSAFETY 
// Implementation of IObjectSafety 
STDMETHODIMP CNetPlayXCtrl::XObjectSafety::GetInterfaceSafetyOptions(REFIID riid,
																	 DWORD __RPC_FAR *pdwSupportedOptions,
																	 DWORD __RPC_FAR *pdwEnabledOptions) 
{ 
	METHOD_PROLOGUE_EX(CNetPlayXCtrl, ObjectSafety)
	if (!pdwSupportedOptions || !pdwEnabledOptions) 
	{ 
		return E_POINTER; 
	} 
	*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; 
	*pdwEnabledOptions = 0; 
	
	if (NULL == pThis->GetInterface(&riid)) 
	{ 
		TRACE("Requested interface is not supported.\n"); 
		return E_NOINTERFACE; 
	} 
	
	// What interface is being checked out anyhow? 
	OLECHAR szGUID[39]; 
	int i = StringFromGUID2(riid, szGUID, 39); 
	
	if (riid == IID_IDispatch) 
	{ 
		// Client wants to know if object is safe for scripting 
		*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER; 
		return S_OK; 
	} 
	else if(riid == IID_IPersistPropertyBag
		|| riid == IID_IPersistStreamInit
		|| riid == IID_IPersistStorage
		|| riid == IID_IPersistMemory) 
	{ 
		// Those are the persistence interfaces COleControl derived controls support 
		// as indicated in AFXCTL.H 
		// Client wants to know if object is safe for initializing from persistent data 
		*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA; 
		return S_OK; 
	} 
	else 
	{ 
		// Find out what interface this is, and decide what options to enable 
		TRACE("We didn’t account for the safety of this interface, and it’s one we support...\n"); 
		return E_NOINTERFACE; 
	}
} 

STDMETHODIMP CNetPlayXCtrl::XObjectSafety::SetInterfaceSafetyOptions(REFIID riid,
																		DWORD dwOptionSetMask,
																		DWORD dwEnabledOptions) 
{ 
	METHOD_PROLOGUE_EX(CNetPlayXCtrl, ObjectSafety) 

	OLECHAR szGUID[39]; 
	// What is this interface anyway? 
	// We can do a quick lookup in the registry under HKEY_CLASSES_ROOT\Interface 
	int i = StringFromGUID2(riid, szGUID, 39); 
	if (0 == dwOptionSetMask && 0 == dwEnabledOptions) 
	{ 
		// the control certainly supports NO requests through the specified interface 
		// so it’s safe to return S_OK even if the interface isn’t supported. 
		return S_OK; 
	} 
	
	// Do we support the specified interface? 
	if (NULL == pThis->GetInterface(&riid)) 
	{
		TRACE1("%s is not support.\n", szGUID); 
		return E_FAIL; 
	} 
	
	
	if (riid == IID_IDispatch) 
	{ 
		TRACE("Client asking if it’s safe to call through IDispatch.\n"); 
		TRACE("In other words, is the control safe for scripting?\n"); 
		if (INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwEnabledOptions) 
		{ 
			return S_OK; 
		}
		else 
		{ 
			return E_FAIL; 
		} 
	} 
	else if( riid == IID_IPersistPropertyBag
		|| riid == IID_IPersistStreamInit
		|| riid == IID_IPersistStorage
		|| riid == IID_IPersistMemory) 
	{
		TRACE("Client asking if it’s safe to call through IPersist*.\n"); 
		TRACE("In other words, is the control safe for initializing from persistent data?\n"); 
		
		if (INTERFACESAFE_FOR_UNTRUSTED_DATA == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_DATA == dwEnabledOptions) 
		{ 
			return NOERROR; 
		} 
		else 
		{ 
			return E_FAIL; 
		} 
	} 
	else 
	{ 
		TRACE1("We didn’t account for the safety of %s, and it’s one we support...\n", szGUID); 
		return E_FAIL; 
	} 
} 

STDMETHODIMP_(ULONG) CNetPlayXCtrl::XObjectSafety::AddRef()
{
	METHOD_PROLOGUE_EX_(CNetPlayXCtrl, ObjectSafety) 
	return (ULONG)pThis->ExternalAddRef(); 
} 

STDMETHODIMP_(ULONG) CNetPlayXCtrl::XObjectSafety::Release()
{
	METHOD_PROLOGUE_EX_(CNetPlayXCtrl, ObjectSafety) 
	return (ULONG)pThis->ExternalRelease(); 
} 

STDMETHODIMP CNetPlayXCtrl::XObjectSafety::QueryInterface(REFIID iid, LPVOID* ppvObj) 
{ 
	METHOD_PROLOGUE_EX_(CNetPlayXCtrl, ObjectSafety) 
	return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj); 
} 

#endif // L_IMPL_OBJECTSAFETY 


void CNetPlayXCtrl::SetNetStayTime(short staytime) 
{
	m_staytime = (DWORD)staytime;
}

BOOL CNetPlayXCtrl::GetTempFileName(char *lpfilename,int filetype)
{
	int i = 0;
	FILE *fpFile = NULL;
	char windowsfile[MAX_PATH];
	GetWindowsDirectory(windowsfile,MAX_PATH);
	for(i=0;i<10000;i++)
	{
		if(filetype == 1) //index
		{
			sprintf(lpfilename,"%s\\PlayxIndex_%d",windowsfile,i);
			fpFile = fopen(lpfilename,"wb");
			if(fpFile)
			{
				fclose(fpFile);
				return TRUE;
			}
		}
		else if(filetype == 2)
		{
			sprintf(lpfilename,"%s\\PlayxDownTmp_%d",windowsfile,i);
			fpFile = fopen(lpfilename,"wb");
			if(fpFile)
			{
				fclose(fpFile);
				return TRUE;
			}
		}
		else
		{
			sprintf(lpfilename,"%s\\CutFileTmp_%d",windowsfile,i);
			fpFile = fopen(lpfilename,"wb");
			if(fpFile)
			{
				fclose(fpFile);
				return TRUE;
			}
		}
	}
	return FALSE;
}


BSTR CNetPlayXCtrl::GetSaveFileName(LPCTSTR serName, LPCTSTR Remotefile, short isAsf) 
{
	char tempfile[MAX_PATH];
	char savefile[MAX_PATH];
	BOOL bIsHanve = FALSE;
	CString strResult;
	sprintf(tempfile,"%s",Remotefile);
	memset(savefile,'\0',MAX_PATH);
	int i;
	int slen = strlen(tempfile);
	for(i=slen;i>0 ; i--)
	{
		if(tempfile[i] == '/')
		{
			memcpy(savefile,tempfile + i + 1,slen - i - 1);
			bIsHanve = TRUE;
			break;
		}
	}
	if(!bIsHanve)
	{
		for(i=slen;i>0 ; i--)
		{
			if(tempfile[i] == '\\')
			{
				memcpy(savefile,tempfile + i + 1,slen - i - 1);
				bIsHanve = TRUE;
				break;
			}
		}
	}

	if(!bIsHanve)
	{
		strcpy(savefile,tempfile);
	}
	memset(tempfile,'\0',MAX_PATH);
	slen = strlen(savefile);
	for(i=slen;i>0 ; i--)
	{
		if(savefile[i] == '.')
		{
			memcpy(tempfile,savefile,i);
			if(isAsf == 2)
				sprintf(savefile,"%s.jpg",tempfile);
			else if(isAsf == 1)
				sprintf(savefile,"%s.asf",tempfile);
			else
			{
/*
#ifdef FILEEXPAND_H264
				sprintf(savefile,"%s.264",tempfile);
#else
				sprintf(savefile,"%s.mp4",tempfile);
#endif
*/
			}
			strcpy(tempfile,savefile);
			if(serName)
			{
				sprintf(savefile,"%s_%s",serName,tempfile);
				strcpy(tempfile,savefile);
			}
			break;
		}
	}
	if(isAsf == 2)
	{
		CFileDialog dlg(FALSE, 
			"jpeg",
			tempfile, 
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			"JPEG文件(*.jpg)|*.jpg||", this);
		if(dlg.DoModal() != IDOK)
		{
			return NULL;
		}
		strResult = dlg.GetPathName();
	}
	else if(isAsf == 1)
	{
		CFileDialog dlg(FALSE, 
			"asf",
			tempfile, 
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			"ASF文件(*.asf)|*.asf||", this);
		if(dlg.DoModal() != IDOK)
		{
			return NULL;
		}
		strResult = dlg.GetPathName();
	}
	else
	{
/*
#ifdef FILEEXPAND_H264
		CFileDialog dlg(FALSE, 
			"264",
			tempfile, 
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			"264文件(*.264)|*.264||", this);
#else
		CFileDialog dlg(FALSE, 
			"mpg",
			tempfile, 
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			"MP4文件(*.mp4)|*.mp4||", this);
#endif
			*/
		CFileDialog dlg(FALSE,
			"*.*",
			tempfile,
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			"All File(*.*)|*.*||", this);


		if(dlg.DoModal() != IDOK)
		{
			return NULL;
		}
		strResult = dlg.GetPathName();
	}
	return strResult.AllocSysString();
}

void CNetPlayXCtrl::OnBtnCut() 
{
	DWORD	cutStartTime=0;
	CDlgCutStartpos	 dlg(m_language?CDlgCutStartpos::IDD:IDD_DLG_CUTSTARTPOS_EN);
	if (m_bOnCutFile || s_hPlayHandle == NULL) return;

	LCPLAYM4_Pause(s_hPlayHandle);
	//DWORD timecc = LCPLAYM4_GetPlayedTime(s_hPlayHandle);
    DWORD timecc = LCPLAYM4_GetPlayedGMTTime(s_hPlayHandle) - m_filecreatetime;
	TimeToTime(m_filecreatetime,m_filetime,timecc,&(dlg.m_allFileTime),&(dlg.m_cutStartDate),&(dlg.m_cutStartTime));
	dlg.m_filecreatetime = m_filecreatetime;
	dlg.m_language = m_language;

#ifdef SET_CUTVIDEO_TIME
	if (IDCANCEL == dlg.DoModal())
	{
		PlayStart();
		return;
	}
#endif

	DeleteFile(m_cutfilename);
	GetTempFileName(m_cutfilename,3);
		
#ifdef SET_CUTVIDEO_TIME
	cutStartTime = (dlg.GetCutStartTime() - m_filecreatetime)*1000;

	if( !LCPLAYM4_SetPlayedTime(s_hPlayHandle,cutStartTime))
	{
		DWORD playtime = LCPLAYM4_GetFileTime(s_hPlayHandle) / 1000;
		if(playtime != 0)
		{
			float curpos;
			curpos = (float)cutStartTime / (float)m_filetime;
			LCPLAYM4_SetPlayPos(s_hPlayHandle,curpos);
		}
		else
		{
			PlayStart();
			return;
		}
	}
#endif
	
	TRACE("Cut Start Time:%d.\n",cutStartTime);

	PlayStart();
//    Sleep(500);
	if(!LCPLAYM4_SetFileCutStart(s_hPlayHandle,m_cutfilename))
	{
		if(m_language)
			AfxMessageBox(IDS_STRING227);
		else
			AfxMessageBox(IDS_STRING228);
		return;
	}

	m_sliderpos->EnableWindow(FALSE);
	m_bOnCutFile=TRUE;
	m_ButtonCut->EnableWindow(FALSE);
	m_ButtonSave->EnableWindow(TRUE);
	m_ButtonDownload->EnableWindow(FALSE);
	m_ButtonGo->EnableWindow(FALSE);
}	

void CNetPlayXCtrl::OnBtnSavecut() 
{
	int ret;
	CString tt,strfile;

	if(!m_bOnCutFile) return;
	m_bOnCutFile = FALSE;

	m_sliderpos->EnableWindow(TRUE);
	m_ButtonCut->EnableWindow(TRUE);
	m_ButtonSave->EnableWindow(FALSE);
	m_ButtonDownload->EnableWindow(TRUE);
	m_ButtonGo->EnableWindow(TRUE);
	if(s_hPlayHandle == NULL) 
	{
		DeleteFile(m_cutfilename);
		return;
	}
	ret = LCPLAYM4_SetFileCutEnd(s_hPlayHandle);
	if(ret <= 0)
	{
		if(m_language)
			AfxMessageBox(IDS_STRING229);
		else
			AfxMessageBox(IDS_STRING230);
		DeleteFile(m_cutfilename);
		return;
	}
	//保存剪切文件时自动暂定播放
	MyBtnEvent(IDC_BTN_PAUSE,MOUSE_LEFT_UP,0);
	
	if(m_language)
	{
#ifdef FILEEXPAND_H264
		tt.LoadString(IDS_STRING265);
#else
		tt.LoadString(IDS_STRING233);
#endif
	}
	else
	{
#ifdef FILEEXPAND_H264
		tt.LoadString(IDS_STRING266);
#else
		tt.LoadString(IDS_STRING234);
#endif
	}
#ifdef FILEEXPAND_H264
	CFileDialog dlg(FALSE, 
			".264",
			NULL, 
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			tt, this);
#else
	CFileDialog dlg(FALSE, 
			".mp4",
			NULL, 
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			tt, this);
#endif
	if( dlg.DoModal() == IDOK)
	{
		strfile = dlg.GetPathName();
		MoveFile(m_cutfilename,strfile);
	}
	DeleteFile(m_cutfilename);
	MyBtnEvent(IDC_BTN_PLAY,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::SortFindResult() 
{
	CPtrArray datalist;
	int iRet,i;
	FILESEARCHITEM_EX *pitem,*pitemnext;
	FILE *writeSortFile,*pReadFile = NULL;


	if (strlen(m_searchindexfile) <= 0)
	{
		return ;
	}

	pReadFile = fopen(m_searchindexfile,"rb");
	if(pReadFile == NULL)
	{
		return;
	}
	datalist.RemoveAll();

	fseek(pReadFile,SEEK_SET,0);
	while((pitem = new FILESEARCHITEM_EX()) != NULL)
	{
		iRet = fread(pitem,1,sizeof(FILESEARCHITEM_EX),pReadFile);
		if(iRet != sizeof(FILESEARCHITEM_EX) )
		{
			if(pitem) delete pitem;
			pitem = NULL;
			break;
		}
		datalist.Add(pitem);
	}
	if(pReadFile) fclose(pReadFile);
	pReadFile = NULL;

	for(iRet = 0;iRet < datalist.GetSize()-1;iRet++)
	{
		for(i=0;i<datalist.GetSize()-iRet-1;i++)
		{
			pitem = (FILESEARCHITEM_EX*)datalist.GetAt(i);
			pitemnext = (FILESEARCHITEM_EX*)datalist.GetAt(i+1);
			if (strcmp(pitem->m_sername, pitemnext->m_sername) > 0)
			{
				datalist.SetAt(i,pitemnext);
				datalist.SetAt(i+1,pitem);
			}
			else if(strcmp(pitem->m_sername, pitemnext->m_sername) == 0 && strcmp(pitem->m_filetime,pitemnext->m_filetime) > 0)
			{
				datalist.SetAt(i,pitemnext);
				datalist.SetAt(i+1,pitem);
			}
		}
	}

	writeSortFile = fopen(m_searchindexfile,"wb");
	if(writeSortFile == NULL) return;
	while(datalist.GetSize())
	{
		pitem = (FILESEARCHITEM_EX*)datalist.GetAt(0);
		datalist.RemoveAt(0);
		fwrite(pitem,sizeof(FILESEARCHITEM_EX),1,writeSortFile);
		delete pitem;
	}
	fflush(writeSortFile);
	fclose(writeSortFile);
	return;
}

BSTR CNetPlayXCtrl::GetSaveDirectory() 
{
	CString strResult;

	LPMALLOC		pMalloc;
	BROWSEINFO		bi;
	LPITEMIDLIST	pidl;
	int				nRetValue = IDCANCEL;
	TCHAR			m_szSelectedFolder[MAX_PATH];

	::ZeroMemory(&bi, sizeof(bi));
	::ZeroMemory(&m_szSelectedFolder, sizeof(m_szSelectedFolder));

	// Gets the Shell's default allocator
	if (::SHGetMalloc(&pMalloc) == NOERROR)
	{
		// Get help on BROWSEINFO struct - it's got all the bit settings.
		bi.hwndOwner = m_hWnd;
		bi.pidlRoot = NULL;
		bi.pszDisplayName = m_szSelectedFolder;
		bi.lpszTitle = "Select Directory";
		bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
		bi.lpfn = NULL;
		bi.lParam = NULL;
		// This next call issues the dialog box.
		if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
		{
			if (::SHGetPathFromIDList(pidl, m_szSelectedFolder))
			{ 
				// At this point pszBuffer contains the selected path
				nRetValue = IDOK;
			} // if
			// Free the PIDL allocated by SHBrowseForFolder.
			pMalloc->Free(pidl);
		} // if
		// Release the shell's allocator.
		pMalloc->Release();
	} // if
	strResult = m_szSelectedFolder;
	return strResult.AllocSysString();
}

BSTR CNetPlayXCtrl::GetSaveFileNameEx(LPCTSTR serName, LPCTSTR Remotefile, short isAsf) 
{
	CString strResult;
	char tempfile[MAX_PATH];
	char savefile[MAX_PATH];
	BOOL bIsHanve = FALSE;
	sprintf(tempfile,"%s",Remotefile);
	memset(savefile,'\0',MAX_PATH);
	int i;
	int slen = strlen(tempfile);
	for(i=slen;i>0 ; i--)
	{
		if(tempfile[i] == '/')
		{
			memcpy(savefile,tempfile + i + 1,slen - i - 1);
			bIsHanve = TRUE;
			break;
		}
	}
	if(!bIsHanve)
	{
		for(i=slen;i>0 ; i--)
		{
			if(tempfile[i] == '\\')
			{
				memcpy(savefile,tempfile + i + 1,slen - i - 1);
				bIsHanve = TRUE;
				break;
			}
		}
	}

	if(!bIsHanve)
	{
		strcpy(savefile,tempfile);
	}
	memset(tempfile,'\0',MAX_PATH);
	slen = strlen(savefile);
	for(i=slen;i>0 ; i--)
	{
		if(savefile[i] == '.')
		{
			memcpy(tempfile,savefile,i);
			if(isAsf == 2)
				sprintf(savefile,"%s.jpg",tempfile);
			else if(isAsf == 1)
				sprintf(savefile,"%s.asf",tempfile);
			else
			{
/*
#ifdef FILEEXPAND_H264
				sprintf(savefile,"%s.264",tempfile);
#else
				sprintf(savefile,"%s.mp4",tempfile);
#endif
*/
			}
			strcpy(tempfile,savefile);
			if(serName)
			{
				sprintf(savefile,"%s_%s",serName,tempfile);
				strcpy(tempfile,savefile);
			}
			break;
		}
	}
	strResult = tempfile;
	return strResult.AllocSysString();
}


void CNetPlayXCtrl::OnIslocalfileChanged() 
{
	// TODO: Add notification handler code

	SetModifiedFlag();
}

void CNetPlayXCtrl::OnBtnDownload()
{
	CDlgDownloadFile	dlg(m_language?CDlgDownloadFile::IDD:IDD_DLG_DOWNLOADBTTIME_EN);
	if (m_bOnCutFile || m_bDownloadFile || s_hPlayHandle == NULL) return;

	//暂停文件播放
	LCPLAYM4_Pause(s_hPlayHandle);
	m_downStartTime = LCPLAYM4_GetPlayedTime(s_hPlayHandle);
	TimeToTime(m_filecreatetime,m_filetime,m_downStartTime,&(dlg.m_allFileTime),&(dlg.m_startDate),&(dlg.m_startTime));
	dlg.m_filecreatetime = m_filecreatetime;
	dlg.m_language = m_language;

	if (IDCANCEL==dlg.DoModal())
	{
		PlayStart();
		return;
	}
	
	sprintf(m_szDownloadFile,dlg.m_szDownloadfile);
	m_downStartTime = (dlg.GetStartTime()-m_filecreatetime)*1000;
	m_downEndTime   = (dlg.GetEndTime()-m_filecreatetime)*1000;

	//定位文件
	if( !LCPLAYM4_SetPlayedTime(s_hPlayHandle,m_downStartTime))
	{
		DWORD playtime = LCPLAYM4_GetFileTime(s_hPlayHandle) / 1000;
		if(playtime != 0)
		{
			float curpos;
			curpos = (float)m_downStartTime / (float)m_filetime;
			LCPLAYM4_SetPlayPos(s_hPlayHandle,curpos);
		}
		else
		{			
			AfxMessageBox(IDS_STRING248);
			PlayStart();
			return;
		}
	}

	m_bDownloadFile = TRUE;
	m_bDownloadStart= FALSE; 
	m_sliderpos->EnableWindow(FALSE);
	m_ButtonCut->EnableWindow(FALSE);
	m_ButtonSave->EnableWindow(FALSE);
	m_ButtonDownload->EnableWindow(FALSE);
	m_ButtonGo->EnableWindow(FALSE);
	MYTIMER_KILL(m_playTimer);
	m_playTimer = SetTimer(TIMERID_PLAYBACK,50,0);
	PlayStart();
	m_dlgDownload.DoModal();
}

void CNetPlayXCtrl::CancelDownload()
{
	m_bDownloadFile  = FALSE;
	m_bDownloadStart = FALSE;
	m_downStartTime  = m_downEndTime = 0;

	m_sliderpos->EnableWindow(TRUE);
	m_ButtonCut->EnableWindow(TRUE);
	m_ButtonSave->EnableWindow(FALSE);
	m_ButtonDownload->EnableWindow(TRUE);
	m_ButtonGo->EnableWindow(TRUE);
	
	LCPLAYM4_SetFileCutEnd(s_hPlayHandle);
	LCPLAYM4_Pause(s_hPlayHandle);
	DeleteFile(m_szDownloadFile);
	
	//恢复正常速度播放
	MYTIMER_KILL(m_playTimer);
	m_playTimer = SetTimer(TIMERID_PLAYBACK,1000,0);
	PlayStart();
	m_dlgDownload.EndDialog(IDCANCEL);
}

void CNetPlayXCtrl::OnBtnGo()
{
	DWORD	goTime=0;
	CDlgCutStartpos	 dlg(m_language?IDD_DLG_SETPLAYPOS:IDD_DLG_SETPLAYPOS_EN);
	dlg.m_type = 1;
	dlg.m_language = m_language;

	if (s_hPlayHandle == NULL) return;

	LCPLAYM4_Pause(s_hPlayHandle);
	//DWORD timecc = LCPLAYM4_GetPlayedTime(s_hPlayHandle);
    DWORD timecc = LCPLAYM4_GetPlayedGMTTime(s_hPlayHandle) - m_filecreatetime;
	TimeToTime(m_filecreatetime,m_filetime,timecc,&(dlg.m_allFileTime),&(dlg.m_cutStartDate),&(dlg.m_cutStartTime));
	dlg.m_filecreatetime = m_filecreatetime;

	if (IDOK == dlg.DoModal())
	{
		goTime = (dlg.GetCutStartTime() - m_filecreatetime)*1000;
		TRACE("Go Time:%d.\n",goTime);
		if( !LCPLAYM4_SetPlayedTime(s_hPlayHandle,goTime))
		{
			DWORD playtime = LCPLAYM4_GetFileTime(s_hPlayHandle) / 1000;
			if(playtime != 0)
			{
				float curpos;
				curpos = (float)goTime / (float)m_filetime;
				if (!LCPLAYM4_SetPlayPos(s_hPlayHandle,curpos))
				{
					if(m_language)
						AfxMessageBox(IDS_STRING255);
					else
						AfxMessageBox(IDS_STRING256);
				}
			}
		}
	}
	PlayStart();
}

void CNetPlayXCtrl::JumpAt(LPCTSTR lpTime) 
{
	int iTime = atoi(lpTime);
	if(s_hPlayHandle && iTime > 0)
	{
		if(!LCPLAYM4_SetPlayedTime(s_hPlayHandle, iTime * 1000))
		{
			DWORD playtime = LCPLAYM4_GetFileTime(s_hPlayHandle) / 1000;
			if(playtime != 0)
			{
				float curpos = ((float)iTime) / (float)playtime;
				LCPLAYM4_SetPlayPos(s_hPlayHandle, curpos);
			}
		}
	}
	else
	{
		//AfxMessageBox("播放句柄为空");
	}
}

void CNetPlayXCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if(nFlags == MK_LBUTTON)
		FireClickSel();
	
	COleControl::OnLButtonDown(nFlags, point);
}

void CNetPlayXCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	if(nFlags == MK_LBUTTON)
		FireLButtonDblClk();
	
	COleControl::OnLButtonDblClk(nFlags, point);
}

void CNetPlayXCtrl::BtnPlay() 
{
	MyBtnEvent(IDC_BTN_PLAY,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::BtnPause() 
{
	MyBtnEvent(IDC_BTN_PAUSE,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::BtnStop() 
{
	MyBtnEvent(IDC_BTN_STOP,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::BtnStep() 
{
	MyBtnEvent(IDC_BTN_STEP,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::BtnFast() 
{
	MyBtnEvent(IDC_BTN_FAST,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::BtnSlow() 
{
	MyBtnEvent(IDC_BTN_SLOW,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::BtnTurn() 
{
	MyBtnEvent(IDC_BTN_TURN,MOUSE_LEFT_UP,0);
}

void CNetPlayXCtrl::BtnAudio(short state) 
{
	m_ButtonAudio->SetState(!state);
	CheckAudio(m_ButtonAudio->GetState());
}


void CNetPlayXCtrl::NetSchSetDiskType(short disktype) 
{
	// TODO: Add your dispatch handler code here
	if(disktype == 5 || disktype == 6 || disktype == 7)
		m_netschdisktype = disktype;
}
