|
|
如何?得ListCtrl的ImageList的其中一??icon小?D
CSortListCtrl?槔^承CListCtrl的??e,已?有SetImageList?了
我想?出image_list?面其中一??小?D(icon) in CSortListCtrl::OnCustomDraw
void CSortListCtrl: rawText(int nItem, int nSubItem, CDC *pDC, COLORREF crText, COLORREF crBkgnd, CRect &rect)
{
ASSERT(pDC);
// GetDrawColors(nItem, nSubItem, crText, crBkgnd);
pDC->FillSolidRect(&rect, crBkgnd);
CString str;
str = GetItemText(nItem, nSubItem);
if (!str.IsEmpty())
{
// get text justification
HDITEM hditem;
hditem.mask = HDI_FORMAT;
m_ctlHeader.GetItem(nSubItem, &hditem);
int nFmt = hditem.fmt & HDF_JUSTIFYMASK;
UINT nFormat = DT_VCENTER | DT_SINGLELINE;
if (nFmt == HDF_CENTER)
nFormat |= DT_CENTER;
else if (nFmt == HDF_LEFT)
nFormat |= DT_LEFT;
else
nFormat |= DT_RIGHT;
rect.OffsetRect(20,0);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(crText);
pDC->SetBkColor(crBkgnd);
pDC->DrawText(str, &rect, nFormat);
//icon
rect.OffsetRect(-20,0);
#define _TEST_ICON_IMAGE_
#ifdef _TEST_ICON_IMAGE_
CImageList* image_list;
CDC* mdc;
CBitmap *bitmap;
image_list=GetImageList(LVSIL_SMALL);
IMAGEINFO ImageInfo;
image_list->GetImageInfo(0,&ImageInfo);
mdc=new CDC;
bitmap = new CBitmap;
mdc->CreateCompatibleDC(pDC);
bitmap->m_hObject=ImageInfo.hbmImage;
//bitmap->m_hObject = (HBITMAP): oadImage(::AfxGetInstanceHandle() ,"DiaIc1on.bmp",IMAGE_BITMAP,15,15,LR_LOADFROMFILE);
mdc->SelectObject(bitmap);
BOOL aa=pDC->BitBlt(rect.left,rect.top,rect.left+15,rect.top+15,mdc,0,0,SRCCOPY);
TRACE("");
#endif//_TEST_ICON_IMAGE_
}
}
void CSortListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
//draw each item.set txt color,bkcolor....
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
// Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT;
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if (pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
{
// This is the prepaint stage for a subitem. Here's where we set the
// item's text and background colors. Our return value will tell
// Windows to draw the subitem itself, but it will use the new colors
// we set here.
int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
int nSubItem = pLVCD->iSubItem;
ItemData *pXLCD = (ItemData *) pLVCD->nmcd.lItemlParam;
ASSERT(pXLCD);
COLORREF crText = crWindowText;
COLORREF crBkgnd = crWindow;
if (pXLCD){
crText = (pXLCD->crText)[nSubItem];
crBkgnd = (pXLCD->crBak)[nSubItem];
}
// store the colors back in the NMLVCUSTOMDRAW struct
pLVCD->clrText = crText;
pLVCD->clrTextBk = crBkgnd;
CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
CRect rect;
GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect);
if (GetItemState(nItem, LVIS_SELECTED))
DrawText(nItem, nSubItem, pDC, crHighLightText, crHighLight , rect);
else
DrawText(nItem, nSubItem, pDC, crText, crBkgnd, rect);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
}
|
|