Results 1 to 31 of 31

Thread: How to disable right click in textbox

  1. #1

    Thread Starter
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    MSDN

    HOWTO: Suppress Default Pop-up Menu When Using Custom Menu

    Q191670


    --------------------------------------------------------------------------------
    The information in this article applies to:

    Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0

    --------------------------------------------------------------------------------


    SUMMARY
    Some Visual Basic controls, such as the TextBox, have a default pop-up menu that will automatically be display when you alternate-mouse click on the control. This article demonstrates one way to disable this default pop-up menu in order that either no menu or only a custom pop-up menu is displayed.



    MORE INFORMATION
    When you alternate-mouse click on the TextBox control, its default pop-up menu will be displayed. Visual Basic does not have a property or any other built-in mechanism that directly disables this feature. However, setting the control's Enabled property to False will prevent the menu from being displayed although this allows the user to see that the control is disabled.

    One workaround is to use the Windows LockWindowUpdate API in conjunction with the Enabled property. The LockWindowUpdate function disables or re- enables drawing in a specified window. After the operation is complete, the control is re-enabled and the LockWindowUpdate API is called a second time to resume drawing of the control.


    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.


    An alternative approach to supressing the default pop-up menu is to subclass the control. Through subclassing, you can monitor for the appropriate mouse messages and handle them accordingly. See the REFERENCES section below for more information on this topic.
    -= a peet post =-

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Another way:

    VB Code:
    1. 'In your form's code
    2.  
    3. Private Sub Form_Load()
    4. Call Hook(Text1.hWnd)
    5. End Sub
    6. Private Sub Form_Unload(Cancel As Integer)
    7. UnHook
    8. End Sub
    9.  
    10. 'Module code
    11. Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    12. (ByVal lpPrevWndFunc As Long, _
    13. ByVal hWnd As Long, _
    14. ByVal Msg As Long, _
    15. ByVal wParam As Long, _
    16. ByVal lParam As Long) As Long
    17.  
    18. Declare Function SetWindowLong Lib "user32" _
    19. Alias "SetWindowLongA" _
    20. (ByVal hWnd As Long, _
    21. ByVal nIndex As Long, _
    22. ByVal dwNewLong As Long) As Long
    23.  
    24. Public Const GWL_WNDPROC = -4
    25. Public Const WM_RBUTTONUP = &H205
    26. Public lpPrevWndProc As Long
    27. Private lngHWnd As Long
    28.  
    29. Public Sub Hook(hWnd As Long)
    30. lngHWnd = hWnd
    31. lpPrevWndProc = SetWindowLong(lngHWnd, GWL_WNDPROC, _
    32. AddressOf WindowProc)
    33. End Sub
    34.  
    35. Public Sub UnHook()
    36. Dim lngReturnValue As Long
    37. lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, lpPrevWndProc)
    38. End Sub
    39.  
    40. Function WindowProc(ByVal hw As Long, _
    41. ByVal uMsg As Long, _
    42. ByVal wParam As Long, _
    43. ByVal lParam As Long) As Long
    44.  
    45. Select Case uMsg
    46. Case WM_RBUTTONUP
    47. 'Do nothing
    48. 'Or popup you own menu
    49. Case Else
    50. WindowProc = CallWindowProc(lpPrevWndProc, hw, _
    51. uMsg, wParam, lParam)
    52. End Select
    53. End Function


  3. #3
    DaoK
    Guest
    Just put something like : IF button =2 then button =1 in mouvedown event...

  4. #4
    DaoK
    Guest
    This one work :
    VB Code:
    1. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. If Button = 2 Then MsgBox "This button is disable"
    3. End Sub

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    That only works if you popup a message box though...

  6. #6
    DaoK
    Guest
    well the msgbox will advertise to no use it and it will block it anyway so I think is a eas solution, maybe not the best but it work.

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Yes, but it is messy.

  8. #8
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Does this messy way work:

    VB Code:
    1. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. If Button = 2 Then
    3. Call Text1_MouseDown(1, Shift, X, Y)
    4. End if
    5. End Sub
    Baaaaaaaaah

  9. #9
    Matthew Gates
    Guest
    The best and safest way is to subclass the textbox, as da_silvy has done. This way, your sure that no matter what the user does, the context menu will not come up. If you rely on the other ways, there may be a way around it.

  10. #10

    Thread Starter
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by abdul
    Does this messy way work:

    VB Code:
    1. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. If Button = 2 Then
    3. Call Text1_MouseDown(1, Shift, X, Y)
    4. End if
    5. End Sub
    sorry abdul, no luck with this
    -= a peet post =-

  11. #11

    Thread Starter
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    the sample u posted dave, throws errors at me ,have u tested it?
    -= a peet post =-

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Yes,

    What is the error and where is it raised?

  13. #13

    Thread Starter
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    mm... don't remember... I'll test it one more time
    -= a peet post =-

  14. #14
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Subclassing the textbox will give the best results, but it doesn't block the user from using copy and paste on the textbox. The user can always use the keyboard (CTRL-C, CTRL-V and CTRL-X)

  15. #15
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    I think he just wants to disable the popup menu...

  16. #16
    DaoK
    Guest
    Send me a Private Message next time ok because I do not want all to be part of the discussion.

    Allo, Qui est à l’appareil?
    Bonjour, C’est David à l’appareil.
    Bonjour David
    Tu voudrais voir “Kiss of The Dragon” avec moi a samedi l’après-mid?
    Je suis desolé, je veut voir le mais je ne peux pas, je suis occupé – je vais jouer au tennis à Samedi l’après-midi.
    Zut! Tu veut choisir un autre temps ou un autre jour?
    Bien sûr, tu es libre à samedi soir?
    Oui, je suis libre.
    Chouette, je vais voir toi à samedi soir
    ------------------------------------
    Hello, who is at the phone?
    Hi, it's David
    Hello David
    Whould you like to go see "Kiss ..." with me saterday afternoon?
    I am sorry but I can not, I am busy, I go play tennis but I want to see it!
    Crap, Do you want to choose an other day or an other time ?
    Of course! Are you free saterday night?
    Yes I am
    Great, I will see you saterday night

  17. #17
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Thanks man

    So that was good?

  18. #18
    Matthew Gates
    Guest
    Here you are, micronirav, just as you asked, but it's not in an application, but I'll explain what you have to do.

    This code goes into a Module file.


    VB Code:
    1. Declare Function SetWindowLong& Lib "user32" _
    2. Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As _
    3. Long, ByVal dwNewLong As Long)
    4.  
    5. Declare Function CallWindowProc Lib "user32" _
    6. Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal _
    7. hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal _
    8. lParam As Long) As Long
    9.  
    10. Const GWL_WNDPROC = (-4)
    11. Const WM_RBUTTONDOWN = &H204
    12.  
    13. Private WndProcOld As Long
    14.  
    15. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As _
    16. Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    17.     If wMsg = WM_RBUTTONDOWN Then Exit Function
    18.     WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, _
    19.     wParam&, lParam&)
    20. End Function
    21.  
    22. Sub SubClassWnd(hwnd As Long)
    23.     WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, _
    24.     AddressOf WindProc)
    25. End Sub
    26.  
    27. Sub UnSubclassWnd(hwnd As Long)
    28.     SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
    29.     WndProcOld& = 0
    30. End Sub

    And this code goes into a form, just copy and paste it.

    VB Code:
    1. Private Sub Form_Load()
    2.     SubClassWnd Text1.hwnd
    3. End Sub
    4.  
    5. Private Sub Form_Unload(Cancel As Integer)
    6.     UnSubclassWnd Text1.hwnd
    7. End Sub

  19. #19
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    That's basically what i posted man :/

    No probs micronirav

  20. #20
    Junior Member
    Join Date
    Apr 2001
    Posts
    20
    IF YOU WANNA DISABLE CUT AND PASTE TOTALLY, DON;T FORGET ABOUT THE SHORTCUTS CTRL+C AND CTRL+V, ANYONE KNOW HOW TO DISABLE THESE SHORTCUTS TOOO?

  21. #21
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yes

    PLEASE DON'T TYPE EVERYTHING IN CAPSLOCK, IT SEEMS AS THOUGH YOU'RE yelling at us

    VB Code:
    1. Declare Function SetWindowLong& Lib "user32" _
    2. Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As _
    3. Long, ByVal dwNewLong As Long)
    4.  
    5. Declare Function CallWindowProc Lib "user32" _
    6. Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal _
    7. hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal _
    8. lParam As Long) As Long
    9.  
    10. Const GWL_WNDPROC = (-4)
    11. Const WM_RBUTTONDOWN = &H204
    12. Const WM_COPY = &H301
    13. Const WM_CUT = &H300
    14. Const WM_PASTE = &H302
    15.  
    16. Private WndProcOld As Long
    17.  
    18. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As _
    19. Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    20.     If wMsg = WM_RBUTTONDOWN Or wMsg = WM_COPY Or wMsg = WM_CUT Or msg = WM_PASTE Then
    21.         Exit Function
    22.     End If
    23.     WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, _
    24.     wParam&, lParam&)
    25. End Function
    26.  
    27. Sub SubClassWnd(hwnd As Long)
    28.     WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, _
    29.     AddressOf WindProc)
    30. End Sub
    31.  
    32. Sub UnSubclassWnd(hwnd As Long)
    33.     SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
    34.     WndProcOld& = 0
    35. End Sub

    VB Code:
    1. Private Sub Form_Load()
    2.     SubClassWnd Text1.hwnd
    3. End Sub
    4.  
    5. Private Sub Form_Unload(Cancel As Integer)
    6.     UnSubclassWnd Text1.hwnd
    7. End Sub



    That does what you want

  22. #22
    Hyperactive Member scsa20's Avatar
    Join Date
    Apr 2001
    Location
    Mars
    Posts
    456
    I'm able to get around it by using the key on the right side that's between the Windows Key and the Ctrl key


    p|-|34|2 /\/\3 f0|2 | $p34k 1337
    My TSS quote of the day: "If your haveing a bad day, just press the restart button."

  23. #23
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Smile Info.

    There's no need to sub-class the WM_RBUTTONDOWN message... Just look for the WM_CONTEXT message, which is sent to controls to show the default context menu...

    I wrote some code in this thread demonstrating this: http://forums.vb-world.net/showthrea...threadid=97630

    Hope this helps.
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  24. #24
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I must say that it's funny to notice that da_silvy, who in another thread claimed he didn't post any code previously posted, has simply copied the code from the tip I provided several years ago.
    http://www.vb-world.net/tips/tip131.html

  25. #25
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    heheh i didn't notice that

    i didn't copy it from there though

    i used matt gates' code as a base then just added the handling for WM_COPY, WM_CUT and WM_PASTE

    anyway:

    I wrote in the other thread something along the lines of:

    I don't post code that someone else has already posted in the same thread!

    anyway, why'd you bring it up?

    trying to make a fool out of me?

  26. #26
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I was refering to your first post in this thread, not the one using WM_CUT|COPY|PASTE messages.
    And i think you're doing a good job of making a fool out of yourself so I don't have to... Just kidding.

  27. #27
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    hehehe

    i can't remember where i got that from

    Pretty sure it wasn't vb-world though...

    at least it was in this thread then i would've copped it

  28. #28
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Of course it comes from my tip here at VB-World.
    It uses the exact same variable names and even the comments are exactly the same and on the same place.
    But never mind.
    The code in the tip section is there so you and anybody else can use it.

  29. #29
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yeah

    i remember though

    I wrote

    I don't post code that has already been posted in that thread...

  30. #30
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    this works really well pEEt, thanks

    although now my boss wants the copy and paste functions in there aswell! lol

    /me goes back to work

  31. #31
    Lively Member
    Join Date
    Mar 2003
    Posts
    68
    I know this thread is old - but I found it and some others very good at answering some questions.

    I put all the information together into the following code for a module - hopefully it helps someone else.

    VB Code:
    1. Option Explicit
    2.  
    3. Public Enum GetWindowLongIndexes
    4.     GWL_EXSTYLE = (-20)
    5.     GWL_HINSTANCE = (-6)
    6.     GWL_HWNDPARENT = (-8)
    7.     GWL_ID = (-12)
    8.     GWL_STYLE = (-16)
    9.     GWL_USERDATA = (-21)
    10.     GWL_WNDPROC = (-4)
    11. End Enum
    12.  
    13. Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As GetWindowLongIndexes) As Long
    14. Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As GetWindowLongIndexes, ByVal dwNewLong As Long) As Long
    15.  
    16. Public Enum WindowMessages
    17.     WM_NULL = &H0   ' 0
    18.     WM_CREATE = &H1 ' 1
    19.     WM_DESTROY = &H2    ' 2
    20.     WM_MOVE = &H3   ' 3
    21.     WM_SIZE = &H5   ' 5
    22.     WM_ACTIVATE = &H6   ' 6
    23.     WM_SETFOCUS = &H7   ' 7
    24.     WM_KILLFOCUS = &H8  ' 8
    25.     WM_ENABLE = &HA ' 10
    26.     WM_SETREDRAW = &HB  ' 11
    27.     WM_SETTEXT = &HC    ' 12
    28.     WM_GETTEXT = &HD    ' 13
    29.     WM_GETTEXTLENGTH = &HE  ' 14
    30.     WM_PAINT = &HF  ' 15
    31.     WM_CLOSE = &H10 ' 16
    32.     WM_QUERYENDSESSION = &H11   ' 17
    33.     WM_QUIT = &H12  ' 18
    34.     WM_QUERYOPEN = &H13 ' 19
    35.     WM_ERASEBKGND = &H14    ' 20
    36.     WM_SYSCOLORCHANGE = &H15    ' 21
    37.     WM_ENDSESSION = &H16    ' 22
    38.     WM_SHOWWINDOW = &H18    ' 24
    39.     WM_SETTINGCHANGE = &H1A ' 26
    40.     WM_WININICHANGE = &H1A  ' 26
    41.     WM_DEVMODECHANGE = &H1B ' 27
    42.     WM_ACTIVATEAPP = &H1C   ' 28
    43.     WM_FONTCHANGE = &H1D    ' 29
    44.     WM_TIMECHANGE = &H1E    ' 30
    45.     WM_CANCELMODE = &H1F    ' 31
    46.     WM_CAPTURECHANGED = &H1F    ' 31
    47.     WM_SETCURSOR = &H20 ' 32
    48.     WM_MOUSEACTIVATE = &H21 ' 33
    49.     WM_CHILDACTIVATE = &H22 ' 34
    50.     WM_QUEUESYNC = &H23 ' 35
    51.     WM_GETMINMAXINFO = &H24 ' 36
    52.     WM_PAINTICON = &H26 ' 38
    53.     WM_ICONERASEBKGND = &H27    ' 39
    54.     WM_NEXTDLGCTL = &H28    ' 40
    55.     WM_SPOOLERSTATUS = &H2A ' 42
    56.     WM_DRAWITEM = &H2B  ' 43
    57.     WM_MEASUREITEM = &H2C   ' 44
    58.     WM_DELETEITEM = &H2D    ' 45
    59.     WM_VKEYTOITEM = &H2E    ' 46
    60.     WM_CHARTOITEM = &H2F    ' 47
    61.     WM_SETFONT = &H30   ' 48
    62.     WM_GETFONT = &H31   ' 49
    63.     WM_SETHOTKEY = &H32 ' 50
    64.     WM_GETHOTKEY = &H33 ' 51
    65.     WM_QUERYDRAGICON = &H37 ' 55
    66.     WM_COMPAREITEM = &H39   ' 57
    67.     WM_COMPACTING = &H41    ' 65
    68.     WM_WINDOWPOSCHANGING = &H46 ' 70
    69.     WM_WINDOWPOSCHANGED = &H47  ' 71
    70.     WM_POWER = &H48 ' 72
    71.     WM_COPYDATA = &H4A  ' 74
    72.     WM_CANCELJOURNAL = &H4B ' 75
    73.     WM_INPUTLANGCHANGEREQUEST = &H50    ' 80
    74.     WM_INPUTLANGCHANGE = &H51   ' 81
    75.     WM_HELP = &H53  ' 83
    76.     WM_CONTEXTMENU = &H7B   ' 123
    77.     WM_NCCREATE = &H81  ' 129
    78.     WM_NCDESTROY = &H82 ' 130
    79.     WM_NCCALCSIZE = &H83    ' 131
    80.     WM_NCHITTEST = &H84 ' 132
    81.     WM_NCPAINT = &H85   ' 133
    82.     WM_NCACTIVATE = &H86    ' 134
    83.     WM_GETDLGCODE = &H87    ' 135
    84.     WM_NCMOUSEMOVE = &HA0   ' 160
    85.     WM_NCLBUTTONDOWN = &HA1 ' 161
    86.     WM_NCLBUTTONUP = &HA2   ' 162
    87.     WM_NCLBUTTONDBLCLK = &HA3   ' 163
    88.     WM_NCRBUTTONDOWN = &HA4 ' 164
    89.     WM_NCRBUTTONUP = &HA5   ' 165
    90.     WM_NCRBUTTONDBLCLK = &HA6   ' 166
    91.     WM_NCMBUTTONDOWN = &HA7 ' 167
    92.     WM_NCMBUTTONUP = &HA8   ' 168
    93.     WM_NCMBUTTONDBLCLK = &HA9   ' 169
    94.     WM_KEYDOWN = &H100  ' 256 - Also repeats when key held down
    95.     WM_KEYUP = &H101    ' 257
    96.     WM_CHAR = &H102 ' 258
    97.     WM_DEADCHAR = &H103 ' 259
    98.     WM_SYSKEYDOWN = &H104   ' 260
    99.     WM_SYSKEYUP = &H105 ' 261
    100.     WM_SYSCHAR = &H106  ' 262
    101.     WM_SYSDEADCHAR = &H107  ' 263
    102.     WM_CONVERTREQUESTEX = &H108 ' 264
    103.     WM_IME_STARTCOMPOSITION = &H10D ' 269
    104.     WM_IME_ENDCOMPOSITION = &H10E   ' 270
    105.     WM_IME_COMPOSITION = &H10F  ' 271
    106.     WM_IME_KEYLAST = &H10F  ' 271
    107.     WM_INITDIALOG = &H110   ' 272
    108.     WM_COMMAND = &H111  ' 273
    109.     WM_SYSCOMMAND = &H112   ' 274
    110.     WM_TIMER = &H113    ' 275
    111.     WM_HSCROLL = &H114  ' 276
    112.     WM_VSCROLL = &H115  ' 277
    113.     WM_INITMENU = &H116 ' 278
    114.     WM_INITMENUPOPUP = &H117    ' 279
    115.     WM_MENUSELECT = &H11F   ' 287
    116.     WM_MENUCHAR = &H120 ' 288
    117.     WM_ENTERIDLE = &H121    ' 289
    118.     WM_MENURBUTTONUP = &H122    ' 290
    119.     WM_MENUDRAG = &H123 ' 291
    120.     WM_MENUGETOBJECT = &H124    ' 292
    121.     WM_MENUCOMMAND = &H126  ' 294
    122.     WM_CTLCOLORMSGBOX = &H132   ' 306
    123.     WM_CTLCOLOREDIT = &H133 ' 307
    124.     WM_CTLCOLORLISTBOX = &H134  ' 308
    125.     WM_CTLCOLORBTN = &H135  ' 309
    126.     WM_CTLCOLORDLG = &H136  ' 310
    127.     WM_CTLCOLORSCROLLBAR = &H137    ' 311
    128.     WM_CTLCOLORSTATIC = &H138   ' 312
    129.     WM_MOUSEMOVE = &H200    ' 512
    130.     WM_LBUTTONDOWN = &H201  ' 513
    131.     WM_LBUTTONUP = &H202    ' 514
    132.     WM_LBUTTONDBLCLK = &H203    ' 515
    133.     WM_RBUTTONDOWN = &H204  ' 516
    134.     WM_RBUTTONUP = &H205    ' 517
    135.     WM_RBUTTONDBLCLK = &H206    ' 518
    136.     WM_MBUTTONDOWN = &H207  ' 519
    137.     WM_MBUTTONUP = &H208    ' 520
    138.     WM_MBUTTONDBLCLK = &H209    ' 521
    139.     WM_MOUSEWHEEL = &H20A   ' 522
    140.     WM_PARENTNOTIFY = &H210 ' 528
    141.     WM_ENTERMENULOOP = &H211    ' 529
    142.     WM_EXITMENULOOP = &H212 ' 530
    143.     WM_NEXTMENU = &H213 ' 531
    144.     WM_SIZING = &H214   ' 532
    145.     WM_CAPTURECHANGED_R = &H215 ' 533
    146.     WM_MOVING = &H216   ' 534
    147.     WM_POWERBROADCAST = &H218   ' 536
    148.     WM_DEVICECHANGE = &H219 ' 537
    149.     WM_MDICREATE = &H220    ' 544
    150.     WM_MDIDESTROY = &H221   ' 545
    151.     WM_MDIACTIVATE = &H222  ' 546
    152.     WM_MDIRESTORE = &H223   ' 547
    153.     WM_MDINEXT = &H224  ' 548
    154.     WM_MDIMAXIMIZE = &H225  ' 549
    155.     WM_MDITILE = &H226  ' 550
    156.     WM_MDICASCADE = &H227   ' 551
    157.     WM_MDIICONARRANGE = &H228   ' 552
    158.     WM_MDIGETACTIVE = &H229 ' 553
    159.     WM_MDISETMENU = &H230   ' 560
    160.     WM_ENTERSIZEMOVE = &H231    ' 561
    161.     WM_EXITSIZEMOVE = &H232 ' 562
    162.     WM_DROPFILES = &H233    ' 563
    163.     WM_MDIREFRESHMENU = &H234   ' 564
    164.     WM_IME_SETCONTEXT = &H281   ' 641
    165.     WM_IME_NOTIFY = &H282   ' 642
    166.     WM_IME_CONTROL = &H283  ' 643
    167.     WM_IME_COMPOSITIONFULL = &H284  ' 644
    168.     WM_IME_SELECT = &H285   ' 645
    169.     WM_IME_CHAR = &H286 ' 646
    170.     WM_IME_KEYDOWN = &H290  ' 656
    171.     WM_IME_KEYUP = &H291    ' 657
    172.     WM_MOUSEHOVER = &H2A1   ' 673
    173.     WM_MOUSELEAVE = &H2A3   ' 675
    174.     WM_CUT = &H300  ' 768
    175.     WM_COPY = &H301 ' 769
    176.     WM_PASTE = &H302    ' 770
    177.     WM_CLEAR = &H303    ' 771
    178.     WM_UNDO = &H304 ' 772
    179.     WM_RENDERFORMAT = &H305 ' 773
    180.     WM_RENDERALLFORMATS = &H306 ' 774
    181.     WM_DESTROYCLIPBOARD = &H307 ' 775
    182.     WM_DRAWCLIPBOARD = &H308    ' 776
    183.     WM_PAINTCLIPBOARD = &H309   ' 777
    184.     WM_VSCROLLCLIPBOARD = &H30A ' 778
    185.     WM_SIZECLIPBOARD = &H30B    ' 779
    186.     WM_ASKCBFORMATNAME = &H30C  ' 780
    187.     WM_CHANGECBCHAIN = &H30D    ' 781
    188.     WM_HSCROLLCLIPBOARD = &H30E ' 782
    189.     WM_QUERYNEWPALETTE = &H30F  ' 783
    190.     WM_PALETTEISCHANGING = &H310    ' 784
    191.     WM_PALETTECHANGED = &H311   ' 785
    192.     WM_HOTKEY = &H312   ' 786
    193.     WM_PRINT = &H317    ' 791
    194.     WM_PRINTCLIENT = &H318  ' 792
    195.     WM_APPCOMMAND = &H319   ' 793
    196.     WM_PENWINFIRST = &H380  ' 896
    197.     WM_PENWINLAST = &H38F   ' 911
    198.     WM_DDE_FIRST = &H3E0    ' 992
    199.     WM_DDE_INITIATE = &H3E0 ' 992
    200.     WM_DDE_TERMINATE = (&H3E0 + 1)  ' 993
    201.     WM_DDE_ADVISE = (&H3E0 + 2) ' 994
    202.     WM_DDE_UNADVISE = (&H3E0 + 3)   ' 995
    203.     WM_DDE_ACK = (&H3E0 + 4)    ' 996
    204.     WM_DDE_DATA = (&H3E0 + 5)   ' 997
    205.     WM_DDE_REQUEST = (&H3E0 + 6)    ' 998
    206.     WM_DDE_POKE = (&H3E0 + 7)   ' 999
    207.     WM_DDE_EXECUTE = (&H3E0 + 8)    ' 1000
    208.     WM_DDE_LAST = (&H3E0 + 8)   ' 1000
    209.     WM_PSD_PAGESETUPDLG = (&H400)   ' 1024
    210.     WM_USER = &H400 ' 1024
    211.     WM_CHOOSEFONT_GETLOGFONT = &H401    ' 1025
    212.     WM_PSD_FULLPAGERECT = (&H400 + 1)   ' 1025
    213.     WM_PSD_MINMARGINRECT = (&H400 + 2)  ' 1026
    214.     WM_PSD_MARGINRECT = (&H400 + 3) ' 1027
    215.     WM_PSD_GREEKTEXTRECT = (&H400 + 4)  ' 1028
    216.     WM_PSD_ENVSTAMPRECT = (&H400 + 5)   ' 1029
    217.     WM_PSD_YAFULLPAGERECT = (&H400 + 6) ' 1030
    218.     WM_CHOOSEFONT_SETLOGFONT = (&H400 + 101)    ' 1125
    219.     WM_CHOOSEFONT_SETFLAGS = (&H400 + 102)  ' 1126
    220. End Enum
    221.  
    222. Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As WindowMessages, ByVal wParam As Long, ByVal lParam As Long) As Long
    223.  
    224. Public Function MyWindowProc(ByVal hwnd As Long, ByVal wMsg As WindowMessages, ByVal wParam As Long, ByVal lParam As Long) As Long
    225. '    Debug.Print ("wMsg = " & CStr(wMsg))
    226.     Select Case wMsg
    227.         'Put the events you want to ignore/act-on on in here
    228.         Case WM_RBUTTONDOWN
    229.             Debug.Print ("Right button has been disabled")
    230.         Case WM_COPY
    231.             Debug.Print ("Ctrl-C has been disabled")
    232.         Case WM_CUT
    233.             Debug.Print ("Ctrl-X has been disabled")
    234.         Case WM_PASTE
    235.             Debug.Print ("Ctrl-V has been disabled")
    236.         Case WM_CONTEXTMENU
    237.             Debug.Print ("Menu Key has been disabled")
    238.         Case Else
    239.             MyWindowProc = CallWindowProc(GetWindowLong(hwnd, GWL_USERDATA), hwnd, wMsg, wParam, lParam)
    240.     End Select
    241. End Function
    242.  
    243. ' Recommended Usage
    244. '
    245. ' Private Sub Form_Load()
    246. '     Call SubClassWnd( MyObject.hwnd )
    247. ' End Sub
    248.  
    249. Public Sub SubClassWnd(hwnd As Long)
    250.     Call SetWindowLong(hwnd, GWL_USERDATA, SetWindowLong(hwnd, GWL_WNDPROC, AddressOf MyWindowProc))
    251. End Sub
    252.  
    253. ' Recommended Usage
    254. '
    255. ' Private Sub Form_Unload(Cancel As Integer)
    256. '     Call UnSubclassWnd( MyObject.hwnd )
    257. ' End Sub
    258.  
    259. Sub UnSubclassWnd(hwnd As Long)
    260.     Call SetWindowLong(hwnd, GWL_WNDPROC, GetWindowLong(hwnd, GWL_USERDATA))
    261.     Call SetWindowLong(hwnd, GWL_USERDATA, 0)
    262. 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
  •  



Click Here to Expand Forum to Full Width