Tools Links Login

Remove The Textbox Menu

This article will show you how you can remove that annoying textbox menu and replace it with your own or just have it gone.

Original Author: SPY-3

Code

Non-API

To do this simply add this code to the MouseDown part of the textbox

If Button = 2 Then

YourTextboxName.Enabled = False

YourTextboxName.Enabled = True

YourTextboxName.SetFocus

PopupMenu YourMenuName

End If

Replace all the Green text with what your control names are.

Hope this helped.


API

Option Explicit

'Parts of this were orginally made by

' Written by Matt Hart

'Altered by SPY-3

'This was originally written for a webbrowser see

'http://blackbeltvb.com/index.htm?free/webbmenu.htm




Public 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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Public 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 GW_HWNDNEXT = 2

Public Const GW_CHILD = 5


  
Public Const WM_MOUSEACTIVATE = &H21

Public Const WM_CONTEXTMENU = &H7B

Public Const WM_RBUTTONDOWN = &H204


Public origWndProc As Long


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_MOUSEACTIVATE

Dim C As Integer

Call CopyMemory(C, ByVal VarPtr(lParam) + 2, 2)

If C = WM_RBUTTONDOWN Then

YourForm.PopupMenu YourForm.YourMenu

SendKeys "{ESC}"

End If

Case WM_CONTEXTMENU

YourForm.PopupMenu YourForm.YourMenu

SendKeys "{ESC}"

End Select

AppWndProc = CallWindowProc(origWndProc, hwnd, Msg, wParam, lParam)

End Function
Then under Form_Load() put this
origWndProc = SetWindowLong(YourTextBox.hwnd, GWL_WNDPROC, AddressOf AppWndProc)



http://Tiamat-Studios.vze.com

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 90 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.