⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flashplayerdlg.cpp

📁 VC编写的Flash播放器
💻 CPP
字号:
// FlashPlayerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FlashPlayer.h"
#include "FlashPlayerDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFlashPlayerDlg dialog

CFlashPlayerDlg::CFlashPlayerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFlashPlayerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFlashPlayerDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFlashPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFlashPlayerDlg)
	DDX_Control(pDX, IDC_FLASH, flash);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFlashPlayerDlg, CDialog)
	//{{AFX_MSG_MAP(CFlashPlayerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_TERMINATE, OnTerminate)
	ON_BN_CLICKED(IDC_REPLAY, OnReplay)
	ON_BN_CLICKED(IDC_BACKWARD, OnBackward)
	ON_BN_CLICKED(IDC_FORWARD, OnForward)
	ON_BN_CLICKED(IDC_LASTFRAME, OnLastframe)
	ON_BN_CLICKED(IDC_FASTBACK, OnFastback)
	ON_BN_CLICKED(IDC_FASTFORWARD, OnFastforward)
	ON_BN_CLICKED(IDC_ZOOMIN, OnZoomin)
	ON_BN_CLICKED(IDC_ZOOMOUT, OnZoomout)
	ON_BN_CLICKED(IDC_REVERT, OnRevert)
	ON_BN_CLICKED(IDC_CLOSE, OnClose)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFlashPlayerDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	timerflag=false;  //Timer启用的标志
	screenflag=false;  //全屏的标志  
	playflag=false;  //有无文件打开的标志
	
	CSliderCtrl *m_pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
	m_pSlider->SetRange(0,100);  //设定Slider的活动范围是0~100
	
	flash.SetBackgroundColor(RGB(150,100,0));

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFlashPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFlashPlayerDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFlashPlayerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CFlashPlayerDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if   (GetDlgItem(IDC_FLASH)->GetSafeHwnd())   
	{		
		GetDlgItem(IDC_FLASH)->MoveWindow(0,cy/20,cx,19*cy/20,true);
	}
}

void CFlashPlayerDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	char szFilters[]="MyType Files (*.swf)|*.swf||";
	CFileDialog fileDlg (TRUE, "swf", "*.swf",OFN_FILEMUSTEXIST| OFN_HIDEREADONLY,szFilters, this);
	if( fileDlg.DoModal ()==IDOK )  
    {
        CString pathName = fileDlg.GetPathName();  
		flash.SetMovie(pathName);  
		playflag=TRUE;
		
		if(!timerflag)
		{
			m_nTimer=SetTimer(1,10,0);  //开启计时器
			timerflag=!timerflag;
		}
	}

}

void CFlashPlayerDlg::OnPlay() 
{
	// TODO: Add your control notification handler code here
	flash.Play();
}

void CFlashPlayerDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
	flash.Stop();
}

void CFlashPlayerDlg::OnTerminate() 
{
	// TODO: Add your control notification handler code here
	  flash.Rewind();    
	flash.Stop(); 

}

void CFlashPlayerDlg::OnReplay() 
{
	// TODO: Add your control notification handler code here
	 flash.Rewind();
 flash.Play();

}

void CFlashPlayerDlg::OnBackward() 
{
	// TODO: Add your control notification handler code here
	flash.Back();

}

void CFlashPlayerDlg::OnForward() 
{
	// TODO: Add your control notification handler code here
	 flash.Forward();

}

void CFlashPlayerDlg::OnLastframe() 
{
	// TODO: Add your control notification handler code here
	flash.GotoFrame(flash.GetTotalFrames()-1);
}

void CFlashPlayerDlg::OnFastback() 
{
	// TODO: Add your control notification handler code here
	int current=flash.CurrentFrame();
	if(current>4)
	{
		current-=5;
		flash.GotoFrame(current);
	}
	else
	{
		flash.SetFrameNum(0);
	}

}

void CFlashPlayerDlg::OnFastforward() 
{
	// TODO: Add your control notification handler code here
	int current=flash.CurrentFrame();
	int i=flash.GetFrameNum();
	if(current<flash.GetTotalFrames()-5)
	{
		current+=5;
		flash.GotoFrame(current);
	}
	else
	{
		flash.SetFrameNum(flash.GetTotalFrames()-1);
	}

}

void CFlashPlayerDlg::OnZoomin() 
{
	// TODO: Add your control notification handler code here
	flash.Zoom(50);

}

void CFlashPlayerDlg::OnZoomout() 
{
	// TODO: Add your control notification handler code here
	 flash.Zoom(200);   

}

void CFlashPlayerDlg::OnRevert() 
{
	// TODO: Add your control notification handler code here
	flash.Zoom(0);

}

void CFlashPlayerDlg::OnClose() 
{
	// TODO: Add your control notification handler code here
	flash.SetMovie("http://");
	KillTimer(m_nTimer);  //停止计时器
	CSliderCtrl *m_pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);  
	m_pSlider->SetPos(0);  //滑块置零
	timerflag=FALSE;////////////////////////////////
	playflag=FALSE;////////////////////////////////

}

void CFlashPlayerDlg::OnReleasedcaptureSlider(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CSliderCtrl *m_pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1); 
	int num=m_pSlider->GetPos();
	num=num*flash.GetTotalFrames()/100;
    flash.GotoFrame(num);
	
	////////////////////////////////////////////////////////////////////////////////////
	//将下面代码添加到,Dialog类的OnInitDialog()函数中
	m_pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
	m_pSlider->SetRange(0,100);  //设定Slider的活动范围是0~100
	
	*pResult = 0;
}

void CFlashPlayerDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CSliderCtrl *m_pSlider=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
	m_pSlider->SetPos(flash.CurrentFrame()*100/flash.GetTotalFrames()); 

	CDialog::OnTimer(nIDEvent);
}

BOOL CFlashPlayerDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	 if(timerflag)
		KillTimer(m_nTimer);

	return CDialog::DestroyWindow();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -