|
-
Sep 6th, 2005, 03:06 PM
#1
Thread Starter
Addicted Member
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:
Option Explicit
Private Const GWL_WNDPROC = (-4)
Private Const WM_RBUTTONUP = &H205
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (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 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
Private m_lWndProc As Long
Private OriginalWndProc As Long
Public Sub WindowHook(hWnd As Long)
m_lWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf MessageCenter)
OriginalWndProc = hWnd
End Sub
Public Sub WindowFree(hWnd As Long)
SetWindowLong hWnd, GWL_WNDPROC, m_lWndProc
End Sub
Private Function MessageCenter(ByVal hWnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
'Only suppress context menu for hooked control
If Msg = WM_RBUTTONUP Then
If hWnd = OriginalWndProc Then
Form1.PopupMenu Form1.mnuCustom
MessageCenter = 0
Exit Function
End If
End If
'Pass it on to the normal window processor.
MessageCenter = CallWindowProc(m_lWndProc, hWnd, Msg, wParam, lParam)
End Function
Last edited by DKasler; Sep 6th, 2005 at 04:46 PM.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
Sep 6th, 2005, 03:26 PM
#2
Re: Right click menu in a combo box
This works for a combo 
VB Code:
'Module code
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
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4
Public Const WM_CONTEXTMENU As Long = &H7B
Public lpPrevWndProc As Long
Private lnghWnd As Long
Public Sub Hook(hWnd As Long)
Dim h As Long
h = FindWindowEx(hWnd, 0&, "Edit", vbNullString)
lnghWnd = h
lpPrevWndProc = SetWindowLong(lnghWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook()
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(lnghWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub
Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_CONTEXTMENU
Exit Function
Case WM_DESTROY
UnHook
End Select
WindowProc = CallWindowProc(lpPrevWndProc, lnghWnd, uMsg, wParam, lParam)
End Function
In a form :
VB Code:
'form code
Option Explicit
Private Sub Form_Load()
Hook Combo1.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Sep 6th, 2005, 03:27 PM
#3
-
Sep 6th, 2005, 03:27 PM
#4
Re: Right click menu in a combo box
This will work for the dropdown portion of the cbo and not just the primary textbox?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 6th, 2005, 03:29 PM
#5
-
Sep 6th, 2005, 03:33 PM
#6
Re: Right click menu in a combo box
Yes, post #2. It looks like it doesnt apply to the dropdown portion.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 6th, 2005, 03:35 PM
#7
-
Sep 6th, 2005, 03:39 PM
#8
Thread Starter
Addicted Member
Re: Right click menu in a combo box
Ok... 2 questions...
1) What needs to be in the vbmenu editor for this to work?
2) Im getting (;t put in the text box when the form loads, and it didnt do that till I hooked the contol.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
Sep 6th, 2005, 03:39 PM
#9
Re: Right click menu in a combo box
Thats what I thought but perhaps the code can be modded easily to include that functionality. I dont think the dropdown listbox is really parented by the cbo since it may be a child of the editbox's control.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 6th, 2005, 03:42 PM
#10
-
Sep 6th, 2005, 03:44 PM
#11
-
Sep 6th, 2005, 03:46 PM
#12
Re: Right click menu in a combo box
Thats what I thought. The dropdown is independant from the cbo. Its not a child window then but a FindWindow API candidate. 
Ps, too lazy to check it out myself.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 6th, 2005, 03:52 PM
#13
-
Sep 6th, 2005, 03:54 PM
#14
-
Sep 6th, 2005, 04:10 PM
#15
Re: Right click menu in a combo box
Yes, but shouldnt the message for the click be the WM_COMMAND? or is it a different one for the right click?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 6th, 2005, 04:14 PM
#16
Thread Starter
Addicted Member
Re: Right click menu in a combo box
Forgive me for being a bit confused...
but from the code you pasted how can I get a right click menu on the combo box?
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
Sep 6th, 2005, 04:27 PM
#17
-
Sep 6th, 2005, 04:27 PM
#18
-
Sep 6th, 2005, 04:36 PM
#19
Thread Starter
Addicted Member
Re: Right click menu in a combo box
Last edited by DKasler; Sep 6th, 2005 at 04:45 PM.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
Sep 6th, 2005, 04:46 PM
#20
-
Sep 6th, 2005, 04:48 PM
#21
Thread Starter
Addicted Member
Re: Right click menu in a combo box
 Originally Posted by manavo11
Can you post your code? 
I figured it out, I accidently removed the "Exit Function" when I put my menu code in.
Thanks alot for the help.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
Jan 7th, 2006, 03:30 PM
#22
Addicted Member
Re: Right click menu in a combo box
 Originally Posted by DKasler
I figured it out, I accidently removed the "Exit Function" when I put my menu code in.
Thanks alot for the help.
Can You Show Me What did you Do with "WindowProc" Function ?
Because i want to Pop up my Menu
-
Jan 16th, 2006, 02:33 AM
#23
Re: Right click menu in a combo box [RESOLVED]
In the code in post #2, you need to add code to popup your own menu :
VB Code:
Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_CONTEXTMENU
[hl=yellow][b]PopupMenu YourMenu[/b][/hl]
Exit Function
Case WM_DESTROY
UnHook
End Select
WindowProc = CallWindowProc(lpPrevWndProc, lnghWnd, uMsg, wParam, lParam)
End Function
Has someone helped you? Then you can Rate their helpful post. 
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
|