正文

Custom Draw ListView Controls(4)2009-01-20 11:43:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/yuqiexing/40621.html

分享到:

  case CDDS_ITEMPOSTPAINT:

  {

   // Item PostPaint

   // restore old font if any

   if (m_pOldItemFont) {

    if (! pDC) pDC = CDC::FromHandle(hdc);

    pDC->SelectObject(m_pOldItemFont);

    m_pOldItemFont = NULL;

   }

 

   // do we want to do any extra drawing?

   if (IsItemPostDraw()) {

    if (! pDC) pDC = CDC::FromHandle(hdc);

     OnItemPostDraw(pDC,nItem,nState,lParam);

   }

  }

  break;

 

  case CDDS_POSTPAINT:

  {

   // Item PostPaint

   // do we want to do any extra drawing?

   if (IsPostDraw()) {

    if (! pDC) pDC = CDC::FromHandle(hdc);

     CRect r(pNMLVCUSTOMDRAW->nmcd.rc);

 

    OnPostDraw(pDC,r);

   }

  }

  break;

 }

 

 ASSERT(CDRF_DODEFAULT==0);

 *pResult = 0;

 if (bNotifyPostPaint) {

  *pResult |= CDRF_NOTIFYPOSTPAINT;

 }

 

 if (bNotifyItemDraw) {

  *pResult |= CDRF_NOTIFYITEMDRAW;

 }

 

 if (bNotifySubItemDraw) {

  *pResult |= CDRF_NOTIFYSUBITEMDRAW;

 }

 

 if (bNewFont) {

  *pResult |= CDRF_NEWFONT;

 }

 

 if (bSkipDefault) {

  *pResult |= CDRF_SKIPDEFAULT;

 }

 

 if (*pResult == 0) {

  // redundant as CDRF_DODEFAULT==0 anyway

  // but shouldn't depend on this in our code

  *pResult = CDRF_DODEFAULT;

 }

}


Phew! That's a fair bit of code. The good news? There's less code left for us to write when we derive from CListCtrlWithCustomDraw.

 

To make this work, those virtual functions need to be defined. The defaults for these functions are to do nothing; so using the CListCtrlWithCustomDraw on its own will work the same as a standard list control. It is only when you derive from this class and override some of the virtual functions that the ListView control changes appearance. If you do not override them, then you get the standard behaviour.

To start with, here are the additions to the class declaration for CListCtrlWithCustomDraw:

 

阅读(1769) | 评论(1)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册