?
Solved

VB6 - Disable right click context menu

Posted on 2004-11-07
7
Medium Priority
?
1,098 Views
Last Modified: 2008-02-01
I have a quick question, how do I disable the right click context menu?

I already have a custom made menu for some of my textboxes already, but I want the others to be disabled.  When I say disabled, I don't mean the custom menu, I mean the main Windows menu (Cut, Copy, Paste, Select All).  I just want a plain text box with no other functionality.

Thanks.
0
Comment
Question by:greyknight17
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 100 total points
ID: 12517407
Take a look at this example from Microsoft:
http://support.microsoft.com/kb/q191670/

~IM
0
 
LVL 17

Assisted Solution

by:zzzzzooc
zzzzzooc earned 100 total points
ID: 12518227
If you want to subclass the textboxes, here's an example.


Form1:
--------------------
Option Explicit
Private Sub Form_Load()
    Call WindowHook(True, Text1.hWnd)
    Call WindowHook(True, Text2.hWnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Call WindowHook(False, Text1.hWnd)
    Call WindowHook(False, Text2.hWnd)
End Sub


Module1:
--------------------
Option Explicit

Private Declare Function CallWindowProc Lib "user32" 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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long

Private Const GWL_WNDPROC As Long = -4

Private Const WM_CONTEXTMENU As Long = &H7B

Private Const PropName As String = "lngPrevProc"
Public Function WindowHook(ByVal blnTrue As Boolean, ByVal lngHandle As Long) As Boolean
    Dim lngPrevProc As Long
    If blnTrue = True Then
        lngPrevProc = SetWindowLong(lngHandle, GWL_WNDPROC, AddressOf WindowProc)
        If lngPrevProc <> 0 Then
            Call SetProp(lngHandle, PropName, lngPrevProc)
            WindowHook = True
        End If
    Else
        lngPrevProc = CLng(GetProp(lngHandle, PropName))
        If lngPrevProc <> 0 Then
            Call SetWindowLong(lngHandle, GWL_WNDPROC, lngPrevProc)
            Call RemoveProp(lngHandle, PropName)
            WindowHook = True
        End If
    End If
End Function
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If uMsg = WM_CONTEXTMENU Then
        'just textbox focus (like context-menu does)
        Call SetFocus(hWnd)
    Else
        WindowProc = CallWindowProc(CLng(GetProp(hWnd, PropName)), hWnd, uMsg, wParam, lParam)
    End If
End Function

0
 
LVL 15

Author Comment

by:greyknight17
ID: 12523403
I think that's the link I was using before to create the custom context menu, but how do I disable the context menu completely?  Or am I missing/misreading something?

Does it prevent the user from copying and pasting text inside the box also?  I want to make sure that both are disabled so the user can't copy or paste using the context menu or the shortcut keys (ctrl+c, ctrl+x, ctrl+v, etc.).

zzzz...I'm lost in that code LOL.  I'm still a beginner with the Windows APIs, so I need to look into it further to understand it.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12691404
??
>>so I need to look into it further to understand it
They never "looked" into it to understand it, which isn't my fault. The proposed solution IS the answer which I was nice enough to provide for ONLY 50 points. If you (the moderator) do not think I provided an answer, atleast provide NO refund.
0
 
LVL 15

Author Comment

by:greyknight17
ID: 12695876
Sorry about that zzz and idle.  Shouldn't have that little points in the first place.  My fault for not understanding it either.

I'll accept both answers.

Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question