In VISUALBAISC5.0, you can use the method of playing video animation files (*.AVI) to add animation effects to our software, but how to achieve the video picture-in-picture effect in the software? After the author's exploration, I found that this effect can be achieved by using the API functions mciExecute, mciSendString and SetWindowPos of WIDOWS95.
Below, the author takes the most commonly used method of superimposing a small picture on a large picture as an example to illustrate the implementation method of video picture-in-picture.
1. Create a form. Enter the VISUALBAISC5.0 system environment and create a new form FORM1.
2. Create a video window. Here the author uses two picture boxes (PictureBox), one large and one small, as the video window. Select the PictureBox control in the Control Toolbox and pull out two boxes (Picture1 and Picture2) in the form. Among them, Picture1 is a large screen and plays the AVI01.AVI file; Picture2 is a small screen and plays the AVI02.AVI file.
3. Write the script for the corresponding control.
Common modules:
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
ACTIVATE process of FORM1:
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
QueryUnload process of FORM1:
mciExecute"STOPAVI01"
mciExecute"STOPAVI02"
mciExecute"CLOSEAVI01"
mciExecute"CLOSEAVI02"
When you run this program, you can see that two animations are played at the same time, achieving the picture-in-picture effect of the video. The above program runs successfully in VISUALBAISC5.0 and WINDOWS95. ->