PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Mark Strickland on October 06, 2005, 08:18:40 AM

Title: ListView Colors
Post by: Mark Strickland on October 06, 2005, 08:18:40 AM
I need to make rows in a ListView different colors (either text or background) to help make a list more readable.

I looked on the Web but I am not sure how some of the methods will work with FF.

Any thoughts or some other method all together?

Thanks.
Title: ListView Colors
Post by: TechSupport on October 06, 2005, 11:10:40 AM
The following is some quick code that I stole from POFSS and adapted to FireFly.

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 lpNmh  As NMHDR Ptr
   Local lpLvNm As NM_LISTVIEW Ptr
   Local lpLvCd As NMLVCUSTOMDRAW Ptr

   Select Case wMsg
     Case %WM_NOTIFY
          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
                           If (@lpLvCd.nmcd.dwItemSpec Mod 2) = 0 Then
                               @lpLvCd.clrTextBk = %White
                               @lpLvCd.clrText = %Black
                           Else
                              @lpLvCd.clrTextBk = RGB(180,247,250)
                              @lpLvCd.clrText = %Black
                           End If
                           Function = %CDRF_NEWFONT
                      End Select
               
                End Select
   
           End If
           
   End Select
   
       
End Function
Title: Success!
Post by: Mark Strickland on October 06, 2005, 02:08:55 PM
Paul,

As ususal you come through!  The example works great.  Another "thing" for the "bag of tricks".

FF has been up to the task for this huge application.  The EXE is now 1.8 megs.  It will probably be at least 2.0 megs when it is done.  Multiple tabs, multi-level tabs, hundreds of controls, thousands of lines of PB code, and a Cheetah DB.

Mark
Title: One more cool trick
Post by: Mark Strickland on October 06, 2005, 03:36:27 PM
I added a variant to the sample code.

As written it flip/flops row colors based if the row is an odd or even number.  I wanted to color groups of rows so I added the FF_ListView_SetItemlParam function to store a flip/flop color flag with the row.  I fetch this value with the GetItem function and set the color based on that.

Now I have groups of lines with a shaded background and groups with a white background.  This works no matter how many members are in the group.

I could have gone even a bit farther and put the color value in the row param value and every row could have it's own color.

Thanks again for the help.
Title: Re: Success!
Post by: TechSupport on October 06, 2005, 05:18:30 PM
Quote from: Mark StricklandAs ususal you come through!  
My pleasure! I learned something new as well.

QuoteFF has been up to the task for this huge application.  The EXE is now 1.8 megs.  It will probably be at least 2.0 megs when it is done.  Multiple tabs, multi-level tabs, hundreds of controls, thousands of lines of PB code, and a Cheetah DB.
Hey, don't tell me... spread the word throughout the PB world.  :)

Seriously though, thanks!
Title: ListView Colors
Post by: Jean-Pierre LEROY on January 13, 2006, 07:14:16 PM
Hi,

Just try the sample code to change the color of a row in a listview; works fine.

But now I just need to change the color depending on the value of the first column of the row.

If the value is > 0 then I would like to write in green.
If the value if < 0 then I would like to write in red.

Any ideas how I can do that.

Thank you
Jean-Pierre.
Title: ListView Colors
Post by: TechSupport on January 14, 2006, 01:07:12 PM
Maybe try the following:

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 lpNmh  As NMHDR Ptr
   Local lpLvNm As NM_LISTVIEW Ptr
   Local lpLvCd As NMLVCUSTOMDRAW Ptr

   Select Case wMsg
     Case %WM_NOTIFY
          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
                           ' Determine the value at column 0. If it is less than zero then
                           ' use red, otherwise use green.
                           If Val( FF_ListView_GetItemText( @lpLvCd.nmcd.hdr.hWndFrom, @lpLvCd.nmcd.dwItemSpec, 0) ) < 0 Then
                               ' Use Red
                               @lpLvCd.clrTextBk = %Red
                               @lpLvCd.clrText = %Black
                           Else        
                               ' Use Green
                               @lpLvCd.clrTextBk = %Green
                               @lpLvCd.clrText = %Black
                           End If
                           Function = %CDRF_NEWFONT
                     
                      End Select
               
                End Select
 
           End If
         
   End Select
 
     
End Function
Title: ListView Colors
Post by: Jean-Pierre LEROY on January 15, 2006, 01:32:14 PM
Thank you Paul for your help; it works exactly as expected !

Jean-Pierre
Title: ListView Colors
Post by: gian young on January 17, 2006, 03:07:31 AM
I have been following this Topic with interest because of the opportunity to learn.

However can anyone assist:-

Where do the equates come from that are used in the above examples, for example Type NMLVCUSTOMDRAW ptr and constants like %NM_CUSTOMDRAW, plus other used here.

When I try to incorporate this code my system throws up its hands and says it doesn't know about these.

Using Win Xp, FireFly 2.5 and PB 8.01

Regards

Gian Young Australia
Title: ListView Colors
Post by: TechSupport on January 17, 2006, 09:30:22 AM
Hi Gian,

Those equates, etc, are in the "CommCtrl.inc" file that ships in the \winapi directory of your PowerBASIC installation.

If FireFly is having problems then you may want to uncheck the "Environment" option called "Dynamically create Commctrl.inc exclude equates"(it is located on the "Code Generation" branch in the "Environment Options" dialog).

Owner draw stuff can be a little difficult at first but once you have done it a couple of times it is pretty easy. It also opens up a lot of possibilities. I usually find good examples on the PB Forum. Also, make sure to read the Win32.hlp topics on the subject.