|
-
Sep 22nd, 2000, 06:20 PM
#1
Thread Starter
Frenzied Member
is there a way to disable the right click on a text box?
NXSupport - Your one-stop source for computer help
-
Sep 22nd, 2000, 06:46 PM
#2
_______
<?>
[code]
'get rid of popup for text box on right click
'
'<<<<<<<<<< put this in a bas module >>>>>>>>>>>>>>>>>>
'
Option Explicit
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 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 WM_RBUTTONUP = &H205
Public lpPrevWndProc As Long
Public lngHWnd As Long
Public Sub Hook(hWnd As Long)
lngHWnd = hWnd
lpPrevWndProc = SetWindowLong(lngHWnd, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
Public Sub UnHook()
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, _
lpPrevWndProc)
End Sub
Public Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_RBUTTONUP
'Do nothing
'Or popup your own menu
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, _
uMsg, wParam, lParam)
End Select
End Function
' <<<<<<<<<<<<<<<< form code >>>>>>>>>>>>>>>>>>>>>
'Add the following code to the Form_Load event of the form where the text box is placed:
Call Hook(Text1.hWnd)
'Where Text1 is the name of the text box you want to Subclass.
'Add the following code to the Form_Unload event:
Call UnHook
[code]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 23rd, 2000, 11:55 AM
#3
Add the following to a Module.
Code:
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong 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
Const GWL_WNDPROC = (-4)
Const WM_RBUTTONDOWN = &H204
Private WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_RBUTTONDOWN Then Exit Function
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Add the following to a Form with a TextBox.
Code:
Private Sub Form_Load()
SubClassWnd Text1.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd Text1.hwnd
End Sub
-
Sep 23rd, 2000, 03:07 PM
#4
Thread Starter
Frenzied Member
Thanks guys, Megatron, how did you get the Text to come up blue? or is it just another color coding mistake at the vbworld forunms?
NXSupport - Your one-stop source for computer help
-
Sep 24th, 2000, 05:03 AM
#5
Hyperactive Member
HeSaidJoe,
Your code is good. But can you teach me if I have multiple text box (I don't know the exact number, they are in an array), how should I modify the source.
-
Sep 26th, 2000, 06:05 AM
#6
New Member
Easy Solution Disable right click in Text Box
Hi,
Try easy one.
Steps to Create Sample Project
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Add a TextBox control to Form1.
Choose Menu Editor from the Tools menu and create a menu named mnuPopUp on Form1. Deselect the Visible CheckBox and add items such as the following:
File
New
Open
Add the following code to the code window of Form1:
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hwndLock As Long) As Long
Private Sub mnuOne_Click()
Text1.Text = "Menu One was clicked"
End Sub
Private Sub mnuTwo_Click()
Text1.Text = "Menu two was clicked"
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If Button = vbRightButton Then
' Avoid the 'disabled' gray text by locking updates
LockWindowUpdate Text1.hWnd
' A disabled TextBox will not display a context menu
Text1.Enabled = False
' Give the previous line time to complete
DoEvents
' Display our own context menu
PopupMenu mnuPopup
' Enable the control again
Text1.Enabled = True
' Unlock updates
LockWindowUpdate 0&
End If
End Sub
Save and run the project.
Alternate-mouse click on Text1. Only the custom menu is displayed. The standard editing menu is not shown.
-
Sep 26th, 2000, 06:57 AM
#7
transcendental analytic
Looks like the final code tag in HesaidJoes post triggered the blue text in Megatrons post
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|