Results 1 to 23 of 23

Thread: Right click menu in a combo box [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Resolved Right click menu in a combo box [RESOLVED]

    I have some code, that I found and it works fine with a text box but i cant figure out how to make it work with a combo box since a combo box does not have a mousedown function.

    Anythoughts? or have a better way of doing it?

    PS. I tried subclassing the combo box to add the mousedown function with some code I found but that didnt seem to help.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const GWL_WNDPROC = (-4)
    4. Private Const WM_RBUTTONUP = &H205
    5.  
    6.  
    7.  
    8. Private Declare Function GetWindowLong Lib "user32" Alias _
    9. "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    10.  
    11. Private Declare Function SetWindowLong Lib "user32" Alias _
    12. "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As _
    13. Long, ByVal dwNewLong As Long) As Long
    14.  
    15. Private Declare Function CallWindowProc Lib "user32" Alias _
    16. "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd _
    17. As Long, ByVal Msg As Long, ByVal wParam As Long, _
    18. ByVal lParam As Long) As Long
    19.  
    20. Private m_lWndProc As Long
    21. Private OriginalWndProc As Long
    22.  
    23. Public Sub WindowHook(hWnd As Long)
    24.     m_lWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf MessageCenter)
    25.     OriginalWndProc = hWnd
    26. End Sub
    27.  
    28.  
    29.  
    30. Public Sub WindowFree(hWnd As Long)
    31.  
    32.     SetWindowLong hWnd, GWL_WNDPROC, m_lWndProc
    33. End Sub
    34.  
    35. Private Function MessageCenter(ByVal hWnd As Long, ByVal Msg As Long, _
    36. ByVal wParam As Long, ByVal lParam As Long) As Long
    37.  
    38. 'Only suppress context menu for hooked control
    39.  
    40.         If Msg = WM_RBUTTONUP Then
    41.          If hWnd = OriginalWndProc Then
    42.             Form1.PopupMenu Form1.mnuCustom
    43.             MessageCenter = 0
    44.            Exit Function
    45.         End If
    46.     End If
    47.    
    48.            
    49. 'Pass it on to the normal window processor.
    50. MessageCenter = CallWindowProc(m_lWndProc, hWnd, Msg, wParam, lParam)
    51. End Function
    Last edited by DKasler; Sep 6th, 2005 at 04:46 PM.
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

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