English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

我一個程式做好了但是感覺好單調我想加入音樂一打開就有音樂可聽這樣的程式碼 我該如何弄?

2006-02-27 19:50:29 · 2 個解答 · 發問者 小洪 6 in 電腦與網際網路 程式設計

2 個解答

'若不想使用元件也可用API來播放
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Private Sub Form_Activate()
Dim S As String, S1 As String

'S1=音樂檔(wav,mp3,mid...)
S1 = "C:Kiss Goodbye.mp3"
'將長檔名改成短檔名
S = String(LenB(S1), Chr(0))
GetShortPathName S1, S, Len(S)
S = Left(S, InStr(S, Chr(0)) - 1)
'關掉之前播放的媒體
mciSendString "close MyWav", vbNullString, 0, 0
'打開媒體
mciSendString "open " & S & " alias MyWav", vbNullString, 0, 0
'開始播放
mciSendString "play MyWav", vbNullString, 0, 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
'關掉媒體
mciSendString "close MyWav", vbNullString, 0, 0
End Sub

2006-02-27 16:31:10 · answer #1 · answered by W.J.S. 7 · 0 0

用這個元件 MMControl
屬性設定..
MMControl1.DeviceType="WaveAudio"
MMControl1.BackVisible=False
MMControl1.EjectVisible=False
MMControl1.NextVisible=False
MMControl1.PauseVisible=False
MMControl1.PlayVisible=True
MMControl1.PrevVisible=False
MMControl1.RecordVisible=False
MMControl1.StepVisible=False
MMControl1.StopVisible=True

MMControl1.filename = "檔名.WAVE" <<<<這裡要輸入你要播放的檔案
MMControl1.Command = "open"

2006-02-27 12:06:25 · answer #2 · answered by XXXPKMOTO 3 · 0 0

fedest.com, questions and answers