Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


When you right-click a TextBox control, Windows sends it a WM_CONTEXTMENU message, to which VB reacts by displaying the default Edit popup menu, that contains editing commands such as Cut, Copy, Paste, and Select All. Using a subclassing technique you can easily trap this message before it reaches the original window procedure, and suppress the default Edit menu or substitute it with a custom popup menu. Thanks to the MsgHook DLL this is a trivial task:

Click here to copy the following block
' REQUIRES THE MSGHOOK.DLL COMPONENT

' you can omit the following constant definition,
' because it is contained in the MsgHook type library
Const WM_CONTEXTMENU = &H7B

Dim WithEvents TextBoxHook As MsgHook

Private Sub Form_Load()
  ' subclass the Text1 control
  Set TextBoxHook = New MsgHook
  TextBoxHook.StartSubclass Text1.hWnd
End Sub

Private Sub TextBoxHook_BeforeMessage(uMsg As Long, wParam As Long, _
  lParam As Long, retValue As Long, Cancel As Boolean)
  If uMsg = WM_CONTEXTMENU Then
    ' Show a custom popup menu.
    PopupMenu mnuPopup
    ' Cancel the default processing
    ' (i.e. don't display the default context menu).
    Cancel = True
  End If
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.