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

📄 playerdlg.cpp

📁 一个自己编的Flashplayer
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PlayerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Player.h"
#include "PlayerDlg.h"
#include "shockwaveflash.h"
#include "OpenNetDlg.h"
#include <Windowsx.h>
#include <io.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString GetFileName(CString &Path);//从路径中得到文件名
long oldproc; 
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg dialog

CPlayerDlg::CPlayerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPlayerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPlayerDlg)
		//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_PlayList.SetSize(0,30);
	ZoomFlag=0;
	TimerFlag=false;
	ScreenFlag=false;
}

void CPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPlayerDlg)
	DDX_Control(pDX, IDC_LIST1, m_CtrList);
	DDX_Control(pDX, IDS_SLIDER, m_strslider);
	DDX_Control(pDX, IDC_SLIDER, m_slider);
	DDX_Control(pDX, IDC_FLASH, m_Flash);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)
	//{{AFX_MSG_MAP(CPlayerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(IDM_ABOUT, OnAbout)
	ON_COMMAND(IDM_OPEN, OnOpen)
	ON_COMMAND(IDM_CLOSE, OnClose)
	ON_COMMAND(IDM_OPENNET, OnOpennet)
	ON_COMMAND(IDM_EXIT, OnExit)
	ON_COMMAND(IDM_100, On100)
	ON_COMMAND(IDM_FULLSCREEN, OnFullscreen)
	ON_COMMAND(IDM_VIEWALL, OnViewall)
	ON_COMMAND(IDM_ZOOMIN, OnZoomin)
	ON_COMMAND(IDM_ZOOMOUT, OnZoomout)
	ON_COMMAND(IDM_QUALITY_HIGH, OnQualityHigh)
	ON_COMMAND(IDM_QUALITY_LOW, OnQualityLow)
	ON_COMMAND(IDM_QUALITY_MEDIUM, OnQualityMedium)
	ON_UPDATE_COMMAND_UI(IDM_ZOOMOUT, OnUpdateZoomout)
	ON_WM_INITMENUPOPUP()
	ON_UPDATE_COMMAND_UI(IDM_ZOOMIN, OnUpdateZoomin)
	ON_UPDATE_COMMAND_UI(IDM_CLOSE, OnUpdateClose)
	ON_COMMAND(IDM_PRINT, OnPrint)
	ON_UPDATE_COMMAND_UI(IDM_VIEWALL, OnUpdateViewall)
	ON_UPDATE_COMMAND_UI(IDM_100, OnUpdate100)
	ON_UPDATE_COMMAND_UI(IDM_FULLSCREEN, OnUpdateFullscreen)
	ON_WM_SIZE()
	ON_WM_TIMER()
	ON_WM_HSCROLL()
	ON_UPDATE_COMMAND_UI(IDM_PRINT, OnUpdatePrint)
	ON_WM_DROPFILES()
	ON_COMMAND(IDM_PLAYLIST, OnPlaylist)
	ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// CPlayerDlg message handlers
//////////////////////////////////////////////////////////
//响应函数
/////////////////////////////////////////////////////////
//使对话框中菜单栏中的某项变灰的响应函数
void CPlayerDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
 CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
 // TODO: Add your message handler code here
 ASSERT(pPopupMenu != NULL);
 // Check the enabled state of various menu items.
    CCmdUI state;
    state.m_pMenu = pPopupMenu;
    ASSERT(state.m_pOther == NULL);
    ASSERT(state.m_pParentMenu == NULL);
 // Determine if menu is popup in top-level menu and set m_pOther to
 // it if so
 //(m_pParentMenu == NULL indicates that it is secondary popup).
    HMENU hParentMenu;
    if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
        state.m_pParentMenu = pPopupMenu;   
 // Parent == child for tracking popup.
    else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
    {
        CWnd* pParent = this;
        // Child windows don't have menus--need to go to the top!
        if (pParent != NULL &&
           (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
        {
           int nIndexMax = ::GetMenuItemCount(hParentMenu);
           for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
           {
      if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
            {
          // When popup is found, m_pParentMenu is containing menu.
            state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
                break;
            }
           }
        }
    }
    state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
    for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
      state.m_nIndex++)
    {
        state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
        if (state.m_nID == 0)
           continue; // Menu separator or invalid cmd - ignore it.
        ASSERT(state.m_pOther == NULL);
        ASSERT(state.m_pMenu != NULL);
        if (state.m_nID == (UINT)-1)
        {
      // Possibly a popup menu, route to first item of that popup.
           state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
       if (state.m_pSubMenu == NULL ||
            (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
            state.m_nID == (UINT)-1)
           {
            continue;    // First item of popup can't be routed to.
           }
           state.DoUpdate(this, TRUE);  
// Popups are never auto disabled.
        }
        else
        {
         // Normal menu item.
       // Auto enable/disable if frame window has m_bAutoMenuEnable
        // set and command is _not_ a system command.
           state.m_pSubMenu = NULL;
           state.DoUpdate(this, FALSE);
      }
    // Adjust for menu deletions and additions.
     UINT nCount = pPopupMenu->GetMenuItemCount();
     if (nCount < state.m_nIndexMax)
     {
       state.m_nIndex -= (state.m_nIndexMax - nCount);
       while (state.m_nIndex < nCount &&
       pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
       {
            state.m_nIndex++;
        }
     }
     state.m_nIndexMax = nCount;
    }
}
/////////////////////////////////////////////////////////////////////////////
	
BOOL CPlayerDlg::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
	
	m_Flash.SetScaleMode(0);
	GetMenu()->GetSubMenu(1)->CheckMenuItem(IDM_VIEWALL,MF_BYCOMMAND |MF_CHECKED);
	m_strslider.SetWindowText("0/0");
	m_slider.SetLineSize(1);
	m_slider.SetPageSize(50);
	m_acc=LoadAccelerators(AfxGetInstanceHandle( ),MAKEINTRESOURCE(IDR_MENU1));
	ASSERT(m_acc);
	CString cline(*(__argv + 1));
	if (cline.Right(4)==".swf")
	{
		LoadFlash(cline);
	}
	m_xSplitter.BindWithControl(this, IDC_SPLITTER);
    m_xSplitter.SetMinWidth(50,100);
    m_xSplitter.AttachAsLeftPane(IDC_FLASH);
   // m_xSplitter.AttachAsLeftPane(IDC_SLIDER);
//	m_xSplitter.AttachAsLeftPane(IDS_SLIDER);
    m_xSplitter.AttachAsRightPane(IDC_LIST1);
    m_xSplitter.RecalcLayout();
	m_bPlayList=TRUE;
	return TRUE;  //unless you set the focus to a control
}

void CPlayerDlg::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 CPlayerDlg::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 CPlayerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPlayerDlg::OnAbout() 
{
	// TODO: Add your command handler code here
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

void CPlayerDlg::OnOpen() 
{
	// TODO: Add your command handler code here
	char   szBuf[50*256]="\0";   
	CFileDialog OpenSWFDialog(true,NULL,NULL,
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,
		"Flash文件|*.swf\0",this);
	OpenSWFDialog.m_ofn.lStructSize=88;
	OpenSWFDialog.m_ofn.lpstrTitle="打开Flash文件";
	OpenSWFDialog.m_ofn.lpstrFile=szBuf;
	OpenSWFDialog.m_ofn.nMaxFile=sizeof(szBuf);
	//OpenSWFDialog.m_ofn.lpstrInitialDir="c:";
	if (IDOK==OpenSWFDialog.DoModal())
	{
		//MessageBox(OpenSWFDialog.GetPathName());
		  POSITION   pos   =   OpenSWFDialog.GetStartPosition();   
		  CString   str;   
		  while(pos)   
		  {   
		  str   =   OpenSWFDialog.GetNextPathName(pos);  
		  str.ReleaseBuffer();
		  m_PlayList.Add(str);
		  m_CtrList.AddString(GetFileName(str)); 
		  }
		LoadFlash(m_PlayList.GetAt(0));

	}
	
}

void CPlayerDlg::OnClose() 
{
	// TODO: Add your command handler code here
	m_Flash.SetMovie("http://");//只有这样才能关闭Flash
	KillTimer(m_nTimer);
	m_slider.SetPos(0); 
	TimerFlag=false;
}

void CPlayerDlg::OnOpennet() 
{
	// TODO: Add your command handler code here
	COpenNetDlg dlg;
	if (dlg.DoModal()==IDOK)
	{
		m_Flash.SetMovie(dlg.m_URL);
	}
}

void CPlayerDlg::OnExit() 
{
	// TODO: Add your command handler code here
	DestroyWindow();
}

void CPlayerDlg::On100() 
{
	m_Flash.SetScaleMode(0);
	// TODO: Add your command handler code here
	m_Flash.SetScale("%100");
	GetMenu()->GetSubMenu(1)->CheckMenuItem(IDM_100,MF_BYCOMMAND |MF_CHECKED);
	GetMenu()->GetSubMenu(1)->CheckMenuItem(IDM_VIEWALL,MF_BYCOMMAND |MF_UNCHECKED);
}

void CPlayerDlg::OnFullscreen() 
{
	// TODO: Add your command handler code here
	 if(!ScreenFlag)
	 {
		 GetWindowPlacement(&m_WndPos); 
		 m_Flash.GetWindowPlacement(&m_FlashPos);  
		 m_Flash.GetWindowRect(FlashRect);  
		m_slider.ShowWindow(SW_HIDE );
		 SetMenu(NULL);  
		 DrawMenuBar();
		
		 m_strslider.ShowWindow(SW_HIDE);
		 HWND hwnd=this->GetSafeHwnd();
		 LONG style=GetWindowLong(hwnd,GWL_STYLE);
		 SetWindowLong(hwnd,GWL_STYLE,style-WS_CAPTION );
		 CClientDC dc(this);
		 this->MoveWindow(-3,-3,dc.GetDeviceCaps(HORZRES)+6,dc.GetDeviceCaps(VERTRES)+6);
		 m_Flash.SetWindowPos(&CWnd::wndTop ,0,0,dc.GetDeviceCaps(HORZRES),dc.GetDeviceCaps(VERTRES),SWP_SHOWWINDOW);
		 ScreenFlag=TRUE;////////////////////

	 } 
}

void CPlayerDlg::OnViewall() 
{
	// TODO: Add your command handler code here
//	m_Flash.SetWMode(0);
	//m_Flash.set
	m_Flash.SetScaleMode(2);
	GetMenu()->GetSubMenu(1)->CheckMenuItem(IDM_100,MF_BYCOMMAND |MF_UNCHECKED);
	GetMenu()->GetSubMenu(1)->CheckMenuItem(IDM_VIEWALL,MF_BYCOMMAND |MF_CHECKED);
}

void CPlayerDlg::OnZoomin() 
{
	// TODO: Add your command handler code here
	m_Flash.Zoom(50);
	ZoomFlag++;
}

void CPlayerDlg::OnZoomout() 
{
	// TODO: Add your command handler code here
	m_Flash.Zoom(200);
	ZoomFlag--;
}

void CPlayerDlg::OnQualityHigh() 
{
	// TODO: Add your command handler code here
	m_Flash.SetQuality2("High");
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(2,MF_BYPOSITION  |MF_CHECKED);
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(1,MF_BYPOSITION  |MF_UNCHECKED);
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(0,MF_BYPOSITION  |MF_UNCHECKED);
}

void CPlayerDlg::OnQualityLow() 
{
	// TODO: Add your command handler code here
	m_Flash.SetQuality2("low");
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(0,MF_BYPOSITION  |MF_CHECKED);
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(1,MF_BYPOSITION  |MF_UNCHECKED);

⌨️ 快捷键说明

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