Owner-drawn button, WM_CTLCOLORBTN and WM_DRAWITEM (clearing an HDC)

Viewed 5730

I'm trying to implement a simple owner-drawn button, which will just contain an image from a brush.

Here's my code (WTL, but it's quite straightforward):

case WM_CTLCOLORBTN:
    dc.SetBkMode(TRANSPARENT);
    POINT pt = { 0 };
    button.MapWindowPoints(m_hWnd, &pt, 1);
    dc.SetBrushOrg(-pt.x, -pt.y, NULL);
    return m_brushHeader;

Everything works fine so far, but for proper keyboard support, I have to add focus rectangle. So now I'm also handling the WM_DRAWITEM message:

case WM_DRAWITEM:
    if(lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_FOCUS))
    {
        if((lpDrawItemStruct->itemState & ODS_FOCUS) && 
            !(lpDrawItemStruct->itemState & ODS_NOFOCUSRECT))
        {
            dc.DrawFocusRect(&lpDrawItemStruct->rcItem);
        }
        else
        {
            // Need to remove the rectangle here!
        }
        break;
    }
    break;

The rectangle is properly added, but when the focus is moved to a different button, and I receive the ODA_DRAWENTIRE request, I have to clear it.

How do I clear the content of the HDC? I found only methods of filling it with color, etc. I need to make it empty/transparent, like it was before using DrawFocusRect.

P.S. The application uses visual styles, i.e. ComCtl32.dll Version 6.

1 Answers
Related