jim mcnamara replied to an earlier thread of mine with the following code, which works to trap the right mouse up on an entire row...BUT:

How do I subclass a datagrid to catch the WM_RBUTTONUP message on one of the cells...
(I want to replace the normal "copy..cut..paste" context menu with my own)


____________________________________________________
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.