On Fri, 05 Dec 2003 16:05:28 -0500, Matthew Hanna
<mh************@appsci.com> wrote:
Is there any code out there to replace the Open File dialog in the
common controls? Or, I would like to just make sure that the Explorer
item in the context menu doesn't appear when the user right clicks on a
folder. Any ideas?
Thanks!
Matthew Hanna
As mercilessly hacked from
www.AllAPI.net :-
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "cOpenDlg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' cOpenDlg.cls - J French 18/11/01 - From KPD
' Dim OD As New cOpenDlg
' OD.Parent = Me (Optional)
' OD.Path = "C:\test"
' OD.Title = "Open File :"
' OD.FileName = "The File Name"
' OD.Filter = "Text Files (*.txt)|*.txt|"
'
' FullFile = OD.FileNameToOpen
'
' OD.FileName is now "A Test File"
' OD.Path is now "C:\TEST\DEV"
' --- Open File Constants - added 25/3/01 JF
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_CREATEPROMPT = &H2000
Private Const OFN_DONTADDTORECENT = &H2000000
Private Const OFN_ENABLEHOOK = &H20
Private Const OFN_ENABLEINCLUDENOTIFY = &H400000
Private Const OFN_ENABLESIZING = &H800000
Private Const OFN_ENABLETEMPLATE = &H40
Private Const OFN_ENABLETEMPLATEHANDLE = &H80
Private Const OFN_EX_NOPLACESBAR = &H1
Private Const OFN_EXPLORER = &H80000 ' new look commdlg - default
Private Const OFN_EXTENSIONDIFFERENT = &H400
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_FORCESHOWHIDDEN = &H10000000
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_LONGNAMES = &H200000 ' force long names for 3.x
modules
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_NODEREFERENCELINKS = &H100000
Private Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x
modules
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOREADONLYRETURN = &H8000
Private Const OFN_NOTESTFILECREATE = &H10000
Private Const OFN_NOVALIDATE = &H100
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_READONLY = &H1
Private Const OFN_SHAREAWARE = &H4000
Private Const OFN_SHAREFALLTHROUGH = 2
Private Const OFN_SHARENOWARN = 1
Private Const OFN_SHAREWARN = 0
Private Const OFN_SHOWHELP = &H10
Private Const OFN_USEMONIKERS = &H1000000
Private Type TOPENFILENAME
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
lpstrFileExcPathBack 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
Private Declare Function GetOpenFileName _
Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" _
(pOpenfilename As TOPENFILENAME) As Long
Private Type TM
OwnerHWnd As Long
Filter As String
FileName As String
Path As String
Title As String
End Type
Dim OF As TOPENFILENAME, m As TM
Public Function FileNameToOpen$()
FileNameToOpen = LF_ShowOpen
End Function
' ---
Public Property Let Filter(Value$)
m.Filter = Value
End Property
Public Property Get Filter$()
Filter = m.Filter
End Property
' ---
Public Property Let FileName(Value$)
m.FileName = Value
End Property
Public Property Get FileName$()
FileName = m.FileName
End Property
' ---
Public Property Let Path(Value$)
m.Path = Value
End Property
Public Property Get Path$()
Path = m.Path
End Property
' ---
Public Property Let Title(Value$)
m.Title = Value
End Property
Public Property Get Title$()
Title = m.Title
End Property
' ---
Public Property Let Parent(Value As Form)
m.OwnerHWnd = 0
If Not Value Is Nothing Then
m.OwnerHWnd = Value.hwnd
End If
End Property
' --- Main Routine
Private Function LF_ShowOpen() As String
Dim S$
Dim ActiveForms As Collection
Dim F As Form
' --- Disable all Enabled and Visible Forms
If m.OwnerHWnd = 0 Then
Set ActiveForms = New Collection
For Each F In Forms
If F.Visible Then
If F.Enabled Then
ActiveForms.Add F
F.Enabled = False
End If
End If
Next
End If
'Set the structure size
OF.lStructSize = Len(OF)
'Set the owner window
OF.hwndOwner = m.OwnerHWnd
'Set the application's instance
OF.hInstance = App.hInstance
'Set the filter
S$ = m.Filter
Call StrReplaceStr(S$, "|", Chr$(0))
OF.lpstrFilter = S$ + Chr$(0)
'Create a buffer - File Name In - Full File & Path Out
OF.lpstrFile = m.FileName + Space$(255)
'Set the maximum number of chars
OF.nMaxFile = 255
'Create a buffer
OF.lpstrFileExcPathBack = Space$(254)
'Set the maximum number of chars
OF.nMaxFileTitle = 255
'Set the initial directory
OF.lpstrInitialDir = m.Path
'Set the dialog title
OF.lpstrTitle = m.Title
'extra flags - Hide Read Only Option
' - File MUST exist
' - Do not change App's CurDir on exit
OF.flags = OFN_HIDEREADONLY _
Or OFN_FILEMUSTEXIST _
Or OFN_NOCHANGEDIR
'Show the 'Open File'-dialog
If GetOpenFileName(OF) Then
LF_ShowOpen = StrExtStr(OF.lpstrFile, Chr$(0), 1)
m.FileName = StrExtStr(OF.lpstrFileExcPathBack, Chr$(0), 1)
m.Path = ExtractFilePath(LF_ShowOpen)
Else
LF_ShowOpen = ""
End If
' --- Re-Enable Forms
If m.OwnerHWnd = 0 Then
For Each F In ActiveForms
F.Enabled = True
Next
Set ActiveForms = Nothing
End If
End Function
Private Sub Class_Initialize()
m.Filter = "All Files (*.*)|*.*|"
m.Title = "Open File:"
m.Path = CurDir
End Sub