Posted on 2009-12-29 17:02
S.l.e!ep.¢% 阅读(477)
评论(0) 编辑 收藏 引用 所属分类:
VC
以前绘制 +/- 时是使用图片,看到有人用代码实现,转贴之
绘制CTreeCtrl的+/-展开按钮的代码.
void DrawExpandButton( HDC hdc, LONG x, LONG y, BOOL bExpand, BOOL bFill )
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
const int PROPTREEITEM_EXPANDBOX = 9; // 按钮大小
const int PROPTREEITEM_EXPANDBOXHALF = (PROPTREEITEM_EXPANDBOX / 2);
![](/Images/OutliningIndicators/InBlock.gif)
HPEN hPen;
HPEN oPen;
HBRUSH oBrush;
![](/Images/OutliningIndicators/InBlock.gif)
hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
oPen = (HPEN)SelectObject(hdc, hPen);
oBrush = (HBRUSH)SelectObject(hdc, GetStockObject(bFill ? WHITE_BRUSH : NULL_BRUSH));
![](/Images/OutliningIndicators/InBlock.gif)
Rectangle(hdc, x, y, x + PROPTREEITEM_EXPANDBOX, y + PROPTREEITEM_EXPANDBOX);
SelectObject(hdc, GetStockObject(BLACK_PEN));
![](/Images/OutliningIndicators/InBlock.gif)
if (!bExpand)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MoveToEx(hdc, x + PROPTREEITEM_EXPANDBOXHALF, y + 2, NULL);
LineTo(hdc, x + PROPTREEITEM_EXPANDBOXHALF, y + PROPTREEITEM_EXPANDBOX - 2);
}
![](/Images/OutliningIndicators/InBlock.gif)
MoveToEx(hdc, x + 2, y + PROPTREEITEM_EXPANDBOXHALF, NULL);
LineTo(hdc, x + PROPTREEITEM_EXPANDBOX - 2, y + PROPTREEITEM_EXPANDBOXHALF);
![](/Images/OutliningIndicators/InBlock.gif)
SelectObject(hdc, oPen);
SelectObject(hdc, oBrush);
DeleteObject(hPen);
}
![](/Images/OutliningIndicators/None.gif)