visual basic以其简单、快捷的特点深受广大多媒体开发者的喜爱。用visual basicfor windows 95(以下简称vb4.0)可以迅速地编写出真正的windows 95应用软件,尤其是在vb4.0中通过调用windows 95 api函数,一方面可以灵活地利用windows 95提供的系统资源,另一方面无需调用vb的mci(多媒体控制接口),使多媒体软件编写更方便。
本文所提供的源程序,具有简单、方便操作和易于移植使用的特点。
该程序可以使用户选择播放*.avi文件,如稍加改动即可播放其他格式的多媒体文件。本程序经vb4.0编译通过。
调用*.avi文件源程序如下:
源程序清单:
’窗体files01.frm的特性表
version 4.00
begin vb.form files01
caption="files"
clientheight=4365
clientleft=1095
clienttop=1515
clientwidth=7230
height=4770
left=1035
linktopic="files"
scaleheight=4365
scalewidth=7230
top=1170
width=7350
begin vb.commandbutton command1
caption="ok"
height=735
left=5880
tabindex=4
top=1800
width=615
end
begin vb.textbox text1
height=375
left=600
tabindex=3
top=360
width=5415
end
begin vb.filelistbox file1
height=2760
left=2760
tabindex=2
top=1080
width=2175
end
begin vb.dirlistbox dir1
height=2280
left=600
tabindex=1
top=1560
width=1815
end
begin vb.drivelistbox drive1
height=315
left=720
tabindex=0
top=1080
width=1695
end
end
’窗体files01.frm代码
attribute vb-name="files01"
attribute vb-creatable=false
attribute vb-exposed=false
private sub command1-click()
load file02
flie02.show
end sub
private sub dir1-change()
flie1.path=dir1.path
end sub
private sub drive1-change()
dir1.path=drive1.drive
end sub
private sub file1-click()
flie1.path=dir1.path
end sub
private sub file1-dblclick()
pth$=dir1.path
if right$(pth$,1)="\"then
text1.text=pth$+file1.filename
else
text1.text=pth$+"\"+file1.filename
end if
end sub
’窗体file02.frm特性表
version 4.00
begin vb.form file02
caption="file02"
clientheight=4230
clientleft=1095
clienttop=1515
clientwidth=6720
height=4635
left=1035
linktopic="form1"
scaleheight=4230
scalewidth=6720
top=1170
width=6840
begin vb.commandbutton command3
caption="end"
height=735
left=2400
tabindex=2
top=2520
width=3135
end
begin vb.commandbutton command2
caption="stop"
height=975
left=4920
tabindex=1
top=720
width=1455
end
begin vb.commandbutton command1
caption="play"
height=975
left=360
tabindex=0
top=600
width=3135
end
end
’窗体file02代码
attribute vb-name="file02"
attribute vb-creatable=false
attribute vb-exposed=false
private sub command1-click()
aa
end sub
private sub command2-click()
i&=mciexecute("close video")
unload file02
unload file01
load files01
flies01.show
end sub
private sub command3-click()
i&=mciexecute("close video")
end
end sub
’多媒体调用模块
attribute vb-name="module1"
declare function mciexecute lib "c:\win95\system\winmm.d
ll"->
(by val meicommand as string) as long
sub aa()
if files01.text1.text=""then
unload file02
load files01files01.show
end if
on error resume next
tf$="open"+files01.text1.text+"type avivideo alias video
"
i&=mciexecute(tf$)
i&=mciexecute("play video")
end sub
与vb3.0在windows 3.1中使用动态程序连接库mmsystem.dll不同,vb4.0使用windows95中的动态程序连接库winmm.dll。若运行本程序应首先调用files01.frm,然后选取所要调用的avi文件,最后进行播放。如想播放其他格式的文件,只需将语句:
tf$="open"+files01.text1.text+"type avivideo alias video
"中的"type avivideoalias video"以及程序中与别名有关语句作相应的改动即可。