How to create a user defined listbox control in VC++ ?

Key Words: VC++, SubClass , Control
 
NoteThe VC++ project GuanRuiPaint make a big progress,  all UI related tasks have been done already !
   
CDC * pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
 
int nWidth= lpDrawItemStruct->itemData;
 
int nStype= lpDrawItemStruct->itemData;
 
if(m_nParamIndex==PEN_STYLE)
  nWidth
=1;
 CPen pen;
 COLORREF crLine
=RGB(255,0,0);
 
int nCenterPos=(CRect(lpDrawItemStruct->rcItem).Height()-
     nWidth)
/2+CRect(lpDrawItemStruct->rcItem).TopLeft().y;
 
if (lpDrawItemStruct->itemAction & ODA_DRAWENTIRE) 
 {
  crLine
=RGB(0,0,0);
  CBrush br(GetSysColor(COLOR_BTNFACE));
  pDC
->FillRect(&lpDrawItemStruct->rcItem,&br);
 }
 
if ((!(lpDrawItemStruct->itemState & ODS_SELECTED)) &&
  (lpDrawItemStruct
->itemAction & (ODA_SELECT)))
 { 
  crLine
=RGB(0,0,0);
  CBrush br(GetSysColor(COLOR_BTNFACE));
  
//CBrush br(RGB(128,0,0));
  pDC
->FillRect(&lpDrawItemStruct->rcItem,&br);
 }
 
if ((!(lpDrawItemStruct->itemState & ODS_SELECTED)) &&
  (lpDrawItemStruct
->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
 { 
  crLine
=RGB(255,0,0);
  CBrush br(RGB(
0,0,255));
  pDC
->FillRect(&lpDrawItemStruct->rcItem,&br);

  pen
.CreatePen(PS_SOLID,1,crLine);
  CPen 
*pOldPen=pDC->SelectObject(&pen);
  pDC
->MoveTo(5,nCenterPos);
  pDC
->LineTo(CRect(lpDrawItemStruct->rcItem).Width()-5,nCenterPos);
  pDC
->SelectObject(pOldPen)->DeleteObject();
 }
posted @ 2007-08-07 10:51  RayG  阅读(520)  评论(2编辑  收藏  举报