Results 1 to 12 of 12

Thread: Common Dialog and Right Click

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    1

    Common Dialog and Right Click

    I've got an application sitting on a Citrix box where I want to prevent the user from being able to right-click within a common dialog box and getting the menu of delete/copy/ etc etc. I've got privileges set so the can't delete from dangerous folders (like c:\windows), but I can't set stuff up so that they can't do a file copy from inside the dialog box.

    Basically (ugh) I want to TOTALLY inhibit the right-mouse within the box.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Common Dialog and Right Click

    Don't know (haven't tried) if we can customize the Common Dialog Control but You could build your own 'common dialog' form

  3. #3
    New Member
    Join Date
    Jun 2009
    Posts
    2

    Re: Common Dialog and Right Click

    Quote Originally Posted by jggtz View Post
    Don't know (haven't tried) if we can customize the Common Dialog Control but You could build your own 'common dialog' form
    Yeh... but I was hoping to avoid that. <sigh>.

  4. #4
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Common Dialog and Right Click

    Maybe subclass the mouse and disable right click ?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Common Dialog and Right Click

    One way, far more advanced is to use a combination of subclassing/hooking.

    Subclassing would allow you to check for wm_contextmenu messages (about to show popup menu). However, you need the hWnd of the dialog to subclass and since the dialog shows modally, you can't get the hWnd from VB code alone, because your code stops when the dialog is displayed and doesn't continue until after it closes. This is where hooking comes into play. You will need to set up a hook that is specifically looking for the creation of the dialog and once found, the subclass is created for its hWnd.

    All pretty advanced, don't know your comfort level with hooking and subclassing. You can find hooking examples by searching the forum for positioning the common dialog.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Common Dialog and Right Click

    Welcome to the forums.

    How about something simple like removing the common dialog from your application?

    I don't know what you use the control for, but you could probably perform the same actions using other, more controlable controls (like a listbox or something)

  7. #7
    Hyperactive Member Jimq's Avatar
    Join Date
    Apr 2009
    Posts
    260

    Re: Common Dialog and Right Click

    Dnt use vb in that case, u can use registry for these things ....it has all things u require

  8. #8
    Hyperactive Member Jimq's Avatar
    Join Date
    Apr 2009
    Posts
    260

    Re: Common Dialog and Right Click

    try this out http://www.online-tech-tips.com/comp...-context-menu/

    Or it is better for u to disable Right Click


    (Pss Volpe Check ur visitor messages)

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Common Dialog and Right Click

    If you absolutely want to use the common dialog, you can with the code posted below.
    As mentioned by others, you can create your own, and you can also go the 100&#37; api way too. Short of creating your own dialog where you get mouse down events from VB, you are still looking at subclassing to prevent the context menu.
    Code:
    ' replaced.  See next post
    A sample call would look like:
    Code:
    Private Sub Command1_Click()
        SetHook
        CommonDialog1.ShowOpen
        UnHook
    End Sub
    Caution: Subclassing in design time is prone to crashes, but since this is subclassing a modal window and unsubclassing automatically, it should be 99.9% safe as long as you don't mess with the hooking/subclassing routines.

    Last but not least: tested with XP only.

    EDITED: Hmm, after playing with this a bit, the dialog can replace the listview we were subclassing. This can happen when clicking on the navigation icons: my desktop, my network places, my documents, etc. So, if this is something you will use, I can tweak the code to determine when this happens and adjust to the situation automatically. If you are comfortable with subclassing, feel free to modify the code yourself.
    Fixed. See next post
    Last edited by LaVolpe; Jun 19th, 2009 at 01:16 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Common Dialog and Right Click

    Updated code. The following applies to my previous post above. It will handle the common dialog changing listview midstream.
    Code:
    ' in a module only.... paste this
    
    Option Explicit
    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
    Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function CallNextHookEx Lib "user32.dll" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
    Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const WM_DESTROY As Long = &H2
    Private Const HCBT_CREATEWND As Long = 3
    Private Const WH_CBT As Long = 5
    Private Const GWL_WNDPROC As Long = -4
    Private Const WM_CONTEXTMENU As Long = &H7B
    Private Const WM_PARENTNOTIFY As Long = &H210
    Private Const WM_CREATE As Long = &H1
    
    Private m_HookProc As Long
    Private m_hWnd(0 To 1) As Long
    Private m_WndProc(0 To 2) As Long
    
    Public Sub SetHook()
        ' call to set a CBT hook, just before the common dialog is shown
        If m_HookProc = 0& Then
            Erase m_WndProc()
            Erase m_hWnd()
            m_HookProc = SetWindowsHookEx(WH_CBT, AddressOf HookProc, App.hInstance, App.ThreadID)
        End If
    End Sub
    Public Sub UnHook()
        ' call this immediately after the common dialog is shown
        If m_HookProc Then
            UnhookWindowsHookEx m_HookProc
            m_HookProc = 0&
        End If
    End Sub
    
    Private Function GetAddrOf(inAddr As Long) As Long
        GetAddrOf = inAddr
    End Function
    
    Private Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        ' CBT hook
        If nCode = HCBT_CREATEWND Then                  ' looking for creation of new windows
            Dim sClass As String, lLen As Long
            sClass = String$(20, vbNullChar)
            lLen = GetClassName(wParam, sClass, 20&)    ' looking for dialog window
            If StrComp("#32770", Left$(sClass, lLen), vbTextCompare) = 0& Then
                m_WndProc(2) = GetAddrOf(AddressOf WndProc) ' cache needed in WndProc function
                m_hWnd(0) = wParam                      ' cache for WndProc function & subclass it
                m_WndProc(0) = SetWindowLong(wParam, GWL_WNDPROC, m_WndProc(2))
                Call UnHook                             ' release the hook & subclass the listview
            End If
        End If
        HookProc = CallNextHookEx(m_HookProc, nCode, wParam, lParam)
    
    End Function
    
    Private Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        ' subclasser
        Dim sClass As String, lLen As Long, Index As Long
        Select Case hWnd
        Case m_hWnd(0) ' the dialog proper
            Select Case uMsg
            Case WM_DESTROY ' window is closing; unsubclass now
                SetWindowLong hWnd, GWL_WNDPROC, m_WndProc(Index)
                m_WndProc(Index) = 0&
            Case WM_PARENTNOTIFY ' see if SHELLDLL is being created
                If (wParam And &H7FFF) = WM_CREATE Then
                    sClass = String$(20, vbNullChar)
                    lLen = GetClassName(lParam, sClass, 20&)
                    If StrComp("SHELLDLL_DefView", Left$(sClass, lLen), vbTextCompare) = 0 Then
                        ' it is, that means it also has a new ListView, find that now. Unsubclass old one 1st if needed
                        If m_hWnd(1) Then SetWindowLong m_hWnd(1), GWL_WNDPROC, m_WndProc(1)
                        m_hWnd(1) = FindWindowEx(lParam, 0&, "SysListView32", vbNullString)
                        ' if it was found, subclass it to prevent context menus
                        If m_hWnd(1) Then m_WndProc(1) = SetWindowLong(m_hWnd(1), GWL_WNDPROC, m_WndProc(2))
                    End If
                End If
            End Select
        Case m_hWnd(1) ' the listview
            Index = 1&
            Select Case uMsg
            Case WM_CONTEXTMENU
                ' do nothing
                Debug.Print "got context menu"
                Exit Function
            Case WM_DESTROY ' window is closing; unsubclass now
                SetWindowLong hWnd, GWL_WNDPROC, m_WndProc(Index)
                m_WndProc(Index) = 0&
            End Select
        End Select
        WndProc = CallWindowProc(m_WndProc(Index), hWnd, uMsg, wParam, lParam)
    End Function
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    New Member
    Join Date
    Jun 2009
    Posts
    2

    Re: Common Dialog and Right Click

    Thanks all... I'll give it a shot tomorrow.

  12. #12
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,745

    Re: Common Dialog and Right Click

    Gravedig!

    It's also possible to prevent all other file operations in the CommonDialog?
    I've one client with a single user who is always messing up things when just selection a file with the CD.
    He's moving folders (without knowing it), by accidentally dragging things using the track-pad on a laptop.
    I would like to have a CommonDialog without all the Explorer functionality!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width