⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 这是一本用Visual Studio.NET进行多媒体编程的读物
💻 VB
字号:
Option Strict Off
Option Explicit On
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'对于启动窗体,所创建的第一个实例为默认实例。
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'此调用是 Windows 窗体设计器所必需的。
		InitializeComponent()
	End Sub
	'窗体重写处置,以清理组件列表。
	Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
		If Disposing Then
			If Not components Is Nothing Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(Disposing)
	End Sub
    Private components As System.ComponentModel.IContainer
	'Windows 窗体设计器所必需的
		Public ToolTip1 As System.Windows.Forms.ToolTip
	Public WithEvents CmdClose As System.Windows.Forms.Button
	Public WithEvents CmdOpen As System.Windows.Forms.Button
	Public WithEvents Check1 As System.Windows.Forms.CheckBox
	Public WithEvents StatusBar1 As AxMSComctlLib.AxStatusBar
	Public WithEvents Slider1 As AxMSComctlLib.AxSlider
	Public WithEvents CommonDialog1 As AxMSComDlg.AxCommonDialog
	Public WithEvents MMControl1 As AxMCI.AxMMControl
		Public WithEvents Label3 As System.Windows.Forms.Label
	Public WithEvents Label2 As System.Windows.Forms.Label
	Public WithEvents Label1 As System.Windows.Forms.Label
	'注意:以下过程是 Windows 窗体设计器所必需的
	'可以使用 Windows 窗体设计器来修改它。
	'不要使用代码编辑器来修改它。
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.MMControl1 = New AxMCI.AxMMControl()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.CmdOpen = New System.Windows.Forms.Button()
        Me.CommonDialog1 = New AxMSComDlg.AxCommonDialog()
        Me.StatusBar1 = New AxMSComctlLib.AxStatusBar()
        Me.Slider1 = New AxMSComctlLib.AxSlider()
        Me.Check1 = New System.Windows.Forms.CheckBox()
        Me.CmdClose = New System.Windows.Forms.Button()
        CType(Me.MMControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.CommonDialog1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.StatusBar1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Slider1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'MMControl1
        '
        Me.MMControl1.Enabled = True
        Me.MMControl1.Location = New System.Drawing.Point(174, 56)
        Me.MMControl1.Name = "MMControl1"
        Me.MMControl1.OcxState = CType(resources.GetObject("MMControl1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.MMControl1.Size = New System.Drawing.Size(302, 28)
        Me.MMControl1.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(10, 111)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(53, 20)
        Me.Label1.TabIndex = 3
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(225, 111)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(53, 20)
        Me.Label2.TabIndex = 4
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(440, 111)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(53, 20)
        Me.Label3.TabIndex = 6
        '
        'CmdOpen
        '
        Me.CmdOpen.BackColor = System.Drawing.SystemColors.Control
        Me.CmdOpen.Cursor = System.Windows.Forms.Cursors.Default
        Me.CmdOpen.Location = New System.Drawing.Point(10, 19)
        Me.CmdOpen.Name = "CmdOpen"
        Me.CmdOpen.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CmdOpen.Size = New System.Drawing.Size(114, 28)
        Me.CmdOpen.TabIndex = 7
        Me.CmdOpen.Text = "打开"
        '
        'CommonDialog1
        '
        Me.CommonDialog1.Enabled = True
        Me.CommonDialog1.Location = New System.Drawing.Point(461, 130)
        Me.CommonDialog1.Name = "CommonDialog1"
        Me.CommonDialog1.OcxState = CType(resources.GetObject("CommonDialog1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.CommonDialog1.Size = New System.Drawing.Size(32, 32)
        Me.CommonDialog1.TabIndex = 9
        '
        'StatusBar1
        '
        Me.StatusBar1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.StatusBar1.Location = New System.Drawing.Point(0, 124)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.OcxState = CType(resources.GetObject("StatusBar1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.StatusBar1.Size = New System.Drawing.Size(492, 29)
        Me.StatusBar1.TabIndex = 5
        '
        'Slider1
        '
        Me.Slider1.Location = New System.Drawing.Point(0, 93)
        Me.Slider1.Name = "Slider1"
        Me.Slider1.OcxState = CType(resources.GetObject("Slider1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.Slider1.Size = New System.Drawing.Size(493, 19)
        Me.Slider1.TabIndex = 1
        '
        'Check1
        '
        Me.Check1.BackColor = System.Drawing.SystemColors.Control
        Me.Check1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Check1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Check1.Location = New System.Drawing.Point(174, 19)
        Me.Check1.Name = "Check1"
        Me.Check1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Check1.Size = New System.Drawing.Size(90, 19)
        Me.Check1.TabIndex = 2
        Me.Check1.Text = "循环播放"
        '
        'CmdClose
        '
        Me.CmdClose.BackColor = System.Drawing.SystemColors.Control
        Me.CmdClose.Cursor = System.Windows.Forms.Cursors.Default
        Me.CmdClose.Location = New System.Drawing.Point(10, 56)
        Me.CmdClose.Name = "CmdClose"
        Me.CmdClose.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CmdClose.Size = New System.Drawing.Size(114, 28)
        Me.CmdClose.TabIndex = 8
        Me.CmdClose.Text = "关闭"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(492, 153)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CmdClose, Me.CmdOpen, Me.Check1, Me.StatusBar1, Me.Slider1, Me.CommonDialog1, Me.MMControl1, Me.Label3, Me.Label2, Me.Label1})
        Me.Location = New System.Drawing.Point(10, 29)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "MMControlPlayer"
        CType(Me.MMControl1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.CommonDialog1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.StatusBar1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Slider1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "升级支持"
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
	Private Sub CmdClose_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdClose.Click
		MMControl1.Command = "Close"
		CmdClose.Enabled = False
	End Sub
	
	Private Sub CmdOpen_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdOpen.Click
		' 设定打开文件类型
		CommonDialog1.Filter = "MIDI音乐序器*.mid|*.mid|声音*.wav|*.wav|Widows视频*.avi|*.avi"
		CommonDialog1.ShowOpen()
		MMControl1.Notify = False
		MMControl1.Wait = True
		MMControl1.Shareable = False
		'由系统默认设备类型
		MMControl1.DeviceType = ""
		MMControl1.FileName = CommonDialog1.FileName
		'打开 MCI 设备。
		MMControl1.Command = "Open"
		CmdClose.Enabled = True
		Slider1.Visible = True
	End Sub
	
	Private Sub MMControl1_StatusUpdate(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MMControl1.StatusUpdate
		On Error GoTo Erropen
		'设置文件长度为毫秒形式
		MMControl1.TimeFormat = 0
		Slider1.Max = MMControl1.Length / 1000
		If MMControl1.Position <> MMControl1.Length Then
			Slider1.Value = MMControl1.Position / 1000
		Else
			MMControl1.Command = "Prev"
			Slider1.Value = 0
		End If
		'调用TimeFormateCha函数计算剩余时间和总时间
		StatusBar1.Panels(2)._ObjectDefault = TimeFormateCha(MMControl1.Length - MMControl1.Position)
		StatusBar1.Panels(4)._ObjectDefault = TimeFormateCha((MMControl1.Length))
		Label1.Text = "00:00"
		Label2.Text = TimeFormateCha(MMControl1.Length / 2)
		Label3.Text = TimeFormateCha((MMControl1.Length))
		'由Mode返回不同值并在状态栏经出相应的提示
		Select Case MMControl1.Mode
			Case 524
				StatusBar1.Panels(5)._ObjectDefault = "未打开设备……"
			Case 525
				StatusBar1.Panels(5)._ObjectDefault = "停止状态……"
			Case 526
				StatusBar1.Panels(5)._ObjectDefault = "正在播放……" & CommonDialog1.FileTitle
			Case 527
				StatusBar1.Panels(5)._ObjectDefault = "正在录音……"
			Case 528
				StatusBar1.Panels(5)._ObjectDefault = "正在搜索……"
			Case 529
				StatusBar1.Panels(5)._ObjectDefault = "暂停播放……"
			Case 530
				StatusBar1.Panels(5)._ObjectDefault = "设备就绪……"
		End Select
Erropen: 
		'放弃打开文件
	End Sub
	
	Private Function TimeFormateCha(ByRef sm As Integer) As String
		Dim m As Object
		Dim s As Object
		'TimeFormateCha函数将毫秒转化为分秒格式
		s = (sm / 1000 / 60) Mod 60
		m = (sm / 1000) Mod 60
		TimeFormateCha = VB6.Format(s, "00") & ":" & VB6.Format(m, "00")
	End Function
	
	Private Sub MMControl1_Done(ByVal eventSender As System.Object, ByVal eventArgs As AxMCI.DmciEvents_DoneEvent) Handles MMControl1.Done
		MMControl1.UpdateInterval = 100 ' 间隔100毫秒
	End Sub
	
	Private Sub MnuExit_Click()
		MMControl1.Command = "Close"
		End
	End Sub
	
	Private Sub Check1_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Check1.CheckStateChanged
		If Check1.CheckState = 1 Then
			MMControl1.Command = "Play" '继续播放
		End If
	End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -