***Open Multiple Files***

***Open Multiple Files***

Anonymous
Not applicable
473 Views
4 Replies
Message 1 of 5

***Open Multiple Files***

Anonymous
Not applicable
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
0 Likes
474 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
HJohn

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)
.flags = OFN_ALLOWMULTISELECT '<- set the flags property
End With


Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch
0 Likes
Message 3 of 5

Anonymous
Not applicable
I only wanted to know how to maintain the look of the dialog box, when the flags is set to open multitple files. whenever I set the flags the look of the box changes to a smaller box, different to the one that is displayed if the flags is not set.


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
0 Likes
Message 4 of 5

Anonymous
Not applicable
I only wanted to know how to maintain the look of the dialog box, when the flags is set to open multitple files. whenever I set the flags the look of the box changes to a smaller box, different to the one that is displayed if the flags is not set. If someone knows how to do this please give a hand.
0 Likes
Message 5 of 5

hawstom
Advocate
Advocate
If I understand the question right, you are seeing the old style dialogue box. What you need to do is set the file to use Explorer.

Like This in my code:
cmdlgOpenFile.Flags = OFN_ALLOWMULTISELECT Or _
OFN_EXPLORER
0 Likes