码迷,mamicode.com
首页 > 其他好文 > 详细

控件自绘之CRadioListBox

时间:2015-02-26 16:08:34      阅读:275      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!