none
API mciSendStringA 問題 RRS feed

  • 問題

  •   Private Declare Function mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    
      Private Function PlayMidiFile(ByVal MusicFile As String) As Boolean
        If System.IO.File.Exists(MusicFile) Then
          mciSendStringA("stop music", "", 0, 0)
          mciSendStringA("close music", "", 0, 0)
          mciSendStringA("open " & MusicFile & " alias music", "", 0, 0)
          PlayMidiFile = mciSendStringA("play music", "", 0, 0) = 0
          Return True
        Else
          Return False
        End If
      End Function
    
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PlayMidiFile(TextBox1.Text)
      End Sub
    
    ' 駐 : TextBox1.Text = "C:\Documents and Settings\lin\My Documents\My Music\Girl In Your Dream.mp3"
    
    

    我沒用中斷點的話 它就播不出歌來

    我用中斷點 PlayMidiFile 是 Return False

    歌名 : Girl In Your Dream.mp3

    題外問題 如何輸入檔案捷徑 就傳回檔名 目前程式碼 :

      Public Function GetNameOnly(ByVal strFile As String) As String
        Dim OnlyName As String
        Try
          OnlyName = Mid$(strFile, InStrRev(strFile, "\"), Len(strFile) - InStrRev(strFile, "\") + 1)
        Catch ex As Exception
          Return "UnKwno"
        End Try
        Return OnlyName
      End Function
    
    2011年2月10日 下午 03:41

解答

所有回覆