VB6 - Disable right click context menu

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.
LVL 15
greyknight17Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Take a look at this example from Microsoft:
http://support.microsoft.com/kb/q191670/

~IM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzzzzoocCommented:
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
greyknight17Author Commented:
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
zzzzzoocCommented:
??
>>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
greyknight17Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.