Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Right Click Menu In TextBoxes, Disable or popup your own men
View previous topic :: View next topic  
Author Message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Oct 10th, 2003 07:41 AM    Post subject: Right Click Menu In TextBoxes, Disable or popup your own men Reply with quote

Code:
'Module code
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

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_RBUTTONUP = &H205
Public Const WM_CONTEXTMENU As Long = &H7B
Public lpPrevWndProc As Long
Private lngHWnd As Long

Public Sub Hook(hWnd As Long)
   lngHWnd = hWnd
   lpPrevWndProc = SetWindowLong(lngHWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub UnHook()
   Dim lngReturnValue As Long
   lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub

Function WindowProc(ByVal hw As Long, _
                   ByVal uMsg As Long, _
                   ByVal wParam As Long, _
                   ByVal lParam As Long) As Long

   Select Case uMsg
       Case WM_CONTEXTMENU
           'Do nothing
           'Or popup you own menu
       Case Else
           WindowProc = CallWindowProc(lpPrevWndProc, hw, _
           uMsg, wParam, lParam)
   End Select
End Function


Usage :

Code:
Private Sub Form_Load()
   Call Hook(Text1.hWnd)
End Sub

Private Sub Form_Unload(Cancel As Integer)
   UnHook
End Sub

_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic