News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

LISTBOX - how to write lines in different colors

Started by BrunoFabbri, December 05, 2011, 11:38:36 AM

Previous topic - Next topic

BrunoFabbri

I wish to write lines in a LISTBOX using different colors for the text.
I have tried for long time but I have not found the solution.
I use Platform SDK and MASM.

dedndave

the forum search tool is your friend
i seem to recall a fairly recent thread on this subject with a code example   :U

BrunoFabbri

Before writing here I have made several search with Google and inside MASM forum. In MASM there is an example that uses WM_CTLCOLORLISTBOX. This is good in order to change ALL the rows of the LIST BOX. My problem is in changing only few rows of the listbox. That is, for example, I wish to write 3 rows in black, then 1 row in yellow, and finally return to write in black.

With Google I found many replies to my problem but in my program they does'nt function.


BrunoFabbri

jj2007

I think it is the correct way to solve the problem. I made a proof unsuccessfully but next days I will retry.
Thank you  :U

Ho visto la tua immagine dell'Italia. Sono italiano. ciao


BrunoFabbri

I confirm that the correct solution of the problem is that linked for me by JJ2007, that is:
http://www.masm32.com/board/index.php?topic=5879.0

I write my istructions:
in the resource file it is important to write LBS_OWNERDRAWFIXED | LBS_HASSTRINGS in the definition of LISTBOX;

then in the parent's window procedure:

in WM_INITDIALOG you fill the LISTBOX using ADDSTRING

and then you must insert lines like this in order to modify colors:

.ELSEIF uMsg == WM_DRAWITEM
;
      MOV   EAX,lParam
      MOV   pointstrubox,EAX
      copiarm pointstrubox,strulistbox,SIZEOF strulistbox
      CMP   strulistbox.itemID,-1
      JE   fatto2
      CMP   strulistbox.itemAction,ODA_DRAWENTIRE
      JE   faredraw
      CMP   strulistbox.itemAction,ODA_SELECT
      JNE   fatto2
   faredraw:
      MOV   EAX,strulistbox.hdc
      MOV   hdcbox2,EAX
      MOV   EAX,strulistbox.itemID
      MOV   rigabox,EAX
      invoke   SendMessage,hcam500,LB_GETTEXT,rigabox,pointstring2
      MOV   lungtesto2,EAX
      CMP   rigabox,7
      JE   altrocolore
      CMP   rigabox,11
      JNE   mettigiallo
altrocolore:
      invoke   SetTextColor,hdcbox2,coloreverde
      JMP   dopocolo
mettigiallo:
      invoke   SetTextColor,hdcbox2,coloregiallo
dopocolo:
      invoke   SendMessage,hcam500,LB_GETITEMRECT,rigabox,pointrect2
      invoke   DrawText,hdcbox2,pointstring2,lungtesto2,pointrect2,DT_LEFT
      invoke   SendMessage,hcam500,LB_SETITEMDATA,rigabox,pointstring2
      JMP   fatto2
;
fatto2:
        mov eax,TRUE
        ret

-----------------------------------------

Thanks for all, especially for JJ2007