VB4.0与Windows 95 API接口的多媒体应用程序设计实例
|
本文所提供的源程序,具有简单、方便操作和易于移植使用的特点。该程序可以使用户选择播放*.AVI文件,如稍加改动即可播放其他格式的多媒体文件。本程序经VB4.0编译通过。调用*.AVI文件源程序如下:源程序清单:’窗体files01.frm的特性表VERSION 4.00Begin VB.Form files01Caption=FilesClientHeight=4365ClientLeft=1095ClientTop=1515ClientWidth=7230Height=4770Left=1035LinkTopic=filesScaleHeight=4365ScaleWidth=7230Top=1170Width=7350Begin VB.CommandButton Command1Caption=OkHeight=735Left=5880TabIndex=4Top=1800Width=615EndBegin VB.TextBox text1Height=375Left=600TabIndex=3Top=360Width=5415EndBegin VB.FileListBox File1Height=2760Left=2760TabIndex=2Top=1080Width=2175EndBegin VB.DirListBox Dir1Height=2280Left=600TabIndex=1Top=1560Width=1815EndBegin VB.DriveListBox Drive1Height=315Left=720TabIndex=0Top=1080Width=1695EndEnd’窗体files01.frm代码Attribute VB-Name=files01Attribute VB-Creatable=FalseAttribute VB-Exposed=FalsePrivate Sub Command1-Click()Load file02flie02.ShowEnd SubPrivate Sub Dir1-Change()flie1.Path=Dir1.PathEnd SubPrivate Sub Drive1-Change()Dir1.Path=Drive1.DriveEnd SubPrivate Sub File1-Click()flie1.Path=Dir1.PathEnd SubPrivate Sub File1-DblClick()pth$=Dir1.PathIf Right$(pth$,1)=\ThenText1.Text=pth$+File1.FileNameElseText1.Text=pth$+\+File1.FileNameEnd IfEnd Sub’窗体file02.frm特性表VERSION 4.00Begin VB.Form file02Caption=file02ClientHeight=4230ClientLeft=1095ClientTop=1515ClientWidth=6720Height=4635Left=1035LinkTopic=Form1ScaleHeight=4230ScaleWidth=6720Top=1170Width=6840Begin VB.CommandButton Command3Caption=EndHeight=735Left=2400TabIndex=2Top=2520Width=3135EndBegin VB.CommandButton Command2Caption=StopHeight=975Left=4920TabIndex=1Top=720Width=1455EndBegin VB.CommandButton Command1Caption=PlayHeight=975Left=360TabIndex=0Top=600Width=3135EndEnd’窗体file02代码Attribute VB-Name=file02Attribute VB-Creatable=FalseAttribute VB-Exposed=FalsePrivate Sub Command1-Click()aaEnd SubPrivate Sub Command2-Click()i&=mciExecute(close video)Unload file02Unload file01Load files01flies01.ShowEnd SubPrivate Sub Command3-Click()i&=mciExecute(close video)EndEnd Sub’多媒体调用模块Attribute VB-Name=Module1Declare Function mciExecute Lib c:\win95\system\winmm.dll->(By Val Meicommand As String) As LongSub aa()If files01.Text1.Text=ThenUnload file02Load files01files01.ShowEnd IfOn Error Resume Nexttf$=open+files01.Text1.Text+type avivideo alias videoi&=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以及程序中与别名有关语句作相应的改动即可。 作者:未知 | |