Prevent Right Click

Discussion in 'AutoCAD' started by srinivasan, Mar 14, 2005.

  1. srinivasan

    srinivasan Guest

    Hello all,

    How to prevent the right click in the drawing screen.
    I tried with the right click settings but it gives me either
    the popup menu or repeats last command.
    I want the right click to produce no result in certain commands and to produce the same in some other commands.How to get this.

    Thanks in advance.
    Sri
     
    srinivasan, Mar 14, 2005
    #1
  2. Just a guess, did not try that...
    what about changing the Menu Part containing the context Menus (POP5xx)?
     
    Geometer Zopp \(Kurt Pesendorfer\), Mar 14, 2005
    #2
  3. The following code can be used to disable right clicks in any windows belonging to the current AutoCAD session.
    Code:
    Option Explicit
    Private Const WH_MOUSE_LL As Long = 14
    Private Const HC_ACTION As Long = 0&
    Private Const WM_RBUTTONDOWN As Long = &H204
    Private Const WM_RBUTTONUP As Long = &H205
    
    Private Declare Function CallNextHookEx Lib "user32.dll" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
    Private Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, lpdwProcessId As Long) 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 UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
    
    Private lngMouseHookHandle As Long
    
    Public Sub DisableRightClick()
    lngMouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, AddressOf LowLevelMouseProc, GetModuleHandle(vbNullString), 0&)
    End Sub
    
    Public Sub EnableRightClick()
    Call UnhookWindowsHookEx(lngMouseHookHandle)
    End Sub
    
    Public Function LowLevelMouseProc(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim lpdwProcessId As Long
    If GetWindowThreadProcessId(GetActiveWindow, lpdwProcessId) = GetWindowThreadProcessId(ThisDrawing.Application.hwnd, lpdwProcessId) Then
    If ncode = HC_ACTION Then
    Select Case wParam
    Case WM_RBUTTONDOWN
    LowLevelMouseProc = 1
    Exit Function
    Case WM_RBUTTONUP
    LowLevelMouseProc = 1
    Exit Function
    End Select
    End If
    End If
    LowLevelMouseProc = CallNextHookEx(lngMouseHookHandle, ncode, wParam, lParam)
    End Function
    
     
    Nathan Taylor, Mar 14, 2005
    #3
  4. srinivasan

    srinivasan Guest

    Thanks zopp for your reply.

    removing from the menu will remove the right
    click completely.But what i need is to control the
    right click i.e allowing right click when needed.

    regards
    Sri
     
    srinivasan, Mar 15, 2005
    #4
  5. srinivasan

    srinivasan Guest

    Thanks taylor

    I am having a problem in executing the SetWindowsHookEx
    function.It gives me an compile error in the 'AddressOf' statement.I am working in vba.How to solve this.

    Regards
    Sri
     
    srinivasan, Mar 15, 2005
    #5
  6. srinivasan

    srinivasan Guest

    I am using VBA and SetWindowsHookEx
    function gives me an compile error in the 'AddressOf' statement.

    Regards
    Sri
     
    srinivasan, Mar 16, 2005
    #6
  7. Sorry about the delay. Do you have the LowLevelMouseProc function in a forms code. I think the 'AddressOf' statement requires the function it is calling to be in a standard module.

    Regards - Nathan
     
    Nathan Taylor, Mar 17, 2005
    #7
  8. srinivasan

    bcoward Guest

    The AddressOf operator came about with VBA v6. I think that is 2002 and later. Without this VBA object model you can't subclass within the IDE IIRC.

    Regards,

    Bob Coward
    CADS, Inc
     
    bcoward, Mar 18, 2005
    #8
  9. srinivasan

    srinivasan Guest

    I couldnt find any such LowLevelMouseProc functions.

    Regards
    Sri
     
    srinivasan, Mar 18, 2005
    #9
  10. srinivasan

    srinivasan Guest

    Sorry i do have it in the module.

    Regards
    Sri
     
    srinivasan, Mar 18, 2005
    #10
  11. As per Bob's post what version of AutoCAD are you using?
    Regards - Nathan
     
    Nathan Taylor, Mar 21, 2005
    #11
  12. srinivasan

    srinivasan Guest

    I am using 2000.

    Regards
    Sri
     
    srinivasan, Mar 22, 2005
    #12
  13. Sorry Sri, As per Bob's post you probably can not use my code.
    Regards - Nathan
     
    Nathan Taylor, Mar 22, 2005
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.