字符串解析... ...

野马 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
...全文
23 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
thinkeasy 2002-11-07
  • 打赏
  • 举报
回复

'=======================================
'打开文件
'=======================================
Function GetFileName(DefaultDir As String) As String
Dim ofn As OPENFILENAME
Dim rtn As String
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = frmMain.hwnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "所有文件"
ofn.lpstrFile = Space(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space(254)
ofn.nMaxFileTitle = 255
'ofn.lpstrInitialDir = App.path
ofn.lpstrTitle = "打开文件"
ofn.flags = &H200 + &H80000 ' 6148

rtn = GetOpenFileName(ofn)

If rtn >= 1 Then
GetFileName = ofn.lpstrFile
Else
GetFileName = ""
End If

End Function

欢迎去我的小站看看,可能有你想要的东西
http://lihuasoft.go163.net
niuzhenjun 2002-11-07
  • 打赏
  • 举报
回复
可能是你的字符集问题,用用lenb()试试

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧