在Visual Basic 6.0中实现自动播放VCD

2016-02-19 18:43 10 1 收藏

下面图老师小编要向大家介绍下在Visual Basic 6.0中实现自动播放VCD,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!

【 tulaoshi.com - 编程语言 】

《超级解霸》等VCD播放软件一般都有个按钮或菜单选项,叫做“播放VCD”,单击即可自动播放VCD影片。如果文件路径是固定的, 那只用多媒体控件(mmcontrol)即可实现,但对于不同电脑来说,因为硬盘的逻辑分区数量不同,光盘机的路径很可能是不同的。它到底是怎样实现的呢?下面,请看我详细分析:

用“regedit.exe”查看Windows98的注册表中光盘机的属性项(hkey_local_machine, enum, scsi),比较硬盘机的属性项(hkey_local_machine, enum, esdi)和软盘机
的属性项(hkey_local_machine, enum, flop),就可发现:不同的盘体,是用“devicetype”这个参数来区别的,硬盘的devicetype是“0”, 软盘是“0a”,光盘机是“5”。再用“devicetype”为关键字,查找有关win32 API的编程手册,就可得到辨别不同盘体的函数“getdevicetype”了。

有了这个函数,使用以下句子,即可得到光盘机盘符:

If GetDriveType("d:") 5 Then
If GetDriveType("e:") 5 Then
If GetDriveType("f:") 5 Then
If GetDriveType("g:") 5 Then
drivecd = "H"
GoTo getcdfiles
End If
drivecd = "G"
GoTo getcdfiles
End If
drivecd = "F"
GoTo getcdfiles
End If
drivecd = "E"
GoTo getcdfiles
Else
drivecd = "D"
End If
getcdfiles:

程序使用穷举法,依次判断D、E、F、G盘的devicetype是否为“5”,都不是则光盘机为H(盘符超过H的机器不多,所以穷举到此为止),得到的“drivecd”就是光盘机盘符。

因为所有VCD影片的路径都是mpegav,所以用VB函数"Dir()"便可得到完整的播放路径:
MMControl1.FileName = drivecd & ":Mpegav" & Dir(drivecd & ":Mpegav*.dat")。

以下源程序,具体实现了自动播放VCD。程序窗体中只有一个多媒体控件——MMcontrol1,程序一旦运行即从第一个文件开始自动播放,按多媒体控件上的“next”键,播放下一个文件。

'声明GetDriveType函数
Private Declare Function GetDriveType Lib "kernel32" Alias " GetDriveTypeA" (ByVal nDrive As String) As Long
Dim files() As String
Dim drivecd As String
Dim i As Integer
Dim j As Integer

Private Sub Form_Load()
'判断光盘机盘符
If GetDriveType("d:") 5 Then
If GetDriveType("e:") 5 Then
If GetDriveType("f:") 5 Then
If GetDriveType("g:") 5 Then
drivecd = "H"
GoTo getcdfiles
End If
drivecd = "G"
GoTo getcdfiles
End If
drivecd = "F"
GoTo getcdfiles
End If
drivecd = "E"
GoTo getcdfiles
Else
drivecd = "D"
End If

'将所有VCD文件放入数组files()
getcdfiles:
On Error GoTo cderr:
s = Dir(drivecd & ":Mpegav*.dat")
i = 1
While s ""
ReDim Preserve files(i) As String
files(i) = s
i = i + 1
s = Dir()
Wend
j = 1
Call vcdplay

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

On Error GoTo 0
Exit Sub
cderr:
MsgBox "CD is not ready!"
Unload Me
End Sub

'判断是否播放下一个文件
Private Sub MMControl1_StatusUpdate()
If MMControl1.Position = MMControl1.Length Then
j = j + 1
If j i - 1 Then j = 1
Call vcdplay
End If
End Sub

'播放VCD文件
Private Sub vcdplay()
MMControl1.Command = "stop"
MMControl1.Command = "close"
MMControl1.FileName = drivecd & ":Mpegav" & files(j)
MMControl1.Command = "open"
MMControl1.Command = "play"
End Sub

以上程序在中文Windows98,Visual Basic 6.0上通过。

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

来源:http://www.tulaoshi.com/n/20160219/1618745.html

延伸阅读
标签: windows系统
在Windows 8中禁用自动播放与运行功能   Windows的自动播放功能已经成为了用户的困扰,因为大多数病毒通过USB或是CD/DVD的自动播放与运行进行传播。在微软最新的Windows 8操作系统中,自动播放默认情况下是打开的。 当插入CD/DVD或是USB时会在右上角看到一个通知,点击后就会看到类似下图的界面,你可以选择操作。 如果...
标签: vb
如果你在Windows下使用过C/C++,那么编写这样的DLL可能没有什么困难。在C语言里都包括inp和outp函数。可以把下面这段C语言代码(32位)编译生成DLL,然后在VB中调用。 #include #include /*作用:从指定端口读入一个字节 参数:portid端口号 返回值:读入的字节*/ int _stdcall Inport(short portid) { return inp(portid);} ...
标签: vb
从 Visual Basic 6.0 到 Visual Basic.NET 的转换(1) Microsoft Visual Basic.NET 是 Microsoft Visual Basic? 的后续版本,它是基于 .NET 框架重新设计的,您可以用它来轻松地创建用于 Microsoft Windows? 操作系统和 Web 的下一代应用程序。使用 Visual Basic.NET,可视化开发 Web 应用程序、Web 服务、Windows 应用程序和服务器端组件...
标签: vb
升级 向导 将 Currency 数据类型转换为 Decimal,因此以下代码: Dim x As Currency 升级后将变为: Dim x As Decimal Date Visual Basic 6.0 Date 变量在内部以 Double 格式存储,能够作为 Double 类型的变量操作。 Date 变量存储为 IEEE 64 位浮点数,表示从 100 年 1 月 1 日到 9999 年 12 月 31 日的日期和从 0:...
标签: vb
升级 向导 过程的 ParamArray 参数标记有升级警告。例如,以下代码: Function MyFunction(ParamArray p() As Variant) ... End Function 升级后将变为: UPGRADE_WARNING: ParamArray p was changed from ByRef to ByVal Function MyFunction(ByVal ParamArray p() As Object) ... End Function 声明中的...

经验教程

419

收藏

31
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部