Q | a question about CListCtrl - waiting on line ... |
T | 怎样将 CListCtrl 中的一行( one item)的背景或 Text Color 设为其它 color ? |
A | Using Custom Draw The following code fragment is a portion of a WM_NOTIFY handler that illustrates how to handle custom draw notifications sent to a list-view control: Hide Example LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam; switch (pnm->hdr.code){ ... case NM_CUSTOMDRAW: LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; switch(lplvcd->nmcd.dwDrawStage) { case CDDS_PREPAINT : return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: SelectObject(lplvcd->nmcd.hdc, GetFontForItem(lplvcd->nmcd.dwItemSpec, lplvcd->nmcd.lItemlParam) ); lplvcd->clrText = GetColorForItem(lplvcd->nmcd.dwItemSpec, lplvcd->nmcd.lItemlParam); lplvcd->clrTextBk = GetBkColorForItem(lplvcd->nmcd.dwItemSpec, lplvcd->nmcd.lItemlParam); /* At this point, you can change the background colors for the item and any subitems and return CDRF_NEWFONT. If the list-view control is in report mode, you can simply return CDRF_NOTIFYSUBITEMREDRAW to customize the item's subitems individually */ ... return CDRF_NEWFONT; // or return CDRF_NOTIFYSUBITEMREDRAW; case CDDS_SUBITEM | CDDS_ITEMPREPAINT: SelectObject(lplvcd->nmcd.hdc, GetFontForSubItem(lplvcd->nmcd.dwItemSpec, lplvcd->nmcd.lItemlParam, lplvcd->iSubItem)); lplvcd->clrText = GetColorForSubItem(lplvcd->nmcd.dwItemSpec, lplvcd->nmcd.lItemlParam, lplvcd->iSubItem)); lplvcd->clrTextBk = GetBkColorForSubItem(lplvcd->nmcd.dwItemSpec, lplvcd->nmcd.lItemlParam, lplvcd->iSubItem)); /* This notification is received only if you are in report mode and returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. At this point, you can change the background colors for the subitem and return CDRF_NEWFONT.*/ ... return CDRF_NEWFONT; } ... } |
Q | 请问怎样在clistctrl里显示jpeg图片的缩略图呢 |
T | 谢谢 |
A | BEGIN_MESSAGE_MAP(CImagePage, CPropertyPage) //{ {AFX_MSG_MAP(CImagePage) ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST_PREVIEW, OnCustomDraw) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CImagePage::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here LPNMLVCUSTOMDRAW pnmCustDraw = (LPNMLVCUSTOMDRAW)pNMHDR; switch(pnmCustDraw->nmcd.dwDrawStage){ case CDDS_PREPAINT: *pResult = CDRF_NOTIFYITEMDRAW ;break; case CDDS_ITEMPREPAINT: *pResult = CDRF_NOTIFYPOSTPAINT ;break; case CDDS_ITEMPOSTPAINT:{ int iItem=pnmCustDraw->nmcd.dwItemSpec; CDC dc; dc.Attach(pnmCustDraw->nmcd.hdc); HICON hi=GetIconFromFile(m_strImageFile,iItem); m_pic.CreateFromIcon(hi);DestroyIcon(hi); CRect rectDest; //call CListCtrl::GetItemRect to get target rect m_wndImgPrvwList.GetItemRect(iItem,rectDest,LVIR_ICON); dc.DPtoLP(rectDest); m_pic.Render(&dc,&rectDest); dc.Detach(); *pResult = CDRF_DODEFAULT; break; } default: *pResult = CDRF_DODEFAULT; break; } } 显示图标的……改改就行…… |
Q | 有兴趣者请进:如何改变CListCtrl或其它控件的滚动条的颜色? |
T | 哪位大侠知道:在程序中如何改变CListCtrl或其它控件的滚动条的颜色(前景、背景)? |
A | 按理来说在窗口过程中处理WM_CTLCOLORSCROLLBAR就可以了……滚动条会往父窗口发这个消息…… Subclass滚动条,在派生类里面自画/处理WM_CTLCOLORSCROLLBAR也应该可以…… _AfxGrayBackgroundWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { |