CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Location
    Somewhere over the rainbow
    Posts
    423

    argh, what is wrong?!

    what the heck is wrong with it??!!??! it drives me crazy!

    Code:
    case WM_NOTIFY:
    {
        switch(LOWORD(wParam))
        {
             case IDC_LIST: 
             {
                  if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
                  {
                     NMLVCUSTOMDRAW *cdraw = (NMLVCUSTOMDRAW*)lParam;
                            
                     if (cdraw->nmcd.dwDrawStage == CDDS_PREPAINT)
                         return CDRF_NOTIFYITEMDRAW;
    
                     if (cdraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT || cdraw->nmcd.dwDrawStage == CDDS_SUBITEM)
                     {      
                        COLORREF crText;
                                
                         if ( cdraw->iSubItem==2 )
                              crText = RGB(255,0,0);
                         else if ( cdraw->iSubItem==1 )
                              crText = RGB(0,255,0);
                         else
                              crText = RGB(128,128,255);
                                
                         cdraw->clrText = crText;
                                
                         return CDRF_DODEFAULT;
                     }
                            
                  }
    		}
    	}	
    }
    the message never arrives if (cdraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT || cdraw->nmcd.dwDrawStage == CDDS_SUBITEM)

    i have seen other src codes and it all works well there (MFC apps !@!@#!@)

    do i need to set my listView to have some style or something?
    Bengi

  2. #2
    Join Date
    May 2002
    Location
    Somewhere over the rainbow
    Posts
    423
    yesssssssssssss i got it to work!!
    finally a good Pure API code that actually works,
    i found it deep inside msdn!

    this is what we need to do in the WM_NOTIFY:
    Code:
    if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
    {
         SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam));
        return TRUE;
    }
    and let the result function to be:

    Code:
    LRESULT ProcessCustomDraw (LPARAM lParam)
    {
        LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
    
        switch(lplvcd->nmcd.dwDrawStage) 
        {
            case CDDS_PREPAINT : //Before the paint cycle begins
                //request notifications for individual listview items
                return CDRF_NOTIFYITEMDRAW;
                
            case CDDS_ITEMPREPAINT: //Before an item is drawn
                if (iSelect == (int)lplvcd->nmcd.dwItemSpec)
                {
                    //customize item appearance
                    lplvcd->clrText   = RGB(255,255,255);
                    lplvcd->clrTextBk = RGB(0,0,255);
    
                    //To set a custom font:
                    //SelectObject(lplvcd->nmcd.hdc, <your custom HFONT>);
    
                    return CDRF_NEWFONT;
                }
                break;
        
            case CDDS_SUBITEM | CDDS_ITEMPREPAINT: //Before a subitem is drawn
                if (iSelect == (int)lplvcd->nmcd.dwItemSpec)
                {
                    if (0 == lplvcd->iSubItem)
                    {
                        //customize subitem appearance for column 0
                        lplvcd->clrText   = RGB(255,255,255);
                        lplvcd->clrTextBk = RGB(255,0,0);
    
                        //To set a custom font:
                        //SelectObject(lplvcd->nmcd.hdc, <your custom HFONT>);
    
                        return CDRF_NEWFONT;
                    }
                    else if (1 == lplvcd->iSubItem)
                    {
                        //customize subitem appearance for columns 1..n
                        //Note: setting for column i carries over to columnn i+1 unless
                        //      it is explicitly reset
                        lplvcd->clrTextBk = RGB(0,255,0);
    
                        return CDRF_NEWFONT;
                    }
                }
        }
        return CDRF_DODEFAULT;
    }
    now we can play with Colors!!! finally gotcha !@#@!#!@#!@
    Last edited by Bengi; March 20th, 2003 at 01:05 AM.
    Bengi

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