469,282 Members | 1,846 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Replace comdlg32 and/or mscomctl

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

Jul 17 '05 #1
7 3965
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


Jul 17 '05 #2
I must be missing something here. How does that code prevent a user's
right-clicking on a folder in the OpenFile dialog and then selecting
Explore?

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.

<snip>
Jul 17 '05 #3

"Matthew Hanna" <mh************@appsci.com> wrote in message
news:sq6Ab.84904$yJ.40467@okepread02...
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

On my machine (XP), all the Explore option does on the context menu is
open a new window on the folder. I can do this anyway using Windows
Explorer, My Computer, etc. I could do it ahead of time if you manage to
disable it in your dialog.

What difference could it make whether I happen to have a folder view
open while selecting a file in your app?
Jul 17 '05 #4
We are using Citrix to allow others to access our main application. It
worked great until we found out that people could access our entire
network. With some additional programming we filled all the holes so
there was no access to the network except for what we offer in the main
application. Then, someone pointed out that they could still get to the
network by getting a file dialog box (Open or Save) and then right
clicking to get explorer. From there the network was wide open. I want
to just watch for explorer to appear and then shut it down but that
isn't an option in my bosses opinion.

Any ideas?

Thanks!
Matthew Hanna

Steve Gerrard wrote:
"Matthew Hanna" <mh************@appsci.com> wrote in message
news:sq6Ab.84904$yJ.40467@okepread02...
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


On my machine (XP), all the Explore option does on the context menu is
open a new window on the folder. I can do this anyway using Windows
Explorer, My Computer, etc. I could do it ahead of time if you manage to
disable it in your dialog.

What difference could it make whether I happen to have a folder view
open while selecting a file in your app?


Jul 17 '05 #5

"Matthew Hanna" <mh************@appsci.com> wrote in message
news:ZZmBb.93159$yJ.48120@okepread02...
We are using Citrix to allow others to access our main application. It worked great until we found out that people could access our entire
network. With some additional programming we filled all the holes so
there was no access to the network except for what we offer in the main application. Then, someone pointed out that they could still get to the network by getting a file dialog box (Open or Save) and then right
clicking to get explorer. From there the network was wide open. I want to just watch for explorer to appear and then shut it down but that
isn't an option in my bosses opinion.

Any ideas?

Thanks!
Matthew Hanna


Oh yeah, Citrix, I forgot about that possibility. They were talking
about that at work a few years ago...

Somehow I don't think you will ever be able to disable features of a
common dialog and be confident that you have permanently filled in the
hole...

You could make your own OpenFile dialog, maybe using the Drive, Dir, and
File list boxes of VB. It is not as pretty, but it would allow as much
(or as little) navigation as you want, and prevent users from doing
anything but picking a location and file name.
Jul 17 '05 #6
On Tue, 09 Dec 2003 11:44:41 -0500, Matthew Hanna
<mh************@appsci.com> wrote:
We are using Citrix to allow others to access our main application. It
worked great until we found out that people could access our entire
network. With some additional programming we filled all the holes so
there was no access to the network except for what we offer in the main
application. Then, someone pointed out that they could still get to the
network by getting a file dialog box (Open or Save) and then right
clicking to get explorer. From there the network was wide open. I want
to just watch for explorer to appear and then shut it down but that
isn't an option in my bosses opinion.

Any ideas?


Yes, roll your own Open/Save Dialogs
Jul 17 '05 #7
On Sat, 06 Dec 2003 15:45:36 GMT, "Randy Birch"
<rg************@mvps.org> wrote:
I must be missing something here. How does that code prevent a user's
right-clicking on a folder in the OpenFile dialog and then selecting
Explore?


You are absolutely right, I did not read the post correctly

The solution looks profoundly nasty
- subclassing theCommonDialog
- or sneaking Mouse Events using SetWindowsHookEx

Painful ...
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Craig Keightley | last post: by
6 posts views Thread by JackpipE | last post: by
2 posts views Thread by Veggis | last post: by
3 posts views Thread by Kerem Gümrükcü | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.