|
-
Sep 20th, 2003, 12:57 PM
#1
Thread Starter
Conquistador
Miscellaneous Textbox Functions
Suppressing default popup menu on a text box
VB Code:
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hwndLock As Long) As Long
Private Sub TextBox_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 TextBox.hwnd
' A disabled TextBox will not display a context menu
TextBox.Enabled = False
' Give the previous line time to complete
DoEvents
' Display our own context menu
PopupMenu mnuPopup
' Enable the control again
TextBox.Enabled = True
' Unlock updates
LockWindowUpdate 0&
End If
End Sub
-
Sep 20th, 2003, 12:57 PM
#2
Thread Starter
Conquistador
Disabling context menu
In a module:
VB 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_CONTEXT = &H7B
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_CONTEXT Then Exit Function
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, _
wParam&, lParam&[b][/b])
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
In a form:
VB Code:
Private Sub Form_Load()
SubClassWnd TextBox.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd TextBox.hwnd
End Sub
This doesn't affect the right click message in any way.
Last edited by da_silvy; Sep 22nd, 2003 at 02:47 AM.
-
Sep 20th, 2003, 01:01 PM
#3
Thread Starter
Conquistador
Disabling copy, cut and paste in a textbox
In a module:
VB 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_COPY = &H301
Const WM_PASTE = &H302
Const WM_CUT = &H300
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_COPY Or wMsg = WM_PASTE Or wMsg = WM_CUT 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
In a form:
VB Code:
Private Sub Form_Load()
SubClassWnd TextBox.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd TextBox.hwnd
End Sub
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
|