VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Remove The Textbox Menu

by SPY-3 (5 Submissions)
Category: Coding Standards
Compatability: VB Script
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

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

Rate Remove The Textbox Menu

Non-API

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

This way will work with probably all versions of VB

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.


This way will only work in VB 5.0 and VB 6.0 as far as i know

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

Download this snippet    Add to My Saved Code

Remove The Textbox Menu Comments

No comments have been posted about Remove The Textbox Menu. Why not be the first to post a comment about Remove The Textbox Menu.

Post your comment

Subject:
Message:
0/1000 characters