|
-
Jun 18th, 2009, 07:42 PM
#1
Thread Starter
New Member
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.
-
Jun 18th, 2009, 08:37 PM
#2
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
-
Jun 19th, 2009, 10:03 AM
#3
New Member
Re: Common Dialog and Right Click
 Originally Posted by jggtz
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>.
-
Jun 19th, 2009, 10:19 AM
#4
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.

-
Jun 19th, 2009, 10:41 AM
#5
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.
-
Jun 19th, 2009, 10:50 AM
#6
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)
-
Jun 19th, 2009, 11:10 AM
#7
Hyperactive Member
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
-
Jun 19th, 2009, 11:17 AM
#8
Hyperactive Member
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)
-
Jun 19th, 2009, 11:18 AM
#9
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% 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.
-
Jun 19th, 2009, 01:15 PM
#10
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
-
Jun 19th, 2009, 10:22 PM
#11
New Member
Re: Common Dialog and Right Click
Thanks all... I'll give it a shot tomorrow.
-
Nov 28th, 2017, 07:42 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|