CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    3

    Custom drawn ListView- can't receive CDRF_NOTIFYITEMDRAW

    I'm custom-drawing a listview control, but while I can receive the CDDS_PREPAINT message, the CDDS_ITEMPREPAINT never comes. I've searched around and tried various things, but to no avail.

    Here is the WM_NOTIFY message:
    Code:
    DWORD result; //global variable
    
    ...
    
    case WM_NOTIFY:
    if(((LPNMHDR)lp)->code==NM_CUSTOMDRAW && ((LPNMHDR)lp)->idFrom == 5467)
    {
    				
                LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lp;
    	switch(lplvcd->nmcd.dwDrawStage)
    	{
    		case CDDS_PREPAINT: //this message is processed fine
    			result = CDRF_NOTIFYITEMDRAW;
    			break;
    		case CDDS_ITEMPREPAINT: //I never receive this one
    		{
    			int iRow = lplvcd->nmcd.dwItemSpec;
    			if(iRow & 1)
    			{
    				lplvcd->clrTextBk = RGB(255, 34, 100);
    				lplvcd->clrText = RGB(255, 22, 2);
    				result = CDRF_NEWFONT;
    			}
    		             result = CDRF_DODEFAULT;
    		}
    		break;
    		default:
    	                       result = CDRF_DODEFAULT;
    	}
                 return result;
    }
    What could be the reason for this? Thanks for any help.
    Last edited by lunaroverlord; January 10th, 2009 at 09:12 PM.

  2. #2
    Join Date
    Dec 2008
    Posts
    114

    Re: Custom drawn ListView- can't receive CDRF_NOTIFYITEMDRAW

    It's a Win32 FAQ (famous since 1995...)
    (see news://comp.os.ms-windows.programmer.win32)

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Custom drawn ListView- can't receive CDRF_NOTIFYITEMDRAW

    Did you try CDRF_NOTIFYSUBITEMDRAW?
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Nov 2008
    Posts
    3

    Re: Custom drawn ListView- can't receive CDRF_NOTIFYITEMDRAW

    Thanks for the responses, but it still doesn't work.

    I tried with CDRF_NOTIFYSUBITEMDRAW, nothing. The only value that ever comes to lplvcd->nmcd.dwDrawStage is 1 (CDDS_PREPAINT), checked that in debugger. Strange, is the code not correct? Why wouldn't it notify me with the CDDS_ITEMPREPAINT message when I'm returning CDRF_NOTIFYITEMDRAW?

    EDIT:
    Maybe the problem's somehow related to that my ListView is not in a dialog, but in the main window?
    This was the original example I borrowed my code from:
    Code:
    if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
    {
       SetWindowLong(hWnd, DWL_MSGRESULT, 
            (LONG)ProcessCustomDraw(lParam));
       return TRUE;
    }
    Here it's used in dialog, but my ListView is a child of the main window, so I'm just returning the value to WndProc. (ProcessCustomDraw is the processing code)
    Last edited by lunaroverlord; January 12th, 2009 at 08:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured