Results 1 to 8 of 8

Thread: Weird reaction on a popup menu *RESOLVED*

  1. #1

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067

    Weird reaction on a popup menu *RESOLVED*

    I have text box which has has a popup menu associated with the right click of the mouse, however, the user is required to click twice in order for my menui to appear. The first click displays the Cut,Copy,Paste menu and then the next click shows my menu. I have stepped through the code and the event is firing.
    any suggestions?

    Mega.
    Last edited by Mega_Man; Oct 30th, 2002 at 03:52 PM.
    "If at first you don't succeed, then skydiving is not for you"

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I believe the only way to turn off the built-in menu is through message hooking. Are you aware of message hooking and it's problems? If not, then one thing you need to know is that when message hooking is active, if you stop your running program by clicking the little "End" button on the IDE menu, VB crashes. To get around that annoying behavior I have a Conditional Compilation Argument called Testing that I turn on in development and off when I compile.
    VB Code:
    1. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    2.         (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    3. Public Const GWL_WNDPROC = -4
    4.  
    5. ' In Form_Load do the following (you could use the For Each method of stepping through the controls)
    6.     For intIndex = 0 To Controls.Count - 1
    7.         #If Testing Then
    8.             ' Don't hook
    9.         #Else
    10.             If TypeOf Controls(intIndex) Is TextBox Then
    11.                 ' Turn off the TextBox system right-click menu
    12.                 Call Hook(Controls(intIndex).hwnd)
    13.             End If
    14.         #End If
    15.     Next
    16.  
    17. Private Sub Form_Unload(Cancel As Integer)
    18.  
    19.     Call UnHook
    20.    
    21. End Sub
    22.  
    23. Public Sub Hook(hwnd As Long)
    24.  
    25.     lngHWnd = hwnd
    26.     lpPrevWndProc = SetWindowLong(lngHWnd, GWL_WNDPROC, AddressOf WindowProc)
    27.    
    28. End Sub
    29.  
    30. Public Sub UnHook()
    31.  
    32.     Dim lngReturnValue As Long
    33.    
    34.     lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, lpPrevWndProc)
    35.    
    36. End Sub

  3. #3

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Martin,
    Thanks a lot. Much appreciated.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  4. #4

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Martin,
    Are there a couple of API calls missing here?
    I cannot seem to get it to work. Missing reference to WindowProc etc..

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Sorry...

    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


    Also I believe that the Hook and UnHook subs need to be in a code module.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    and

    VB Code:
    1. Public Const WM_RBUTTONUP = &H205
    2. Public lpPrevWndProc As Long
    3.  
    4. Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, _
    5.                     ByVal lParam As Long) As Long
    6.    
    7.     Select Case uMsg
    8.         Case WM_RBUTTONUP
    9.         'Do nothing
    10.         'Or popup you own menu
    11.     Case Else
    12.         WindowProc = CallWindowProc(lpPrevWndProc, hwnd, _
    13.         uMsg, wParam, lParam)
    14.     End Select
    15.    
    16. End Function

  7. #7

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Ok,
    Thanks again.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  8. #8
    Lively Member ac11965's Avatar
    Join Date
    May 2000
    Location
    East London, South Africa
    Posts
    69
    hi there

    how do you actually use the windowproc procedure?
    can you please send me an example?

    thanks

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