VB realizes the function of copy, pasting and so on of the right key menu of the screen text box _vb

Source: Internet
Author: User

This paper illustrates the realization of the function of the right key menu, copy and paste in VB screen text box. This function is to prevent the text box right button function, resulting in the right mouse click is invalid. is a very common kind of practical function.

The specific function module code is as follows:

'==========================================================
'| Module Name | Textboxdisableability ' | Description | Disable the function of the text box ' ==========================================================option Explicit Private Declare function SetWindowText Lib "user32" Alias "Setwindowtexta" (ByVal hwnd as Long, ByVal lpstring as String) as Long Private Declare F  Unction 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 Private Declare Function getwindowlong Lib "user32" Alias GETW Indowlonga "(ByVal hwnd as Long, ByVal nindex as Long) as Long Private Declare Function setwindowlong Lib" user32 "Alias" Setwindowlonga "(ByVal hwnd as Long, ByVal nindex as Long, ByVal Dwnewlong as Long) as long Private Const Gwl_wndproc = (- 4 Private Const Wm_cut = &h300 '-------------cut message Private const wm_copy as Long = &h301 '-------------Copy message privat E Const wm_paste as Long = &h302 '-------------paste message
Private Const Wm_clear = &h303 '-------------Delete message [Delete of right-click menu] Private const Em_undo = &hc7 '-------------undo message Privat E Const wm_contextmenu = &h7b '-------------Right-click menu Private Prevwndproc as Long Private Function WndProc (ByVal hwnd as Long, ByVal msg as Long, ByVal WParam as Long, ByVal LParam as Long) as long, msg case Wm_cut, wm_copy, wm_ PASTE, Wm_clear, Em_undo, Wm_contextmenu ' Handle custom events here, preferably for empty case Else ' callback system function processing WndProc = CallWindowProc (prevw Ndproc, hwnd, MSG, WParam, LParam) End Select end Function public Sub disableability (Targettextbox as TextBox) ' program start Si cho With this prevwndproc = GetWindowLong (Targettextbox.hwnd, Gwl_wndproc) SetWindowLong Targettextbox.hwnd, GWL_WNDPROC, Addres

 SOf WndProc End Sub

The function of this Code screen text box menu, copy, paste, etc., in a number of programs can see these features. To share with you VB enthusiasts, I hope to help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.