Listview element with NM_CUSTOMDRAW is flickering

all. http://i.stack.imgur.com/ugfY4.jpg

I have a colored list editor like this, each item represents a different color. So the user clicks on the subItem COLOR_CODE, the color picker is updated to the selected HSV value, and then the user drags the color picker cursor onto the pallete, and the subItem COLOR_CODE should be updated in real time, and so does the color ID text. Most of the time the update is done nicely and smoothly, but sometimes it just flickers in a way - ---- It happens in a really flickering way, as if there was no time to draw it quickly.

I started searching and found many posts, it all resulted in double buffering. Ok I have DOUBLE BUFFERING included in my list like this

case WM_INITDIALOG:
ListView_SetExtendedListViewStyle(GetDlgItem(hDlg,id_listview),LVS_EX_DOUBLEBUFFER);

      

also tried it like this

SendDlgItemMessage(hWnd,id_listview,LVM_SETEXTENDEDLISTVIEWSTYLE,NULL,(LPARAM)LVS_EX_DOUBLEBUFFER);

      

But it did not help. Here is my usual drawing routine Basically it takes any string written in subItem id - 0xffb400 for example and converts it to COLORREF and then sets the BG subItem 2 color to the resulting color;

case WM_NOTIFY:
if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
        {
            SetWindowLong(hDlg, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam,hDlg));
            return TRUE;
        }
        break;

LRESULT colorEditor::ProcessCustomDraw (LPARAM lParam,HWND hDlg)
{
    LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;

    switch(lplvcd->nmcd.dwDrawStage) 
    {
        case CDDS_PREPAINT:
            return CDRF_NOTIFYITEMDRAW;
        case CDDS_ITEMPREPAINT: 
            return CDRF_NOTIFYSUBITEMDRAW;
        case CDDS_ITEMPREPAINT|CDDS_SUBITEM: //Before an item is drawn//
            if (lplvcd->iSubItem==2)
            {
                item_redraw.iItem=lplvcd->nmcd.dwItemSpec;
                SendDlgItemMessageA(hWnd,id_listview,LVM_GETITEM,0,(LPARAM)&item_redraw);
                lplvcd->clrTextBk = colorrefFromString(item_redraw.pszText);
            }
            return CDRF_NEWFONT;
    }
    return CDRF_DODEFAULT;
}

      

Just in case, if you think colorrefFromString is the case, I provide it with a list:

COLORREF colorEditor::colorrefFromString(wchar_t *color)
{
    COLORREF res_color;
    unsigned short i=0,di=0;
    int digits[6];
    int h_digits[3];
    if (color[i]=='0'&&(color[i+1]=='x'||color[i+1]=='X')) i=2;
    int ix=0;

    while (color[(ix++)+i]!='\0'){}
    if (--ix!=5) while((ix++)<5)
        digits[di++]=0;

    while (color[i]!='\0')
    {
        if (color[i]>47&&color[i]<58) digits[di++]=color[i]-48;
        else if (color[i]>64&&color[i]<71) digits[di++]=color[i]-65+10;
        else if (color[i]>96&&color[i]<103) digits[di++]=color[i]-97+10;
        i++;
    }
    h_digits[0]=digits[0]*16+digits[1];
    h_digits[1]=digits[2]*16+digits[3];
    h_digits[2]=digits[4]*16+digits[5];
    res_color=0x00000000|(h_digits[2]<<16)|(h_digits[1]<<8)|h_digits[0];
    return res_color;
}

      

And now QUESTION: Why am I flickering?

+3


source to share


1 answer


At first glance, I see no real reason for the flickering.

But try to do all the drawing here yourself. Maybe it works.



Just calculate the color. Call FillRect on the item rectangle with the given controller and return CDRF_SKIPDEFAULT.

0


source







All Articles