How to make TreeView send CDDS_*ERASE events?

108 Views Asked by At

I'm implementing a customized TreeView with win32. Have the following custom draw code:

void treeCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
    NMCUSTOMDRAW* pNMCustomDraw = (NMCUSTOMDRAW*)pNMHDR;
    NMTVCUSTOMDRAW* pNMTVCustomDraw = (NMTVCUSTOMDRAW*)pNMHDR;
 
    switch (pNMCustomDraw->dwDrawStage)
    {
    case CDDS_PREPAINT:
        *pResult = CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYITEMERASE | CDRF_NOTIFYPOSTERASE;
        break;     
    case CDDS_POSTERASE:
    case CDDS_ITEMPOSTERASE:
        // never happens
        *pResult = CDRF_DODEFAULT;
        break;     
    case CDDS_ITEMPREPAINT:
        *pResult = CDRF_DODEFAULT;
        break;     
    case CDDS_ITEMPOSTPAINT:
        // some working code
}

With all the documented ways I tried to make the view sending any of the CDDS_*ERASE message, with no luck at all, despite the docu saying the corresponding CDRF has to be returned from CDDS_PREPAINT. Am I doing/wanting something utterly impossible?

UPD: The custom draw is done in the window procedure. The pResult is correctly returned, as CDDS_ITEMPOSTPAINT is caught and correctly processed. Just the CDDS_*ERASE remain untriggered.

Usecase: I need to catch the moment of TreeView item being erased off its previous coordinates, so being able to run some custom cleanup code. The CDDS_ITEMPOSTPAINT goes just well with custom drawing, but the drawing is duplicated during the scrolling and navigation, because of no way to erase the old custom stuff.

0

There are 0 best solutions below