15,979
社区成员
发帖
与我相关
我的任务
分享
void CIconComBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC *pDC = CDC::FromHandle(lpDIS->hDC);
CString szItemText;
HICON hiItemIcon = NULL;
CRect rcItem = lpDIS->rcItem;
TEXTMETRIC TextMetric;
pDC->GetTextMetrics(&TextMetric);
if(lpDIS->itemID != -1)
{
GetLBText(lpDIS->itemID,szItemText);
hiItemIcon = (HICON)lpDIS->itemData;
}
else szItemText = "select!";
//selected state
if((lpDIS->itemState & ODS_SELECTED)&& (lpDIS->itemAction&(ODA_SELECT | ODA_DRAWENTIRE)))
{
aniHeight = TextMetric.tmHeight;
anihIcon = hiItemIcon;
aniRc = rcItem;
aniText = szItemText;
pPaintDC = CDC::FromHandle(lpDIS->hDC);
DrawSelectItem(pPaintDC,aniRc,anihIcon,aniText,aniHeight);
}
// normal
else if(lpDIS->itemAction &(ODA_SELECT | ODA_DRAWENTIRE))
{
pDC->FillSolidRect(rcItem,::GetSysColor(COLOR_WINDOW));
pDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
pDC->TextOut(rcItem.left + SIZE_ICON + 1 ,rcItem.top + (SIZE_ICON + 2 - TextMetric.tmHeight)/2,szItemText);
if(hiItemIcon)
{
DrawIconEx(pDC->GetSafeHdc(),rcItem.left,rcItem.top + 2,hiItemIcon,SIZE_ICON,SIZE_ICON,NULL,(HBRUSH)NULL,DI_NORMAL);
}
}
if(lpDIS->itemState & ODA_FOCUS)
{
pDC->DrawFocusRect(rcItem);
}
}
int CIconComBox::InsertItem(int nIndex, HICON ItemIcon,const CString szItemText)
{
int n = CComboBox::InsertString(nIndex,szItemText);
if(n != CB_ERR && n != CB_ERRSPACE)
{
SetItemData(n,(DWORD)ItemIcon);
}
return n;
}