在VISUALBAISC5.0中可以使用播放视频动画文件(*.AVI)的方法在我们的软件中加入动画效果,但在软件中如何实现视频画中画的效果呢?经笔者摸索,发现利用WIDOWS95的API函数mciExecute、mciSendString和SetWindowPos可实现这一效果。
下面笔者以最常用的大画面中叠加小画面为例来说明视频画中画的实现方法。
一、建立窗体。进入VISUALBAISC5.0系统环境,建立一个新的窗体FORM1。
二、建立视频窗口。在这里笔者使用了一大一小的两个图画框(PictureBox)作为视频窗口。选择控件工具箱中的PictureBox控件,在窗体中拉出两个方框(Picture1和Picture2)。其中Picture1为大画面,播放AVI01.AVI文件;Picture2为小画面,播放AVI02.AVI文件。
三、编写相应控件的脚本。
通用模块:
DeclareFunctionmciExecuteLib”winmm.dll”(ByVallpstrCommandAsString)AsLong
DeclareFunctionmciSendStringLib”winmm.dll”Alias”mciSendStringA”(ByVallpstrCommandAsString,ByVallpstrReturnStringAsString,ByValuReturnLengthAsLong,ByValhwndCallbackAsLong)AsLong
DeclareFunctionSetWindowPosLib”user32″(ByValhwndAsLong,ByValhWndInsertAfterAsLong,ByValxAsLong,ByValyAsLong,ByValcxAsLong,ByValcyAsLong,ByValwFlagsAsLong)AsLong
FORM1的ACTIVATE过程:
DimAAAsLong
DimPlayAviAsLong
DimtmpValAsString
DimKeyValSizeAsLong
OnErrorResumeNext
tmpVal=String$(1024,0)
KeyValSize=1024
PlayAvi=mciSendString(“STATUSAVI01READY” Str(Picture2.hwnd),tmpVal,KeyValSize,0)
IfPlayAvi<>263Then
PlayAvi=mciExecute(“closeAVI01”)
EndIf
tmpVal=String$(1024,0)
KeyValSize=1024
PlayAvi=mciSendString(“OPENAVI01.AVIALIASAVI01TYPEAVIVIDEOSTYLECHILDPARENT” Str(Picture2.hwnd) “WAIT”,tmpVal,KeyValSize,0)
x1Pos=Picture1.Width
y1Pos=Picture1.Height
tmpVal=String$(1024,0)
KeyValSize=1024
AA=mciSendString(“STATUSAVI01WINDOWHANDLEWAIT”,tmpVal,KeyValSize,0)
If(Asc(Mid(tmpVal,KeyValSize,1))=0)Then
tmpVal=Left(tmpVal,KeyValSize-1)
Else
tmpVal=Left(tmpVal,KeyValSize)
EndIf
AA=SetWindowPos(tmpVal,0,0,0,x1Pos,y1Pos,0)
AA=mciExecute(“WINDOWAVI01STATESHOW”)
tmpVal=String$(1024,0)
KeyValSize=1024
PlayAvi=mciSendString(“STATUSAVI02READY” Str(Picture1.hwnd),tmpVal,KeyValSize,0)
IfPlayAvi<>263Then
PlayAvi=mciExecute(“CLOSEAVI02”)
EndIf
tmpVal=String$(1024,0)
KeyValSize=1024
PlayAvi=mciSendString(“OPENAVI02.AVIALIASAVI02TYPEAVIVIDEOSTYLECHILDPARENT” Str(Picture1.hwnd) “WAIT”,tmpVal,KeyValSize,0)
x1Pos=Picture2.Width
y1Pos=Picture2.Height
tmpVal=String$(1024,0)
KeyValSize=1024
AA=mciSendString(“STATUSAVI02WINDOWHANDLEWAIT”,tmpVal,KeyValSize,0)
If(Asc(Mid(tmpVal,KeyValSize,1))=0)Then
tmpVal=Left(tmpVal,KeyValSize-1)
Else
tmpVal=Left(tmpVal,KeyValSize)
EndIf
AA=SetWindowPos(tmpVal,0,0,0,x1Pos,y1Pos,0)
MciExecute”WINDOWAVI02STATESHOW”
MciExecute”PLAYAVI01REPEAT”
MciExecute”PLAYAVI02REPEAT”
OnErrorGoTo0
FORM1的QueryUnload过程:
mciExecute”STOPAVI01″
mciExecute”STOPAVI02″
mciExecute”CLOSEAVI01″
mciExecute”CLOSEAVI02″
运行此程序可见两个动画同时播放,实现了视频画中画的效果。以上程序在VISUALBAISC5.0及WINDOWS95中运行通过。->