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
Printable View
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
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
then in your form_load event addCode: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
and in form_unloadCode:Subclass Text1.hWnd
A few notes on what we're doing (and this is quite hardcore if you're new to the API)Code:Unsubclass Text1.hWnd
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.
Or you can use a RichTextBox and set the AutoVerbMenu to False.