首页/技术开发/内容

VC中运用FLASH制作图声并茂的动画程序

技术开发2023-09-14 阅读()
WS_VISIBLE,CRect(0,0,0,0), this, 1024);
    SetTimer (1,0,NULL);
    SetTimer (2,12000,NULL);
    CRect m_rect;
    GetClientRect (&m_rect );
    myflash.MoveWindow (&m_rect);//使flash 控件占满整个视区域
    return 0;
}

char *a = new char [512];
GetCurrentDirectory (100,a);
CString  *s=new CString(a);
myflash.LoadMovie (0,*s+CString("\\zf.swf"));//这里一定要为全路径
myflash.Play();//播放FLASH动画
(5)两个高级话题
5.1 在VC中用COM接口对ms agent 进行操作 #include "stdafx.h"
#include <ole2.h>
#include <AgtSvr.h>
#include <AgtSvr_i.c>
#include <tchar.h>

const LPWSTR kpwszCharacter =L"dot.acs";
int APIENTRY WinMain(HINSTANCE hInstance,
           HINSTANCE hPrevInstance,
        LPSTR     lpCmdLine,
      int       nCmdShow)
{
IAgent *pAgent;
if (FAILED(OleInitialize(NULL)))
     return -1;
HRESULT hRes=CoCreateInstance (CLSID_AgentServer,
          NULL,
           CLSCTX_LOCAL_SERVER,
           IID_IAgent,
           (LPVOID*)&pAgent);
//下面的代码调用IAgent::Load()方法来装入一个动画人物的数据
//由于Agent服务器在自己的内存空间中运行,所以传送的字符串变量需要用SysAllocString()来分配内存

VARIANTARG  vPath;
VariantInit(&vPath);

//初始化OLE变量
vPath.vt = VT_BSTR;

//指明变量类型为Unicode的字符串
vPath.bstrVal=SysAllocString(lpCharacter);

//lpCharacter 为动画人物数据的存放路径

long __RPC_FAR   lCharID,lRequestID;
hRes=pAgent->Load(vPath,&lCharID,&lRequestID);//装入数据人物ID在lCharID中返回

IDispatch  *pdCharacter;
hRes=pAgent->GetCharacter(lCharID,&pdCharacter);
//获取 lCharID的IDispatch接口指针调用IDispatch::QueryInterface()方法

//可以得到IAgentCharacter的接口指针:
IAgentCharacter  *pCharacter;
hRes=pdCharacter->QueryInterface(IID_IAgentCharacter,
           (LPVOID*)&pCharacter);

pdCharacter->Release();

//释放IDispath 通过IAgentCharacter接口就可以调用动画人物支持的各种方法了:

hRes = pCharacter->Show(FALSE,&lRequestID); //显示动画人物
hRes = pCharacter->MoveTo(320,240,100,&lRequestID);//移动动画人物到屏幕中央
BSTR bszSpeak = SysAllocString(L"Hello World!");//分配字符串
hRes = pCharacter->Speak(bszSpeak,NULL,&lRequestID);//让动画人物说话

SysFreeString(bszSpeak);//释放字符串所占内存

// 程序在退出之前需要把创建的Agent对象释放:

if(pCharacter){
    pCharacter->Release();//释放IAgentCharacter接口
    pAgent->Unload(lCharID); //卸载动画人物数据
}
pAgent->Release(); //释放Agent对象
VariantClear(&vPath); //清除OLE变量
}

下载MS AGENT演示源代码(VC)11.1K

5.2 同步问题还可用信号灯来实现
在vc 中进行启动时第一步就创建信号量,值为0。在启动vb创建的程序,然后vc中进行p操作. vb创建的程序中 在退出时使用v操作。实现同步。 P (s):
S - -
If s<0
Then 挂起当前进程
对应:win32 API :WaitForSingleObject  

V(s):
   S++
If s<=0
Then 在s的等待队列中唤醒一进程
对应:win32 API :ReleaseSemaphore  

(6)后记
本程序写于6月份,当时是一个朋友的生日,它是作为一个礼物送给她的。开始的时候,只提供了简单的窗口界面后来,在看了几位高手的佳作后,将它改进了一下。并希望和大家一起讨论,将它更加完美。 

第1页  第2页  第3页  第4页  第5页 

……

相关阅读