VB and VBA Users Source Code: Displaying a custom right click popup menu in a textbox
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Displaying a custom right click popup menu in a textbox
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, October 09, 2001
Hits:
868
Category:
Windows API
Article:
The following code demonstrates how to display a custom right click popup menu in a VB textbox without using subclassing. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long 'Purpose : Shows a custom right click menu for a textbox 'Inputs : Button The button pressed by the user ' txtControl The textbox to display the new popup menu in. ' oPopMenu The popup menu to display 'Outputs : Returns True if a popup menu was displayed 'Author : Andrew Baker 'Date : 28/Sep/2001 'Notes : Prevents the default content menu from begining displayed. 'Example : Function TextBoxRightClickMenu(Button As Integer, txtControl As TextBox, oPopMenu As Object) As Boolean On Error GoTo ErrFailed If Button = vbRightButton Then 'Lock the window updating to prevent the control being displayed as disabled LockWindowUpdate txtControl.hWnd 'Disable the control txtControl.Enabled = False 'Show the popup PopupMenu oPopMenu 'Enable the control txtControl.Enabled = False 'Restore the window updating LockWindowUpdate 0& 'Return success TextBoxRightClickMenu = True End If Exit Function ErrFailed: Debug.Print "Error in TextBoxRightClickMenu: " & Err.Description TextBoxRightClickMenu = False End Function 'Demonstration routine, where MnuPop is a menu containing at least on visible sub menu. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) TextBoxRightClickMenu Button, Text1, MnuPop End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder