Hi All,
Here i want to disable right click on textbox.
Please help me to do this.

Best Regards
Neji

Recommended Answers

All 4 Replies

Use API calls.

Use API calls.

What kind of API..
Please help.

Thank you

1 Module, 1 textbox

In Module :

Option Explicit

Public OldWindowProc As Long

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
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GWL_WNDPROC = (-4)
Public Const WM_USER = &H400
' Pass along all messages except the one that
' makes the context menu appear.
Public Function NoPopupWindowProc(ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CONTEXTMENU = &H7B

    If msg <> WM_CONTEXTMENU Then _
        NoPopupWindowProc = CallWindowProc( _
            OldWindowProc, hWnd, msg, wParam, _
            lParam)
End Function

In Form :

Option Explicit
Private Sub Form_Load()
    ' Set the control's new WindowProc.
    OldWindowProc = SetWindowLong( _
        txtMenuDisabled.hWnd, GWL_WNDPROC, _
        AddressOf NoPopupWindowProc)
End Sub
' Restore the original WindowProc.
Private Sub Form_Unload(Cancel As Integer)
    SetWindowLong _
        txtMenuDisabled.hWnd, GWL_WNDPROC, _
        OldWindowProc
End Sub
commented: Thank you. It worked very nice. +2

Thank you very much jx_man. it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.