Replace comdlg32 and/or mscomctl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Hanna

    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

  • J French

    #2
    Re: Replace comdlg32 and/or mscomctl

    On Fri, 05 Dec 2003 16:05:28 -0500, Matthew Hanna
    <mhanna__NOSPAM @appsci.com> wrote:
    [color=blue]
    >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
    >[/color]

    As mercilessly hacked from www.AllAPI.net :-

    VERSION 1.0 CLASS
    BEGIN
    MultiUse = -1 'True
    END
    Attribute VB_Name = "cOpenDlg"
    Attribute VB_GlobalNameSp ace = False
    Attribute VB_Creatable = True
    Attribute VB_PredeclaredI d = 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.FileNameToOp en
    '
    ' OD.FileName is now "A Test File"
    ' OD.Path is now "C:\TEST\DE V"

    ' --- Open File Constants - added 25/3/01 JF
    Private Const OFN_ALLOWMULTIS ELECT = &H200
    Private Const OFN_CREATEPROMP T = &H2000
    Private Const OFN_DONTADDTORE CENT = &H2000000
    Private Const OFN_ENABLEHOOK = &H20
    Private Const OFN_ENABLEINCLU DENOTIFY = &H400000
    Private Const OFN_ENABLESIZIN G = &H800000
    Private Const OFN_ENABLETEMPL ATE = &H40
    Private Const OFN_ENABLETEMPL ATEHANDLE = &H80
    Private Const OFN_EX_NOPLACES BAR = &H1
    Private Const OFN_EXPLORER = &H80000 ' new look commdlg - default
    Private Const OFN_EXTENSIONDI FFERENT = &H400
    Private Const OFN_FILEMUSTEXI ST = &H1000
    Private Const OFN_FORCESHOWHI DDEN = &H10000000
    Private Const OFN_HIDEREADONL Y = &H4
    Private Const OFN_LONGNAMES = &H200000 ' force long names for 3.x
    modules
    Private Const OFN_NOCHANGEDIR = &H8
    Private Const OFN_NODEREFEREN CELINKS = &H100000
    Private Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x
    modules
    Private Const OFN_NONETWORKBU TTON = &H20000
    Private Const OFN_NOREADONLYR ETURN = &H8000
    Private Const OFN_NOTESTFILEC REATE = &H10000
    Private Const OFN_NOVALIDATE = &H100
    Private Const OFN_OVERWRITEPR OMPT = &H2
    Private Const OFN_PATHMUSTEXI ST = &H800
    Private Const OFN_READONLY = &H1
    Private Const OFN_SHAREAWARE = &H4000
    Private Const OFN_SHAREFALLTH ROUGH = 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
    lpstrCustomFilt er As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileExcPat hBack 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.d ll" _
    Alias "GetOpenFileNam eA" _
    (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.lpstrFileExc PathBack = Space$(254)
    'Set the maximum number of chars
    OF.nMaxFileTitl e = 255
    'Set the initial directory
    OF.lpstrInitial Dir = 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_HIDEREADONL Y _
    Or OFN_FILEMUSTEXI ST _
    Or OFN_NOCHANGEDIR

    'Show the 'Open File'-dialog
    If GetOpenFileName (OF) Then
    LF_ShowOpen = StrExtStr(OF.lp strFile, Chr$(0), 1)
    m.FileName = StrExtStr(OF.lp strFileExcPathB ack, 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_Initializ e()
    m.Filter = "All Files (*.*)|*.*|"
    m.Title = "Open File:"
    m.Path = CurDir
    End Sub




    Comment

    • Randy Birch

      #3
      Re: Replace comdlg32 and/or mscomctl

      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

      Please respond only to the newsgroups so all can benefit.

      <snip>


      Comment

      • Steve Gerrard

        #4
        Re: Replace comdlg32 and/or mscomctl


        "Matthew Hanna" <mhanna__NOSPAM @appsci.com> wrote in message
        news:sq6Ab.8490 4$yJ.40467@okep read02...[color=blue]
        > 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[/color]
        a[color=blue]
        > folder. Any ideas?
        > Thanks!
        >
        > Matthew Hanna
        >[/color]
        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?


        Comment

        • Matthew Hanna

          #5
          Re: Replace comdlg32 and/or mscomctl

          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:[color=blue]
          > "Matthew Hanna" <mhanna__NOSPAM @appsci.com> wrote in message
          > news:sq6Ab.8490 4$yJ.40467@okep read02...
          >[color=green]
          >>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[/color]
          >
          > a
          >[color=green]
          >>folder. Any ideas?
          >>Thanks!
          >>
          >>Matthew Hanna
          >>[/color]
          >
          > 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?
          >
          >[/color]

          Comment

          • Steve Gerrard

            #6
            Re: Replace comdlg32 and/or mscomctl


            "Matthew Hanna" <mhanna__NOSPAM @appsci.com> wrote in message
            news:ZZmBb.9315 9$yJ.48120@okep read02...[color=blue]
            > We are using Citrix to allow others to access our main application.[/color]
            It[color=blue]
            > 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[/color]
            main[color=blue]
            > application. Then, someone pointed out that they could still get to[/color]
            the[color=blue]
            > 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[/color]
            want[color=blue]
            > 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
            >[/color]

            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.


            Comment

            • J French

              #7
              Re: Replace comdlg32 and/or mscomctl

              On Tue, 09 Dec 2003 11:44:41 -0500, Matthew Hanna
              <mhanna__NOSPAM @appsci.com> wrote:
              [color=blue]
              >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?[/color]

              Yes, roll your own Open/Save Dialogs


              Comment

              • J French

                #8
                Re: Replace comdlg32 and/or mscomctl

                On Sat, 06 Dec 2003 15:45:36 GMT, "Randy Birch"
                <rgb_removethis @mvps.org> wrote:
                [color=blue]
                >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?[/color]

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

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

                Painful ...

                Comment

                Working...