?? media.vb
字號:
Imports System.ComponentModel
Imports System.io
Imports System.Runtime.InteropServices
Namespace Media
Friend Class NativeMethods
<DllImport("coredll.dll")> _
Friend Shared Sub MessageBeep(ByVal type As MB)
End Sub
<DllImport("coredll.dll", EntryPoint:="PlaySoundW")> _
Friend Shared Function PlaySound(ByVal lpszName As String, ByVal hModule As IntPtr, ByVal dwFlags As SND) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Friend Enum MB
ICONHAND = &H10
ICONQUESTION = &H20
ICONEXCLAMATION = &H30
ICONASTERISK = &H40
End Enum
<Flags()> _
Friend Enum SND
SYNC = 0
ASYNC = 1
NODEFAULT = 2
[LOOP] = 8
NOSTOP = &H10
NOWAIT = &H2000
FILENAME = &H20000
End Enum
End Class
Public NotInheritable Class SoundPlayer
Inherits Component
Private m_soundLocation As String
Public Event SoundLocationChanged As EventHandler
Public Sub New()
m_soundLocation = ""
End Sub
Public Sub New(ByVal soundLocation As String)
m_soundLocation = ""
m_soundLocation = soundLocation
End Sub
Private Sub OnSoundLocationChanged(ByVal e As EventArgs)
RaiseEvent SoundLocationChanged(Me, e)
End Sub
Public Sub Play()
NativeMethods.PlaySound(Me.soundLocation, IntPtr.Zero, (NativeMethods.SND.FILENAME Or NativeMethods.SND.ASYNC))
End Sub
Public Sub PlayLooping()
NativeMethods.PlaySound(Me.soundLocation, IntPtr.Zero, (NativeMethods.SND.FILENAME Or NativeMethods.SND.LOOP Or NativeMethods.SND.ASYNC))
End Sub
Public Sub PlaySync()
NativeMethods.PlaySound(Me.soundLocation, IntPtr.Zero, NativeMethods.SND.FILENAME)
End Sub
Public Sub [Stop]()
NativeMethods.PlaySound(Nothing, IntPtr.Zero, NativeMethods.SND.NODEFAULT)
End Sub
Public Property SoundLocation() As String
Get
Return m_soundLocation
End Get
Set(ByVal value As String)
If File.Exists(value) Then
m_soundLocation = value
End If
RaiseEvent SoundLocationChanged(Me, EventArgs.Empty)
End Set
End Property
End Class
Public NotInheritable Class SystemSound
Private soundType As NativeMethods.MB
Friend Sub New(ByVal soundType As NativeMethods.MB)
Me.soundType = soundType
End Sub
Public Sub Play()
NativeMethods.MessageBeep(Me.soundType)
End Sub
End Class
Public Class SystemSounds
Public Shared ReadOnly Property Asterisk() As SystemSound
Get
Return New SystemSound(NativeMethods.MB.ICONASTERISK)
End Get
End Property
Public Shared ReadOnly Property Beep() As SystemSound
Get
Return New SystemSound(DirectCast(0, NativeMethods.MB))
End Get
End Property
Public Shared ReadOnly Property Exclamation() As SystemSound
Get
Return New SystemSound(NativeMethods.MB.ICONEXCLAMATION)
End Get
End Property
Public Shared ReadOnly Property Hand() As SystemSound
Get
Return New SystemSound(NativeMethods.MB.ICONHAND)
End Get
End Property
Public Shared ReadOnly Property Question() As SystemSound
Get
Return New SystemSound(NativeMethods.MB.ICONQUESTION)
End Get
End Property
End Class
End Namespace
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -