字符串解析... ...
野马 2002-11-07 04:09:39 1.用API谈出打开对话框
2.解析返回的字符串,用一个变量存路径,用菜单存文件名,可是当打开中文文件名时
出错
比如
打开C:\文档\qq.swf
路径竟然是c:\文档 \q
希望有经验的朋友帮我解决这个问题
注:打开全英文的路径不出错
Public Function Openfiles() '打开文件
Dim sFilters As String
Dim pos As Long
Dim buff As String
Dim sLongname As String
Dim sShortname As String
Dim strtemp As String, q As String
Dim i, k
sFilters = "Flash动画文件(*.swf)" & vbNullChar & "*.swf"
If Topfrm = 1 Then
SetWindowPos Player.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
k = 1
End If
With OFN
.nStructSize = Len(OFN)
.hWndOwner = Me.hwnd
.sFilter = sFilters
.nFilterIndex = 2
.sFile = Space$(1024) & vbNullChar & vbNullChar
.nMaxFile = Len(.sFile)
.sDefFileExt = "bas" & vbNullChar & vbNullChar
.sFileTitle = vbNullChar & Space$(512) & vbNullChar & vbNullChar
.nMaxTitle = Len(OFN.sFileTitle)
.sDialogTitle = "打开Flash动画文件 测试版每次只能打开20个文件,请关注本软件的正式版。"
.flags = OFS_FILE_OPEN_FLAGS Or OFN_ALLOWMULTISELECT Or OFN_EXPLORER
.fnHook = FARPROC(AddressOf OFNHookProc)
End With
If GetOpenFileName(OFN) Then
buff = Trim$(Left$(OFN.sFile, Len(Trim(OFN.sFile)) - 2))
For i = 2 To 20 '把菜单置空
file(i).Enabled = False
file(i).Visible = False
Next
i = 0
Do While Len(buff) > 3 And i <= 20 '********************把文件名记录菜单
If i = 0 Then
StripDelimitedItem buff, vbNullChar
Else
file(i).Enabled = True
file(i).Visible = True
file(i).Checked = False
file(i).Caption = StripDelimitedItem(buff, vbNullChar)
End If
i = i + 1
Loop
'i = InStr(OFN.sFile, " ")
'strtemp = OFN.sFile
'q = Len(Trim(strtemp))
'strtemp = Left$(strtemp, OFN.nFileOffset - 2)
filePath = Left(OFN.sFile, OFN.nFileOffset - 1) & "\" '记录文件路径
'If Right(filePath, 5) <> "桌面\" Then filePath = RTrim(Left$(OFN.sFile, OFN.nFileOffset - 1)) & "\" '记录文件路径
'******************************************************************************
titlFile = i - 1 '文件总数
currFile = 1 '从第一个开始播放
If i < 2 And Len(Trim$(Left$(OFN.sFile, Len(OFN.sFile) - 2))) > 3 Then '如只打开一个文件,把文件名记录菜单
file(1).Enabled = True
file(1).Visible = True
file(1).Caption = Mid$(OFN.sFile, OFN.nFileOffset + 1, Len(OFN.sFile) - OFN.nFileOffset - 1)
filePath = Left$(OFN.sFile, OFN.nFileOffset) '记录文件路径
End If
If k = 1 Then
SetWindowPos Player.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
End If
startPlay (currFile) '开始播放
Else
'MsgBox "按了取消键", vbInformation + vbOKOnly, "取消"
End If
End Function