|
-
Oct 17th, 2001, 03:57 PM
#1
right click conflict...subclassing?
Here's the scenario:
I've got a control (DataGrid) that I want to display my popup menu when I right click in a cell. So I have a "mouseup" routine that looks for a right click.
Problem is that the control, as part of its native functionality, also reacts to the right click event to display the standard edit popup menu.
My question is how to I pre-emp the native popup with my own?
subclassing...?
-
Oct 17th, 2001, 04:15 PM
#2
You have to trap the message - stop it from going to the window, and then do your routine instead.
Classic use for sublcassing.
-
Oct 17th, 2001, 04:18 PM
#3
right click conflict...subclassing?
OK.
Could you be real specific--because I'm new to VB and subclassing is just a concept right now.
Thanks!
-
Oct 18th, 2001, 06:03 AM
#4
Subclass your datagrid to catch the WM_RBUTTONUP message.
in a .BAS module:
Code:
Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
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
Const GWL_WNDPROC = (-4)
Const WM_RBUTTONUP = &H205
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_RBUTTONUP Then
' display your popup menu here
Exit Function ' since you only want your menu exit
' if you let the message thru, then the other menu
' will appear
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
usage:
Call SubCLassWnd(Datagrid1.hWnd)
MAKE SURE TO CALL !!! ->
UnSubclassWnd(Datagrid1.hWnd)
before you exit or your program will crash on exit. That means
you have to do this in the Form_Unload event.
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
|