The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ossama on December 17, 2007, 11:10:47 AM

Title: List View multi-color
Post by: ossama on December 17, 2007, 11:10:47 AM
hello  :bg
how can i make a listview (in the details view) with diffrent background colors in each line ?
ie, for example the first line has the backround color ==RED,the second line with background color ==BLUE,and so on...


the same question but columns in place of lines,

thank you in advance  :U
Title: Re: List View multi-color
Post by: Jackal on December 17, 2007, 01:34:39 PM
this will do it but you will need to play with the hex numbers to get your colors..



    cmp uMsg, WM_NOTIFY
    jne @F
      push edi
      mov edi,lParam
      assume edi:ptr NMHDR
      mov eax,[edi].hwndFrom
      .if eax==hList   
        .if [edi].code == NM_CUSTOMDRAW
          mov ecx,edi
          ASSUME ecx:ptr NMLVCUSTOMDRAW
          .if [ecx].nmcd.dwDrawStage == CDDS_PREPAINT
            mov eax,CDRF_NOTIFYITEMDRAW
            ret
          .elseif [ecx].nmcd.dwDrawStage == CDDS_ITEMPREPAINT
            mov eax, [ecx].nmcd.dwItemSpec
            and eax, 1
            dec eax
            and eax, (00C5C5C5h - 00D6D8D3h)
            add eax, 00787878h
            mov [ecx].clrTextBk, eax
            mov eax, CDRF_NEWFONT
            ret
            ASSUME ecx:nothing
          .endif
        .endif
      .endif
      pop edi
Title: Re: List View multi-color
Post by: ossama on December 17, 2007, 01:37:02 PM
Jackal ,thank you for the help :U
Title: Re: List View multi-color
Post by: ossama on January 01, 2008, 04:37:59 PM
hi Jackal,
your code can change the color of items,but how to change the color of a specific column?or is it possible?
Title: Re: List View multi-color
Post by: donkey on January 01, 2008, 09:14:18 PM
I have not looked at his code but when drawing the text into the listview you have to have the bounding rect of each column so you can paint individual backgrounds then. The attached example paints the columns separate colors when a line is selected...

Note that this is written for RadASM and in GoAsm syntax, you will need my headers to compile it, they are available from my website. Don't bother asking to translate it, I don't have MASM available nor am I likely to download it.

Donkey

[attachment deleted by admin]
Title: Re: List View multi-color
Post by: Jackal on January 01, 2008, 11:54:01 PM
i understood the question as being the way he gave an example of.
Title: Re: List View multi-color
Post by: donkey on January 02, 2008, 12:16:03 AM
Quote from: Jackal on January 01, 2008, 11:54:01 PM
i understood the question as being the way he gave an example of.

Hi Jackal,

No problem with your code at all, the question wasn't clear. I just modified an old listview example I did a few years back to paint the columns separately.

Edgar
Title: Re: List View multi-color
Post by: Jupiter on January 02, 2008, 03:24:01 PM
Article at CodeProject: Neat Stuff to Do in List Controls Using Custom Draw (http://www.codeproject.com/KB/combobox/lvcustomdraw.aspx)
Title: Re: List View multi-color
Post by: ragdog on January 04, 2008, 01:14:57 PM
hi

i have problems with draw color to my listview i uses Jackal source
can your help me please

greets
ragdog

[attachment deleted by admin]
Title: Re: List View multi-color
Post by: Jackal on January 04, 2008, 06:29:38 PM
I dont believe you are ever getting the message CDDS_ITEMPREPAINT. It does get CDDS_PREPAINT however and works down to that point.
Title: Re: List View multi-color
Post by: ragdog on January 05, 2008, 11:15:08 AM
   
I have been to this forum to ask for a color listview I do not in my app
I have something in the resource change?

http://www.masm32.com/board/index.php?action=dlattach;topic=7858.0;id=4151

ragdog

[attachment deleted by admin]
Title: Re: List View multi-color
Post by: ossama on January 06, 2008, 01:14:42 PM
the code of donky shows multi colors of columns , yes , but is is colored only when selecting an item,what i need is how to show items (and sub items) with different colors always (not when selected only)
thank you
Title: Re: List View multi-color
Post by: Jackal on January 06, 2008, 03:44:13 PM
@ragdog.
  I am not sure if its something in the resource or if its something with using a dialog. I myself do not use dialogs for my windows. I use the createwindowex api.

@ossama
  Following the link that jupiter posted there is an example that shows what it is you want. If are able to translate the code then it will work fine. If not then maybe when i get the time i will sit down and do it.
Title: Re: List View multi-color
Post by: ossama on January 06, 2008, 04:23:02 PM
QuoteIf not then maybe when i get the time i will sit down and do it
thank you for help  :U
Title: Re: List View multi-color
Post by: ossama on January 06, 2008, 04:32:27 PM
Quote from: Jupiter on January 02, 2008, 03:24:01 PM
Article at CodeProject: Neat Stuff to Do in List Controls Using Custom Draw (http://www.codeproject.com/KB/combobox/lvcustomdraw.aspx)
yes this is what i want,i will look in the source code and try to translate what i need to masm, i will post an example in masm later,
thank you Jupiter, and Jakal and all of you who had tried to help
REGARDS OSSAMA
Title: Re: List View multi-color
Post by: ossama on January 08, 2008, 04:26:36 PM
hi ragdog,
i had read the topic that jupiter posted here, and i it may help you .if you cant translate the code to masm i will try to do it for you
regards OSSAMA
Title: Re: List View multi-color
Post by: ossama on January 08, 2008, 05:48:33 PM
thank you jupiter for the URL  :U
codeproject.com is very good place for win32 programming
Title: Re: List View multi-color
Post by: Jupiter on January 09, 2008, 10:41:59 AM
ossama

glad that I helped you ;)

(at CodeProject) there are many good articles in many categories!

btw, there is no need to convert C code (sometimes), coz you can create .lib and use it with masm