自绘列表框控件显示略缩图----再稍微改进点点。。
生活随笔
收集整理的這篇文章主要介紹了
自绘列表框控件显示略缩图----再稍微改进点点。。
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?原先貼在QQ空間,汗!!
http://user.qzone.qq.com/382164370/infocenter#!app=2&pos=1334911186
http://user.qzone.qq.com/382164370/infocenter#!app=2&pos=1334840523
每天思考一點(diǎn)無聊的問題,又是接上一篇日記的列表框自繪,在上一個(gè)自繪里面圖片是用WINDOWS自己畫上去的,這次徹底的全部的自己繪制(包括文字),這樣做的好處是圖片上不會(huì)覆蓋一層陰影影響美觀,改動(dòng)是下面的紅色顯示的代碼片段,有一個(gè)問題不知道為什么,就是下面這句
GetSubItemRect(nItem, nSubItem, LVIR_ICON, rect);
得到的矩形rect的寬度總是比圖片寬度大42像素(列表框在ICO模式時(shí)),why?
?
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?
只是在前面的基礎(chǔ)上修改這兩個(gè)函數(shù)。。。 /// //?OnNMCustomdraw void CListImageCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) { //LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR); NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
//TRACE("CListImageCtrl::OnNMCustomdraw()"); // 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. int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec); int nSubItem = pLVCD->iSubItem; CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc); CRect rect; GetSubItemRect(nItem, nSubItem, LVIR_ICON, rect);
XLISTCTRLDATA *pXLCD = (XLISTCTRLDATA *) pLVCD->nmcd.lItemlParam; ASSERT(pXLCD);
COLORREF crText ?= m_crWindowText; COLORREF crBkgnd = m_crWindow;
if (pXLCD) { crText ?= pXLCD[nSubItem].crText; crBkgnd = pXLCD[nSubItem].crBackground;
if (!pXLCD[0].bEnabled) crText = m_crGrayText; }
// store the colors back in the NMLVCUSTOMDRAW struct pLVCD->clrText = crText; pLVCD->clrTextBk = crBkgnd;
//draw image, rect.left += 19; rect.right -= 19; DrawImage(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
//draw checkbox if (pXLCD && (pXLCD[nSubItem].nCheckedState != -1)) DrawCheckbox(nItem, nSubItem, pDC, crText, crBkgnd, rect,pXLCD); //draw text GetSubItemRect(nItem, nSubItem, LVIR_LABEL, rect);
DrawText(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
*pResult = CDRF_SKIPDEFAULT; ? //we have done all the paint
} ?else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM)) ?{
?*pResult = CDRF_DODEFAULT; ?}
}
/// // DrawImage int CListImageCtrl::DrawImage(int nItem, ?int nSubItem, ?CDC* pDC, ?COLORREF crText, ?COLORREF crBkgnd, ?CRect rect, ?XLISTCTRLDATA *pXLCD) { if (rect.IsRectEmpty()) { return 0; }
GetDrawColors(nItem, nSubItem, crText, crBkgnd);
CBrush bkBrush(crBkgnd); CRgn rgn; rgn.CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom); pDC->FrameRgn(&rgn,&bkBrush,2,2); ? ? //draw my border
int nGap = 0; rect.left += 0; ?
CImageList* pImageList = GetImageList(LVSIL_SMALL); if (pImageList) { SIZE sizeImage; sizeImage.cx = sizeImage.cy = 0; IMAGEINFO info;
int nImage = -1; if (pXLCD) nImage = pXLCD[nSubItem].nImage;
if (nImage == -1) return 0;
if (pImageList->GetImageInfo(nImage, &info)) { sizeImage.cx = info.rcImage.right - info.rcImage.left; sizeImage.cy = info.rcImage.bottom - info.rcImage.top; }
if (nImage >= 0) { if (rect.Width() > 0) { POINT point;
point.y = rect.CenterPoint().y - (sizeImage.cy >> 1); point.x = rect.CenterPoint().x - (sizeImage.cx >> 1);
SIZE size; size.cx = rect.Width() < sizeImage.cx ? rect.Width() : sizeImage.cx; size.cy = rect.Height() < sizeImage.cy ? rect.Height() : sizeImage.cy;
// save image list background color COLORREF rgb = pImageList->GetBkColor();
// set image list background color pImageList->SetBkColor(crBkgnd); pImageList->DrawIndirect(pDC, nImage, point, size, CPoint(0, 0)); pImageList->SetBkColor(rgb);
nGap = sizeImage.cx + 5; ? } } }
return nGap; }
總結(jié)
以上是生活随笔為你收集整理的自绘列表框控件显示略缩图----再稍微改进点点。。的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 天地图服务地址
- 下一篇: test libvirt