绘制CTreeCtrl的+/-展开按钮的代码

以前绘制 +/- 时是使用图片,看到有人用代码实现,转贴之

绘制CTreeCtrl的+/-展开按钮的代码.
void  DrawExpandButton( HDC hdc, LONG x, LONG y, BOOL bExpand, BOOL bFill )
{
    
const int PROPTREEITEM_EXPANDBOX        = 9;            // 按钮大小
    const int PROPTREEITEM_EXPANDBOXHALF    = (PROPTREEITEM_EXPANDBOX / 2);

    HPEN hPen;
    HPEN oPen;
    HBRUSH oBrush;

    hPen 
= CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
    oPen 
= (HPEN)SelectObject(hdc, hPen);
    oBrush 
= (HBRUSH)SelectObject(hdc, GetStockObject(bFill ? WHITE_BRUSH : NULL_BRUSH));

    Rectangle(hdc, x, y, x 
+ PROPTREEITEM_EXPANDBOX, y + PROPTREEITEM_EXPANDBOX);
    SelectObject(hdc, GetStockObject(BLACK_PEN));

    
if (!bExpand)
    
{
        MoveToEx(hdc, x 
+ PROPTREEITEM_EXPANDBOXHALF, y + 2, NULL);
        LineTo(hdc, x 
+ PROPTREEITEM_EXPANDBOXHALF, y + PROPTREEITEM_EXPANDBOX - 2);
    }


    MoveToEx(hdc, x 
+ 2, y + PROPTREEITEM_EXPANDBOXHALF, NULL);
    LineTo(hdc, x 
+ PROPTREEITEM_EXPANDBOX - 2, y + PROPTREEITEM_EXPANDBOXHALF);

    SelectObject(hdc, oPen);
    SelectObject(hdc, oBrush);
    DeleteObject(hPen);
}

你可能感兴趣的:(绘制CTreeCtrl的+/-展开按钮的代码)