2013.07.04《用VC++实现Flash的播…

这个博客详细介绍了如何在VC++环境下创建一个对话框,并集成CShockwaveFlash控件来实现Flash电影的播放。通过CFlashDlg类的定义和实现,展示了初始化对话框、加载Flash文件以及播放控制的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2013.07.04《用VC++实现Flash的播放的具体代码》
// FlashDlg.cpp : implementation file
//

#include "stdafx.h"


#include "Flash.h"
#include "FlashDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CFlashDlg dialog

CFlashDlg::CFlashDlg(CWnd* pParent )
 : CDialog(CFlashDlg::IDD, pParent)
{
 //{{AFX_DATA_INIT(CFlashDlg)
  // NOTE: the ClassWizard will add member initialization here
 //}}AFX_DATA_INIT
 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFlashDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CFlashDlg)
 DDX_Control(pDX, IDC_SHOCKWAVEFLASH1, m_Flashplayer);
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFlashDlg, CDialog)
 //{{AFX_MSG_MAP(CFlashDlg)
 ON_WM_SYSCOMMAND()
 ON_WM_PAINT()
 ON_WM_QUERYDRAGICON()
 ON_WM_CREATE()
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFlashDlg message handlers

BOOL CFlashDlg::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
 
 return TRUE;  // return TRUE  unless you set the focus to a control
}

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

int CFlashDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CDialog::OnCreate(lpCreateStruct) == -1)
  return -1;
 
 m_flash.Create("flash", WS_CHILD | WS_VISIBLE | WS_HSCROLL| WS_VSCROLL, CRect(0,0, 500,500), this, 102);    //这段代码在其他方法里面执行没作用的

         m_flash.LoadMovie(0,"D:/login.swf"); //flash 10d.ocx没有setMovie方法
         m_flash.Play();// TODO: Add your specialized creation code here
 
 return 0;
}

// Flash.h : main header file for the FLASH application
//

#if !defined(AFX_FLASH_H__390FAE81_D26D_4310_BAD0_F6855EF9A468__INCLUDED_)
#define AFX_FLASH_H__390FAE81_D26D_4310_BAD0_F6855EF9A468__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
 #error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"  // main symbols

/////////////////////////////////////////////////////////////////////////////
// CFlashApp:
// See Flash.cpp for the implementation of this class
//

class CFlashApp : public CWinApp
{
public:
 CFlashApp();

// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CFlashApp)
 public:
 virtual BOOL InitInstance();
 //}}AFX_VIRTUAL

// Implementation

 //{{AFX_MSG(CFlashApp)
  // NOTE - the ClassWizard will add and remove member functions here.
  //    DO NOT EDIT what you see in these blocks of generated code !
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FLASH_H__390FAE81_D26D_4310_BAD0_F6855EF9A468__INCLUDED_)

 

 

// FlashDlg.h : header file
//
//{{AFX_INCLUDES()
#include "shockwaveflash.h"
//}}AFX_INCLUDES

#if !defined(AFX_FLASHDLG_H__E3F78F02_ADD8_4C28_B3E7_ACFAC136B3B7__INCLUDED_)
#define AFX_FLASHDLG_H__E3F78F02_ADD8_4C28_B3E7_ACFAC136B3B7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "shockwaveflash.h"

/////////////////////////////////////////////////////////////////////////////
// CFlashDlg dialog

class CFlashDlg : public CDialog
{
// Construction
public:
  CShockwaveFlash  m_flash; 
 CFlashDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
 //{{AFX_DATA(CFlashDlg)
 enum { IDD = IDD_FLASH_DIALOG };
 CShockwaveFlash m_Flashplayer;
 //}}AFX_DATA

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

// Implementation
protected:
 HICON m_hIcon;

 // Generated message map functions
 //{{AFX_MSG(CFlashDlg)
 virtual BOOL OnInitDialog();
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
 afx_msg void OnPaint();
 afx_msg HCURSOR OnQueryDragIcon();
 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FLASHDLG_H__E3F78F02_ADD8_4C28_B3E7_ACFAC136B3B7__INCLUDED_)

 

 

 

#if !defined(AFX_SHOCKWAVEFLASH_H__C0BDCC00_9CAF_44E2_A228_D4C3B036594C__INCLUDED_)
#define AFX_SHOCKWAVEFLASH_H__C0BDCC00_9CAF_44E2_A228_D4C3B036594C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.

/////////////////////////////////////////////////////////////////////////////
// CShockwaveFlash wrapper class

class CShockwaveFlash : public CWnd
{
protected:
 DECLARE_DYNCREATE(CShockwaveFlash)
public:
 CLSID const& GetClsid()
 {
  static CLSID const clsid
   = { 0xd27cdb6e, 0xae6d, 0x11cf, { 0x96, 0xb8, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0 } };
  return clsid;
 }
 virtual BOOL Create(LPCTSTR lpszClassName,
  LPCTSTR lpszWindowName, DWORD dwStyle,
  const RECT& rect,
  CWnd* pParentWnd, UINT nID,
  CCreateContext* pContext = NULL)
 { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
  const RECT& rect, CWnd* pParentWnd, UINT nID,
  CFile* pPersist = NULL, BOOL bStorage = FALSE,
  BSTR bstrLicKey = NULL)
 { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
  pPersist, bStorage, bstrLicKey); }

// Attributes
public:

// Operations
public:
 long GetReadyState();
 long GetTotalFrames();
 BOOL GetPlaying();
 void SetPlaying(BOOL bNewValue);
 long GetQuality();
 void SetQuality(long nNewValue);
 long GetScaleMode();
 void SetScaleMode(long nNewValue);
 long GetAlignMode();
 void SetAlignMode(long nNewValue);
 long GetBackgroundColor();
 void SetBackgroundColor(long nNewValue);
 BOOL GetLoop();
 void SetLoop(BOOL bNewValue);
 CString GetMovie();
 void SetMovie(LPCTSTR lpszNewValue);
 long GetFrameNum();
 void SetFrameNum(long nNewValue);
 void SetZoomRect(long left, long top, long right, long bottom);
 void Zoom(long factor);
 void Pan(long x, long y, long mode);
 void Play();
 void Stop();
 void Back();
 void Forward();
 void Rewind();
 void StopPlay();
 void GotoFrame(long FrameNum);
 long CurrentFrame();
 BOOL IsPlaying();
 long PercentLoaded();
 BOOL FrameLoaded(long FrameNum);
 long FlashVersion();
 CString GetWMode();
 void SetWMode(LPCTSTR lpszNewValue);
 CString GetSAlign();
 void SetSAlign(LPCTSTR lpszNewValue);
 BOOL GetMenu();
 void SetMenu(BOOL bNewValue);
 CString GetBase();
 void SetBase(LPCTSTR lpszNewValue);
 CString GetScale();
 void SetScale(LPCTSTR lpszNewValue);
 BOOL GetDeviceFont();
 void SetDeviceFont(BOOL bNewValue);
 BOOL GetEmbedMovie();
 void SetEmbedMovie(BOOL bNewValue);
 CString GetBGColor();
 void SetBGColor(LPCTSTR lpszNewValue);
 CString GetQuality2();
 void SetQuality2(LPCTSTR lpszNewValue);
 void LoadMovie(long layer, LPCTSTR url);
 void TGotoFrame(LPCTSTR target, long FrameNum);
 void TGotoLabel(LPCTSTR target, LPCTSTR label);
 long TCurrentFrame(LPCTSTR target);
 CString TCurrentLabel(LPCTSTR target);
 void TPlay(LPCTSTR target);
 void TStopPlay(LPCTSTR target);
 void SetVariable(LPCTSTR name, LPCTSTR value);
 CString GetVariable(LPCTSTR name);
 void TSetProperty(LPCTSTR target, long property, LPCTSTR value);
 CString TGetProperty(LPCTSTR target, long property);
 void TCallFrame(LPCTSTR target, long FrameNum);
 void TCallLabel(LPCTSTR target, LPCTSTR label);
 void TSetPropertyNum(LPCTSTR target, long property, double value);
 double TGetPropertyNum(LPCTSTR target, long property);
 double TGetPropertyAsNumber(LPCTSTR target, long property);
 CString GetSWRemote();
 void SetSWRemote(LPCTSTR lpszNewValue);
 CString GetFlashVars();
 void SetFlashVars(LPCTSTR lpszNewValue);
 CString GetAllowScriptAccess();
 void SetAllowScriptAccess(LPCTSTR lpszNewValue);
 CString GetMovieData();
 void SetMovieData(LPCTSTR lpszNewValue);
 LPUNKNOWN GetInlineData();
 void SetInlineData(LPUNKNOWN newValue);
 BOOL GetSeamlessTabbing();
 void SetSeamlessTabbing(BOOL bNewValue);
 void EnforceLocalSecurity();
 BOOL GetProfile();
 void SetProfile(BOOL bNewValue);
 CString GetProfileAddress();
 void SetProfileAddress(LPCTSTR lpszNewValue);
 long GetProfilePort();
 void SetProfilePort(long nNewValue);
 CString CallFunction(LPCTSTR request);
 void SetReturnValue(LPCTSTR returnValue);
 void DisableLocalSecurity();
 CString GetAllowNetworking();
 void SetAllowNetworking(LPCTSTR lpszNewValue);
 CString GetAllowFullScreen();
 void SetAllowFullScreen(LPCTSTR lpszNewValue);
 CString GetAllowFullScreenInteractive();
 void SetAllowFullScreenInteractive(LPCTSTR lpszNewValue);
 BOOL GetIsDependent();
 void SetIsDependent(BOOL bNewValue);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SHOCKWAVEFLASH_H__C0BDCC00_9CAF_44E2_A228_D4C3B036594C__INCLUDED_)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值