PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Jean-pierre Leroy on April 29, 2010, 06:17:57 PM

Title: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Jean-pierre Leroy on April 29, 2010, 06:17:57 PM
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
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Paul Squires on April 29, 2010, 09:17:51 PM
WM_NOTIFY should already be available...isn't it?

Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Jean-pierre Leroy on April 30, 2010, 06:51:28 AM
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
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Jean-pierre Leroy on April 30, 2010, 12:14:54 PM
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
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Paul Squires 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.  :)

Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: 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
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Roger Garstang on April 30, 2010, 06:37:40 PM
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?
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Paul Squires on April 30, 2010, 10:11:50 PM
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.  :)
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Paul Squires 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.
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Paul Squires on May 03, 2010, 09:59:28 AM
The WM_CONTEXTMENU message handler has now been implemented.
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Roger Garstang on May 03, 2010, 06:10:02 PM
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.
Title: Re: New special separate message handlers for WM_CONTEXTMENU and WM_NOTIFY
Post by: Jean-pierre Leroy on May 04, 2010, 06:21:27 AM
QuoteThe WM_CONTEXTMENU message handler has now been implemented.

Thank you very much Paul.

Jean-Pierre