高手进,用mcisendstring播放音乐,长短路径转化问题???

来源:百度知道 编辑:UC知道 时间:2024/06/24 15:48:10
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVallpszShortPath 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

Function ShortName(LongPath As String) As String
Dim ShortPath As String
Dim pos As String
Dim Ret As Long
Const MAX_PATH = 260
If LongPath = "" Then Exit Function
ShortPath = Space$(MAX_PATH)
Ret& = GetShortPathName(LongPath, ShortPath, MAX_PATH)
If Ret& Then
pos = InStr(1, ShortPath, " ")
ShortName = Left$(ShortPath, pos - 2)
End If
End Function

Dim AA As String

Private Sub Form_Load()

If Right(App.Path, 1) <> "\"

Public Function getshortname(ByVal sLongFileName As String) As String '获取短路径
Dim lRetVal As Long, sShortPathName As String, iLen As Integer
sShortPathName = Space(255)
iLen = Len(sShortPathName)
lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
getshortname = Left(sShortPathName, lRetVal)
End Function

mciSendString "play " & ShortName(AA), vbNullString, 0, 0

不是标准的API最好不要用