VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code allows you to change the default right click menu in a text box

by bader (7 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 8th January 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code allows you to change the default right click menu in a text box

API Declarations



Public Const GWL_WNDPROC = (-4)
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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 Const WM_CONTEXTMENU = &H7B

Public origWndProc As Long

Public Sub SetHook(hwnd, bSet As Boolean)
If bSet Then
origWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf AppWndProc)
ElseIf origWndProc Then
Dim lRet As Long
lRet = SetWindowLong(hwnd, GWL_WNDPROC, origWndProc)
End If
End Sub

Public Function AppWndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_CONTEXTMENU
Form1.PopupMenu Form1.mnuBP
AppWndProc = 0
Exit Function
End Select
AppWndProc = CallWindowProc(origWndProc, hwnd, Msg, wParam, lParam)
End Function


Rate This code allows you to change the default right click menu in a text box



Option Explicit

Private Sub Form_Load()
    Call SetHook(Text1.hwnd, True)
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Call SetHook(Text1.hwnd, False)
End Sub

Private Sub mnuPrint_Click()
    MsgBox "Print!"
End Sub


Download this snippet    Add to My Saved Code

This code allows you to change the default right click menu in a text box Comments

No comments have been posted about This code allows you to change the default right click menu in a text box. Why not be the first to post a comment about This code allows you to change the default right click menu in a text box.

Post your comment

Subject:
Message:
0/1000 characters