Hello Paul,
When we have to deal with message WM_CONTEXTMENU or WM_NOTIFY in a specific FORM we have to use the CUSTOM message handler of the FORM.
Is-it possible to have separate message handlers for WM_CONTEXTMENU and WM_NOTIFY in the same way we have for WM_CREATE, WM_COMMAND, WM_CLOSE, WM_DESTROY, etc ...
Thanks,
Jean-Pierre
WM_NOTIFY should already be available...isn't it?
Paul,
Yes you're right, only the WM_CONTEXTMENU is missing; could-it be possible to have it on a new version ?
In fact I mentioned WM_NOTIFY because I usually manage the WM_NOTIFY notification trough the CUSTOM message handler of the FORM in the case below; just because I don't know how to adapt this code to be directly under the WM_NOTIFY handler ... all ideas are welcome.
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Local MinMaxPtr As MINMAXINFO Ptr
Static hPopupMenu As Dword
Local lSelectedRow As Long
Select Case wMsg
Case %WM_NOTIFY
Local lpNmh As NMHDR Ptr
Local lpLvNm As NM_LISTVIEW Ptr
Local lpLvCd As NMLVCUSTOMDRAW Ptr
Local lRow As Long
Local lCol As Long
lpNmh = lParam
If @lpNmh.idFrom = IDC_FORM1_LISTVIEW1 Then
lpLvNm = lParam
Select Case @LpLvNm.hdr.Code
Case %NM_CUSTOMDRAW
lpLvCd = lParam
Select Case @lplvcd.nmcd.dwDrawStage
Case %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
Function = %CDRF_NOTIFYSUBITEMDRAW
Case %CDDS_ITEMPREPAINT Or %CDDS_SUBITEM
' to retrieve the line and column number of the cell
lRow = @lpLvCd.nmcd.dwItemSpec ' Line number
lCol = @lpLvCd.iSubItem ' Column number
' for demonstration purpose => should be adapted for your needs
Select Case lRow Mod 3
Case 0
@lpLvCd.clrText = &H0000FF00 ' green text
Case 1
@lpLvCd.clrText = &H000000FF ' red text
Case 2
@lpLvCd.clrTextBk = &H00D8E9EC ' grey backcolor
End Select
Function = %CDRF_NEWFONT
End Select
End Select
End If ' If @lpNmh.idFrom = IDC_FORM1_LISTVIEW1 Then
End Select
End Function
Thanks
Jean-Pierre
Paul,
I was finally able to adapt the code to be directly under the WM_NOTIFY handler:
Function FORM1_WM_NOTIFY ( _
hWndForm As Dword, _ ' handle of Form
idCtrl As Dword, _ ' control ID
ByVal pNMHDR As NMHDR Ptr _ ' pointer to NMHDR structure
) As Long
Local lpLvCd As NMLVCUSTOMDRAW Ptr
Local lRow As Long
Local lCol As Long
' if we are on the right control
If @pNMHDR.idFrom = IDC_FORM1_LISTVIEW1 Then
Select Case @pNMHDR.Code
Case %NM_CUSTOMDRAW
lpLvCd = pNMHDR
Select Case @lplvcd.nmcd.dwDrawStage
Case %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
Function = %CDRF_NOTIFYSUBITEMDRAW
Case %CDDS_ITEMPREPAINT Or %CDDS_SUBITEM
' to retrieve the line and column number of the cell
lRow = @lpLvCd.nmcd.dwItemSpec ' Line number
lCol = @lpLvCd.iSubItem ' Column number
' for demonstration purpose => should be adapted for your needs
Select Case lRow Mod 3
Case 0
@lpLvCd.clrText = &H0000FF00 ' green text
Case 1
@lpLvCd.clrText = &H000000FF ' red text
Case 2
@lpLvCd.clrTextBk = &H00D8E9EC ' grey backcolor
End Select
Function = %CDRF_NEWFONT
End Select
End Select
End If ' If @pNMHDR.idFrom = IDC_FORM1_LISTVIEW1 Then
End Function
I think it's correct .. at least that works.
Jean-Pierre
About half the time I use the WM_NOTIFY handler and the other half I use CUSTOM.... my only fear is that if I use CUSTOM and then later add code to the WM_NOTIFY handler that I will duplicate code or cause a conflict between the two. I really should be more disciplined to use one approach or the other. :)
Paul,
Could it be possible to have a separate message handler for the WM_CONTEXTMENU in the next update ?
Thanks
Jean-Pierre
Quote from: TechSupport on April 30, 2010, 12:50:16 PM
About half the time I use the WM_NOTIFY handler and the other half I use CUSTOM.... my only fear is that if I use CUSTOM and then later add code to the WM_NOTIFY handler that I will duplicate code or cause a conflict between the two. I really should be more disciplined to use one approach or the other. :)
I usually only use WM_CREATE/DESTROY and the Custom message for the form. I just like having everything in one place and not having to add extra functions/stack processing. If I'm making a quick and simple app I'll use the button clicks, but very seldom use the other functions if ever.
Along these same lines though, did we ever get special processing for QueryEndSession too?
Quote from: Jean-Pierre Leroy on April 30, 2010, 05:19:33 PM
Paul,
Could it be possible to have a separate message handler for the WM_CONTEXTMENU in the next update ?
Thanks
Jean-Pierre
I'll see what I can do. It shouldn't be a problem....famous last words. :)
Quote from: Roger Garstang on April 30, 2010, 06:37:40 PM
Along these same lines though, did we ever get special processing for QueryEndSession too?
Nope - I never did anything special for that message.
The WM_CONTEXTMENU message handler has now been implemented.
Quote from: TechSupport on April 30, 2010, 10:12:31 PM
Quote from: Roger Garstang on April 30, 2010, 06:37:40 PM
Along these same lines though, did we ever get special processing for QueryEndSession too?
Nope - I never did anything special for that message.
Processing it in FF is difficult since you return opposite values. A built-in Form message handler for it would be ideal. I think there may be a couple other messages like it too, but I've only ever used it in code.
QuoteThe WM_CONTEXTMENU message handler has now been implemented.
Thank you very much Paul.
Jean-Pierre