列表视图SDK怎么设置单元颜色。  我知道要用一些消息
NM_CUSTOMDRAW
CDDS_ITEMPREPAINT这些消息 还有一些结构 至于怎么做 
请高人详细说一下

解决方案 »

  1.   

    做法是:响应NM_CUSTOMDRAW通知,判断NMCUSTOMDRAW结构(lParam是结构指针)中dwDrawStage的值,当值为CDDS_PREPAINT时返回CDRF_NOTIFYSUBITEMDRAW,当值为CDDS_ITEMPREPAINT时,设置NMLVCUSTOMDRAW结构(lParam是结构指针)中clrTextBk为自己想要的颜色。
      

  2.   

    http://www.vckbase.com/document/viewdoc/?id=891
      

  3.   

    就直接返回你说的这些就可以了。。反之之前做不做什么处理。
    还有。。我子窗口 就是准备换颜色的listview怎么响应NM_CUSTOMDRAW消息。
    是不是父窗口响音。。子窗口发送WM_NOTIFY消息吗。。然后
    Send(父窗口句柄, WM_NOTIFY, 0, lParam);
    这个lParam怎么填
      

  4.   

    我主要是看网上有些文章用到了什么 hdc  还用到SelectObject这些函数
    把我搞昏了。
      

  5.   

    用sdk的話,你也逃不掉用hdc和SlectObject的啊,看看《Windows程序設計》就明白了。
      

  6.   


    不是說讓你手動發送這么一條notify,而是在消息回調中處理WM_NOTIFY,類型為NM_CUSTOMDRAW的情況WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        if (uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
        {
            ...
        }
    }
      

  7.   

    WM_NOTIFY是控件发给父窗口的,你只需要响应通知,不需要自己来发消息。
      

  8.   

    这里的处理我大概知道怎么搞  主要是这个消息 怎么才会得到,。
     比如 我现在想更新我listview的一个单元颜色,改怎么做呢??
      

  9.   

    更新用ListView_Update,或者SendMessage给控件发LVM_UPDATE消息。
      

  10.   

    然后它就会自己发送WM_NOFITY消息给父窗口。我只要在父窗口里面绘制就是了? hdc是子窗口的吗。
    大哥 能给点你的代码看看嘛。
      

  11.   

    是這么一個意思。從上下文猜測,hdc只可能是個變量,很有可能是HDC類型的變量。HDC是DC句柄,用來在窗口上繪圖的。至於子窗口的問題。。首先如果是HDC類型變量,它就不可能是窗口。因為窗口的Handle是HWND類型,其次,hdc也不一定就是子窗口相關的DC句柄,這個還需要根據你是如何定義和得到它的值才能判斷。
    樓主基本的東西還有點欠缺,即使有源碼估計也是問題多多哦。
      

  12.   

    在这个消息映射函数中,NMLVCUSTOMDRAW* pLVCD = reinterpret_cast <NMLVCUSTOMDRAW*>( pNMHDR );是什么意思,三个if都是什么意思,谢谢 
    void CColorListCtrl::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult ) 

    NMLVCUSTOMDRAW* pLVCD = reinterpret_cast <NMLVCUSTOMDRAW*>( pNMHDR ); // Take the default processing unless we set this to something else below. 
    *pResult = 0; // First thing - check the draw stage. If it's the control's prepaint 
    // stage, then tell Windows we want messages for every item. 
    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage ) 

    *pResult = CDRF_NOTIFYITEMDRAW; 

    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage ) 

    *pResult = CDRF_NOTIFYSUBITEMDRAW; 

    else if ( (CDDS_ITEMPREPAINT ¦ CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage ) 
    {
    网友回复:dwDrawStage :Current drawing stage. This value is one of the following. 
    Global Values: 
    CDDS_POSTERASE 
    After the erasing cycle is complete. 
    CDDS_POSTPAINT 
    After the painting cycle is complete. 
    CDDS_PREERASE 
    Before the erasing cycle begins. 
    CDDS_PREPAINT 
    Before the painting cycle begins. 
    Item-specific Values: 
    CDDS_ITEM 
    Indicates that the dwItemSpec, uItemState, and lItemlParam members are valid. 
    CDDS_ITEMPOSTERASE 
    After an item has been erased. 
    CDDS_ITEMPOSTPAINT 
    After an item has been drawn. 
    CDDS_ITEMPREERASE 
    Before an item is erased. 
    CDDS_ITEMPREPAINT 
    Before an item is drawn. 
    CDDS_SUBITEM 
      

  13.   

    Custom Draw With List View and Tree View Controls
    Most common controls can be handled in essentially the same way. However, the list view and tree view controls have some features that require a somewhat different approach to custom draw.For Version 5.0 of the common controls, these two controls may display clipped text if you change the font by returning CDRF_NEWFONT. This behavior is necessary for backward compatibility with earlier versions of the common controls. If you want to change the font of a list view or tree view control, you will get better results if you send a CCM_SETVERSION message with the wParam value set to 5 before adding any items to the control.Custom Draw With List View Controls
    Because list view controls have subitems and multiple display modes, you will need to handle the NM_CUSTOMDRAW notification somewhat differently than for the other common controls.For report mode:The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW. 
    You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. If you specify new fonts or colors and return CDRF_NEWFONT, all subitems of the item will be changed. If you want instead to handle each subitem separately, return CDRF_NOTIFYSUBITEMDRAW. 
    If you returned CDRF_NOTIFYITEMDRAW in the previous step, you will then receive an NM_CUSTOMDRAW notification for each subitem with dwDrawStage set to CDDS_SUBITEM | CDDS_PREPAINT. To change the font or color for that subitem, specify a new font or color and return CDRF_NEWFONT. 
    For the large icon, small icon, and list modes:The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW. 
    You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. You can change the fonts or colors of an item by specifying new fonts and colors and returning CDRF_NEWFONT. Because these modes do not have subitems, you will not receive any additional NM_CUSTOMDRAW notifications. 
    An example of a list view NM_CUSTOMDRAW notification handler is given in the next section.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: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;    
        }
    ...
    }The first NM_CUSTOMDRAW notification has the dwDrawStage member of the NMCUSTOMDRAW structure set to CDDS_PREPAINT. The handler returns CDRF_NOTIFYITEMDRAW to indicate that it wishes to modify one or more items individually. The control then sends an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_PREPAINT for each item. The handler returns CDRF_NOTIFYITEMDRAW to indicate that it wishes to modify the item.If CDRF_NOTIFYITEMDRAW was returned in the previous step, the next NM_CUSTOMDRAW notification has dwDrawStage set to CDDS_ITEMPREPAINT. The handler gets the current color and font values. At this point, you can specify new values for small icon, large icon, and list modes. If the control is in report mode, you can also specify new values that will apply to all subitems of the item. If you have changed anything, return CDRF_NEWFONT. If the control is in report mode and you want to handle the subitems individually, return CDRF_NOTIFYSUBITEMREDRAW.The final notification is only sent if the control is in report mode and you returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. The procedure for changing fonts and colors is the same as that step, but it only applies to a single subitem. Return CDRF_NEWFONT to notify the contr