Results 1 to 3 of 3

Thread: right mouse click

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    hello how doi get a right mouse click in a text box with my menu poping up not that copy past one can one of you help m e
    WHat would we do with out Microsoft.
    A lot more.

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    You've picked quite a hard one as it happens, You need to use a technique called Subclassing, make a new Standard module and add this code


    Code:
    Option Explicit
    
    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 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 Const GWL_WNDPROC = (-4)
    Private Const WM_RBUTTONUP = &H205
    
    Dim hWindowProc As Long
    
    
    
    Public Sub SubClass(hWnd As Long)
    'This Tells Windows to send the window messages to the procedure below (windowproc) rather than handle them itself
    hWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
    End Sub
    
    Public Sub unsubclass(hWnd As Long)
    'This tells it to start handling the messages itself again
    SetWindowLong hWnd, GWL_WNDPROC, hWindowProc
    End Sub
    
    Public Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    If wMsg = WM_RBUTTONUP Then 'If the Message is right mouse button up
    
        Form1.PopupMenu Form1.mnuPopup 'Popup our menu
    
    Else 'If it is another message
    
        WindowProc = CallWindowProc(hWindowProc, hWnd, wMsg, wParam, lParam)     'Call the Default window procedure and let VB Handle the message
    
    End If
    
    End Function
    then in your form_load event add
    Code:
    Subclass Text1.hWnd
    and in form_unload
    Code:
    Unsubclass Text1.hWnd
    A few notes on what we're doing (and this is quite hardcore if you're new to the API)

    Underneath your VB code Windows is doing quite a lot, the main think it does is handle all the window clicking and stuff, for this where you have events, it has one procedure that handles all the messages, this is called the window procedure.

    What we do is Tell windows to send all these window messages to our window procedure instead of to vb's, then if the meassage is right mousebutton up we put up the popup menu outherwise we pass it to the default window procedure.

    There will be lot's of articles on Subclassing around, have a look at them, there's all sorts of stuff you can do with it.


  3. #3
    Guest
    Or you can use a RichTextBox and set the AutoVerbMenu to False.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width