简体   繁体   中英

Win32 Listview Tilemode Interactable Item Space Question

When custom painting a listview item in tileview, returning CDRF_SKIPDEFAULT during CDDS_ITEMPREPAINT enlarges the interactable rect of the item to the size of the actual item (ie the size received from ListView_GetItemRect(LVIR_BOUNDS)) instead of only the size of icon+label. How and why does this happen exactly? I couldn't find a clear answer in the docs or on the web. I mean, shouldn't handling custom paint only affect the painting of the item and not the way you interact with it?

Codesample:

::NMLVCUSTOMDRAW* pNMCustomDraw = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);

switch (pNMCustomDraw->nmcd.dwDrawStage)
{

    // Before the painting cycle begins. 
    case CDDS_PREPAINT:
    {

        return CDRF_NOTIFYITEMDRAW;

    }

    // Before an item is drawn.
    case CDDS_ITEMPREPAINT:
    {

        return CDRF_SKIPDEFAULT;
        
    }
    
}

Visual representation of the question:

在此处输入图像描述

The line case CDDS_ITEM | CDDS_PREPAINT case CDDS_ITEM | CDDS_PREPAINT is checking the result value of "or'ing" CDDS_ITEM | CDDS_PREPAINT CDDS_ITEM | CDDS_PREPAINT . plus, you already checked CDDS_PREPAINT above. Shouldn't it be CDDS_ITEMPREPAINT ?

It should be like this, probably:

switch (pNMCustomDraw->nmcd.dwDrawStage)
{

    // Before the painting cycle begins. 
    case CDDS_PREPAINT:
    {
        return CDRF_NOTIFYITEMDRAW;

    }

    // Before an item is drawn.
    case CDDS_ITEM: // fall through
    case CDDS_ITEMPREPAINT:
    {

        return CDRF_SKIPDEFAULT;
        
    }
}

Plus, MSDN states that:

CDRF_SKIPDEFAULT The application drew the item manually. The control will not draw the item. This occurs when dwDrawStage equals CDDS_ITEMPREPAINT.

in https://docs.microsoft.com/en-us/windows/win32/controls/nm-customdraw-list-view

check here as well (MSDN):

https://docs.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-nmcustomdraw

Try that:). And don't forget to add breaks if needed after cases. Greetings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM