首页 > 其他 > 详细

控件自绘之CRadioListBox

时间:2015-02-26 16:07:23      阅读:379      评论:0      收藏:0      [点我收藏+]

源代码及可执行文件下载地址:http://files.cnblogs.com/rainboy2010/CRadioListBox.zip

技术分享

主要代码如下:

void CRadioListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
     CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
     if (lpDrawItemStruct->itemID == (UINT)-1)
     {
          if (lpDrawItemStruct->itemAction & ODA_FOCUS) pDC->DrawFocusRect(&lpDrawItemStruct->rcItem);
          return;
     }
     else
     {
          int selChange   = lpDrawItemStruct->itemAction & ODA_SELECT;
          int focusChange = lpDrawItemStruct->itemAction & ODA_FOCUS;
          int drawEntire  = lpDrawItemStruct->itemAction & ODA_DRAWENTIRE;

           BOOL sel = lpDrawItemStruct->itemState & ODS_SELECTED;

          if (selChange || drawEntire) 
          {
               CString strText;
               GetText(lpDrawItemStruct->itemID,strText);

              
               pDC->FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor((GetExStyle()&WS_EX_TRANSPARENT)?COLOR_BTNFACE:COLOR_WINDOW));

               // Draw radio button
               int h = lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top;
               CRect rect(lpDrawItemStruct->rcItem.left+2, lpDrawItemStruct->rcItem.top+2, 
                lpDrawItemStruct->rcItem.left+h-3, lpDrawItemStruct->rcItem.top+h-3);
               pDC->DrawFrameControl(&rect, DFC_BUTTON, DFCS_BUTTONRADIO | (sel?DFCS_CHECKED:0));

       
               pDC->SetTextColor(COLOR_WINDOWTEXT);
               pDC->SetBkMode(TRANSPARENT);
               lpDrawItemStruct->rcItem.left += h;

               pDC->DrawText(strText, &lpDrawItemStruct->rcItem, DT_LEFT|DT_VCENTER|DT_SINGLELINE);

            
          }

          if (focusChange  && lpDrawItemStruct->itemState & ODS_FOCUS && sel)
          {
              pDC->DrawFocusRect(&lpDrawItemStruct->rcItem);
          }
         
     }
}

 

控件自绘之CRadioListBox

原文:http://www.cnblogs.com/rainboy2010/p/4301236.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!