FlashPlayer

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VC中添加flash控件2006-08-17 16:59shockware Flash Object.lnk

..\Windows\system32\Macromed\Flash\Flash9.ocx

在"VC开发环境"中,选择"工程"->"添加工程"->Components and controls->..\programFiles\Microsoft Visual Studio\Common\MSDev98\Gallery\Registered ActiveX Controls

选择"shockware Flash Object.lnk",添加Flash控件。

在Flash.h中

#include "shockwaveflash.h"
class CFlash : public CDialog
{

……

public:
//------------Flash文件---------------
char PathName[255];// 保存flash文件名
void FlashRun(); //*.swf文件运行
void FlashPause(); //*.swf文件暂停
void FlashStop(); //*.swf文件停止
long lMSEL; //定义总的播放毫秒数
long CurrentNum; //保存当前的帧数CurrentFrame()
// long CMSEL; //定义当前的已经播放的时间


……


}

在Flash.cpp中

long i_TotalNum=0; //保存总帧数GetTotalFrames()
long CMSEL=0; //定义当前的已经播放的时间

//--------------*.swf----
void CFlash::FlashRun()
{
long state=0;
UpdateData(FALSE);

CMSEL=0;//定义当前的已经播放的时间

CurrentNum=0;
m_FlashOCX.LoadMovie(0,PathName);
state=m_FlashOCX.GetReadyState();
m_FlashOCX.Zoom(0);//还原大小,显示全部的内容

// long lMSEL=0; //定义总的播放毫秒数
if(state==4)
{
m_FlashOCX.GotoFrame(0);
CurrentNum=m_FlashOCX.CurrentFrame();
i_TotalNum=m_FlashOCX.GetTotalFrames();
m_FlashOCX.GotoFrame(CurrentNum);

lMSEL=i_TotalNum; //得到总的毫秒数,将总帧数转换为毫秒数
m_FlashOCX.Play();//播放
SetTimer(3,10,NULL);
}
}

void CFlash::FlashPause()
{
m_FlashOCX.Stop(); //在当前帧位置停止播放
KillTimer(3);
}

void CFlash::FlashStop()
{
KillTimer(3);
m_FlashOCX.GotoFrame(m_FlashOCX.GetTotalFrames()-1);//移动到最后一帧
m_FlashOCX.Stop(); //在末尾停止播放
m_FlashOCX.Zoom(0);//还原大小,显示全部的内容
m_FlashOCX.SetBGColor("0");
}

void CFlash::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int oldNum=CurrentNum;
CurrentNum=m_FlashOCX.CurrentFrame();
if(oldNum!=CurrentNum)
CMSEL=CMSEL+1; //保存现在已经播放的时间数

if(CurrentNum>=i_TotalNum-1)
{ FlashStop(); /*m_FlashOCX.StopPlay();*/ }
else
{
if(CMSEL>=lMSEL) //lMSEL为总的播放时间,CMSEL为当前已经播放的时间数
FlashStop();
else
{
m_FlashOCX.Zoom(0);//还原大小,显示全部的内容
if(m_FlashOCX.IsPlaying()==FALSE)//判断*.swf文件是否正在播放
{ m_FlashOCX.Play(); }
}
}
CDialog::OnTimer(nIDEvent);
}
/////////////////////////

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

“播放”按钮代码:
flash.Play();

“暂停”按钮代码:
flash.St

op();

“停止”按钮代码:
flash.Rewind();
flash.Stop();

“重播”按钮代码:
flash.Rewind();
flash.Play();

“后退”按钮代码:
flash.Back();

“前进”按钮代码:
flash.Forward();

“末帧”按钮代码:
flash.GotoFrame(flash.get_TotalFrames()-1);



“快退”按钮代码:
int current=flash.CurrentFrame();
if(current>4)
{
current-=5;
flash.GotoFrame(current);
}
else
{
flash.put_FrameNum(0);
}

“快进”按钮代码:
int current=flash.CurrentFrame();
int i=flash.get_FrameNum();
if(current{
current+=5;
flash.GotoFrame(current);
}
else
{
flash.put_FrameNum(flash.get_TotalFrames()-1);
}

“放大”按钮代码:
flash.Zoom(50);

“缩小”按钮代码:
flash.Zoom(200);

“还原”按钮代码:
flash.Zoom(0);
////////////////////////////////////////////////////////////////

project ---> add To project ---> components and Controls

插入Shockwave Flash Object
编译器会插入一个CShockwaveFlash类。。

在你的view类里面声明一个CShockwaveFlash成员
CShockwaveFlash m_flash;

然后映射WM_CREATE消息
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (!CView::OnCreate(lpCreateStruct))
return -1;
m_flash.Create(NULL, WS_CHILD | WS_VISIBLE,
CRect(0, 0, 500, 500), this, 1111);
m_flash.LoadMovie("你的swf文件绝对路径");
m_flash.Play();
return 0;
}
---------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
// Use swflash.ocx to play flash
// if it works, it is written by masterz, otherwise I don't know who writes it(*_*)
////////////////////////////////////////////////////////////////////////////////
#define MAX_LOADSTRING 100
#import "c:\winnt\system32\macromed\flash\flash.ocx"
#include
CComModule _Module;
#include
#pragma comment(lib,"atl")
#define ODS(x) OutputDebugString(x)


// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
CAxWindow m_container;
using namespace ShockwaveFlashObjects;
IShockwaveFlash* shwaveflash;

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Initialize global strings
wsprintf(szTitle,"use flash control in sdk exe");
wsprintf(szWindowClass

,"flashinsdk");
MyRegisterClass(hInstance);
CoInitialize(NULL);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
return FALSE;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
return msg.wParam;
}

// FUNCTION: MyRegisterClass()
// PURPOSE: Registers the window class.
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;//(LPCSTR)IDC_FLSH;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
return RegisterClassEx(&wcex);
}

// FUNCTION: InitInstance(HANDLE, int)
// PURPOSE: Saves instance handle and creates main window
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
AtlAxWinInit();
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
HWND heditfilepath;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
wsprintf(szHello,"use flash control in sdk");
HWND hbtnstart;
RECT rc;
switch (message)
{
case WM_CREATE:
GetClientRect(hWnd, &rc );
rc.top = (rc.bottom+rc.top)/2;
m_container.Create( hWnd, rc, LPCTSTR("ShockwaveFlash.ShockwaveFlash.1"), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL );//create a browser control
hbtnstart=CreateWind





相关文档
最新文档