CListCtrl自绘或者设置相关的技术问题

本文探讨了在MFC中使用CListCtrl控件时如何进行自定义绘制,包括设置列表项的颜色、样式,以及处理控件的通知消息以实现报告视图的定制。同时,详细介绍了涉及的结构体和过程,帮助开发者更好地理解和应用CListCtrl高级功能。
摘要由CSDN通过智能技术生成

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)
{
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值