The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: The Dude of Dudes on February 19, 2005, 11:02:25 PM

Title: ListView SubItems
Post by: The Dude of Dudes on February 19, 2005, 11:02:25 PM
I am trying to change text color of 1 Subitem in a report style ListView. My initialization code:

mov cmctlex.dwSize, sizeof cmctlex
mov cmctlex.dwICC, ICC_LISTVIEW_CLASSES
invoke InitCommonControlsEx, addr cmctlex


WinProc code:

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WinProc proc, hWnd: dword, uMsg: dword, wParam: dword, lParam: dword
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


.if uMsg == WM_NOTIFY
  mov ecx, lParam
  assume ecx: ptr NMLVCUSTOMDRAW
.if [ecx].nmcd.hdr.code == NM_CUSTOMDRAW
 
    .if [ecx].nmcd.dwDrawStage == CDDS_PREPAINT
       mov eax, CDRF_NOTIFYSUBITEMDRAW
       ret

    .elseif [ecx].nmcd.dwDrawStage == ( CDDS_ITEMPREPAINT or CDDS_SUBITEM)
.if ([ecx].nmcd.dwItemSpec == 0) && ([ecx].iSubItem == 1)
invoke Beep, 1000, 500
;Item Zero Subitem 1 is being drawn
.endif
    .endif
.endif
.endif

assume ecx: nothing



The Beep is there just to see if the  CDDS_SUBITEM code is ever processed, but it never is. What am I doing wrong?  :(
Title: Re: ListView SubItems
Post by: The Dude of Dudes on February 20, 2005, 06:39:53 AM
AHA! Problem solved:

.elseif uMsg == WM_NOTIFY
  mov ecx, lParam
  assume ecx: ptr NMLVCUSTOMDRAW
.if [ecx].nmcd.hdr.code == NM_CUSTOMDRAW
 
    .if [ecx].nmcd.dwDrawStage == CDDS_PREPAINT
       mov eax, CDRF_NOTIFYITEMDRAW
       ret

    .elseif [ecx].nmcd.dwDrawStage == CDDS_ITEMPREPAINT
mov eax, CDRF_NOTIFYSUBITEMDRAW
ret
    .elseif [ecx].nmcd.dwDrawStage == CDDS_SUBITEM or CDDS_ITEMPREPAINT
.if ([ecx].nmcd.dwItemSpec == 0) && ([ecx].iSubItem == 2)
invoke Beep, 1000, 500
;Item Zero Subitem 1 is being drawn
.endif
    .endif
.endif


assume ecx: nothing

.endif
Title: Re: ListView SubItems
Post by: donkey on February 20, 2005, 04:27:09 PM
It is fairly easy to change the drawing aspects of a listview. You can download my listview example from my website to take a look at how I handled the custom draw notification, it might help a bit.

http://donkey.visualassembler.com/files/TestListView.zip
Title: Re: ListView SubItems
Post by: The Dude of Dudes on February 20, 2005, 09:22:22 PM
Thanx for the example Donkey. It's interesting how you changed the background color of the text through the DC.  :U I had troubles highlighting isolated subitems.  Apparently you need to return CDRF_NOTIFYSUBITEMDRAW in response to the CDDS_ITEMPREPAINT message to be notified before each subitem is drawn. At first I was returning CDRF_NOTIFYSUBITEMDRAW in response to CDDS_PREPAINT. I missed the extra step. Works great now. I change the background color by setting the NMLVCUSTOMDRAW.clrTextBk with a COLORREF value and returning CDRF_NEWFONT. I might try using the DC instead, like in your example.