' Windows API for the Open Filebox
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
' structure needed by Windows API
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
' for more information on Open- or SaveAs dialogs look at
' [URL unfurl="true"]http://www.mvps.org/vbnet/index.html?code/comdlg/filedlgsoverview.htm[/URL]
Public Function OpenFileDialog() As String
' common dialog for browse for desired filename
'set variables for OPENFILENAME type
Dim OFName As OPENFILENAME
'Set the filter
OFName.lpstrFilter = "SW files (*.sld*)" + Chr$(0) + "*.sld*" + Chr$(0) + "SW part files (*.sldprt)" + Chr$(0) + "*.sldprt" + Chr$(0) + "SW assembly files (*.sldasm)" + Chr$(0) + "*.sldasm" + Chr$(0) + "SW drawing files (*.slddrw)" + Chr$(0) + "*.slddrw" + Chr$(0) + "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'default extension
OFName.lpstrDefExt = "" + Chr$(0)
'Set the initial directory
'OFName.lpstrInitialDir = ""
OFName.lpstrInitialDir = TargetPathOnly
'Set the dialog title
OFName.lpstrTitle = "Select file"
'Set the structure size
OFName.lStructSize = Len(OFName)
'Create a buffer
OFName.lpstrFile = Space$(254)
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'no extra flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
OpenFileDialog = Trim$(OFName.lpstrFile)
Else
OpenFileDialog = ""
End If
End Function