Message 1 of 5
***Open Multiple Files***
Not applicable
06-20-2003
10:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I used a call to the Win32 to display the Open file dialog, with it I can select and open one file using the same dialog used by acad. However, if I change the flags to allow multiple selection, the dialog shown is different. Does someone knows how to allow multiple selection maintaining the same dialog? Maintaining it makes the app. more cad like. Here is the code I used, I found it in the web.
Option Explicit
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(lpOpenFilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Sub GetWindow()
Dim rc As Long
Dim pOpenfilename As OPENFILENAME
Const MAX_BUFFER_LENGTH = 4096
Const OFN_ALLOWMULTISELECT = &H200
Dim hWnd As Variant
Dim App As Variant
Dim FileOpen As Variant
'You can set the flags property to OFN_ALLOWMULTISELECT to allow
'multiple selection
With pOpenfilename
.hwndOwner = hWnd
.hInstance = ThisDrawing.Application.LocaleId
.lpstrTitle = "Title goes here:"
.lpstrInitialDir = ThisDrawing.Application.Path
.lpstrFilter = "Drawing Files" & Chr$(0) & "*.dwg" & Chr$(0)
.nFilterIndex = 1
.lpstrFile = String(MAX_BUFFER_LENGTH, 0)
.nMaxFile = MAX_BUFFER_LENGTH - 1
.lpstrFileTitle = .lpstrFile
.nMaxFileTitle = MAX_BUFFER_LENGTH - 1
.lStructSize = Len(pOpenfilename)
End With
rc = GetOpenFileName(pOpenfilename)
If rc Then
Application.Documents.Open (Left$(pOpenfilename.lpstrFile, pOpenfilename.nMaxFile))
End If
End Sub
Option Explicit
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(lpOpenFilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Sub GetWindow()
Dim rc As Long
Dim pOpenfilename As OPENFILENAME
Const MAX_BUFFER_LENGTH = 4096
Const OFN_ALLOWMULTISELECT = &H200
Dim hWnd As Variant
Dim App As Variant
Dim FileOpen As Variant
'You can set the flags property to OFN_ALLOWMULTISELECT to allow
'multiple selection
With pOpenfilename
.hwndOwner = hWnd
.hInstance = ThisDrawing.Application.LocaleId
.lpstrTitle = "Title goes here:"
.lpstrInitialDir = ThisDrawing.Application.Path
.lpstrFilter = "Drawing Files" & Chr$(0) & "*.dwg" & Chr$(0)
.nFilterIndex = 1
.lpstrFile = String(MAX_BUFFER_LENGTH, 0)
.nMaxFile = MAX_BUFFER_LENGTH - 1
.lpstrFileTitle = .lpstrFile
.nMaxFileTitle = MAX_BUFFER_LENGTH - 1
.lStructSize = Len(pOpenfilename)
End With
rc = GetOpenFileName(pOpenfilename)
If rc Then
Application.Documents.Open (Left$(pOpenfilename.lpstrFile, pOpenfilename.nMaxFile))
End If
End Sub