CommonDialog 控件 ShowOpen,怎么可以选多个?

f_d_0 2003-08-29 05:18:54
.Flags=cdlOFNAllowMultiselect 的界面太难看了
.Flags=cdlOFNHideReadOnly 的界面,又能多选最好.
WINAMP3的增加歌曲的打开就做到了,他是怎么做到的?
附:我的部件中的 CommonDialog 控件 后面带的是"(SP3)"是不是和这个版本有关?
...全文
106 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
f_d_0 2003-08-29
  • 打赏
  • 举报
回复
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
Flags 付值两个,两个一起使用,可行.谢谢
junki 2003-08-29
  • 打赏
  • 举报
回复
看来大家都回答差不多了啊!!!
我也……
不知道楼主试过没有,成功没有?
关注……
射天狼 2003-08-29
  • 打赏
  • 举报
回复
或者这样也可以~~

Private Sub cmdNext_Click()
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
CommonDialog1.ShowOpen

End Sub
射天狼 2003-08-29
  • 打赏
  • 举报
回复
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_LONGNAMES = &H200000
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_EXPLORER = &H80000
Private Const OFN_OVERWRITEPROMPT = &H2


Private Sub cmdNext_Click()
CommonDialog1.Flags = OFN_LONGNAMES + OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST + OFN_HIDEREADONLY + OFN_ALLOWMULTISELECT + OFN_EXPLORER
CommonDialog1.ShowOpen

End Sub
lilaclone 2003-08-29
  • 打赏
  • 举报
回复
'cm 是CommDialog对象,以下代码实现了多个文件的选取
Private Sub cmdOpen_Click()
Dim sFileNames() As String
Dim iCount As Integer

cd.Filter = "All Files|*.*"
cd.Flags = cdlOFNAllowMultiselect
cd.ShowOpen

If cd.FileName <> "" Then
sFileNames = Split(cd.FileName, Chr(32))
For iCount = LBound(sFileNames) To UBound(sFileNames)
MsgBox sFileNames(iCount), vbInformation
Next

End If
End Sub
lihonggen0 2003-08-29
  • 打赏
  • 举报
回复
CommonDialog控件的Flags属性有一个标志cdlOFNAllowMultiselect。利用这个标志可以实现多选。如:
CommonDialog1.Flags = CommonDialog1.Flags + cdlOFNAllowMultiselect
无论是在 Windows NT 4.0 还是在 Windows 95 中,如果 cdlOFNAllowMultiselect 标志被单独使用,都不能支持长文件名。这是因为多重文件名要包括空格分隔符,而长文件名也可能包括空格符。在 Windows NT 3.5 中,无法避免这种情况。如果使用 cdlOFNAllowMultiselect,就不能看到长文件名。如果在 Windows 95 中添加 cdlOFNExplorer 标志,就可以既能文件多选,又能看到长文件名。但是,这些文件名是用空字符Chr(0)分隔符,而不是空格分隔符隔开。因此,cdlOFNAllowMultiselect 和 cdlOFNExplorer 一起使用时,在 Windows 95 和 Windows NT 3.5中需要不同的文件名所得结果的语法分析。
当使用 cdlOFNAllowMultiselect 标志时,可能希望增加 MaxFileSize 属性的尺寸以便对所选文件名有足够的内存。MaxFileSize 属性要分配内存以便存储所选的一个或多个文件的实际名称。该属性的范围是 1-32K。缺省值是 256。
下面是一个例子:
Private Sub Command1_Click()
Dim I As Integer
Dim Y As Integer
Dim Z As Integer
Dim FileNames$()

CommonDialog1.FileName = ""
CommonDialog1.Filter = "All Files|*.*"
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
CommonDialog1.Action = 1

CommonDialog1.FileName = CommonDialog1.FileName & Chr(0)

Z = 1
For I = 1 To Len(CommonDialog1.FileName)
I = InStr(Z, CommonDialog1.FileName, Chr(0))
If I = 0 Then Exit For
ReDim Preserve FileNames(Y)
FileNames(Y) = Mid(CommonDialog1.FileName, Z, I - Z)
Z = I + 1
Y = Y + 1
Next

If Y = 1 Then
Text1.Text = FileNames(0)
Else
Text2.Text = ""
For I = 0 To Y - 1
If I = 0 Then
Text1.Text = FileNames(I)
Else
Text2.Text = Text2.Text & UCase(FileNames(I)) & _
Chr$(13) & Chr$(10)
End If
Next
End If
End Sub

7,789

社区成员

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

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