自绘CButton,想在获取焦点的时候给按钮添加一个虚线外框,觉得圆角矩形好看点,于是写了一个。
Gdiplus::Pen pen(Color(255, rColor, gColor, bColor));
pen.SetDashStyle(Gdiplus::DashStyle::DashStyleDot);
// 直角矩形
//g.DrawRectangle(&pen, rcClient.left+1, rcClient.top+1, rcClient.Width()-2, rcClient.Height()-2);
// 圆角矩形
int nRadius = 2;// 圆角半径
GraphicsPath* path = new GraphicsPath;
path->StartFigure();
path->AddArc((REAL)rcClient.left, (REAL)rcClient.top, (REAL)nRadius * 2, (REAL)nRadius * 2, 180.0, 90.0);
path->AddArc((REAL)rcClient.left + rcClient.Width() - nRadius * 2, (REAL)rcClient.top, (REAL)nRadius * 2, (REAL)nRadius * 2, 270.0, 90.0);
path->AddArc((REAL)rcClient.left + rcClient.Width() - nRadius * 2, (REAL)rcClient.top + rcClient.Height() - nRadius * 2, (REAL)nRadius * 2, (REAL)nRadius * 2, 0.0, 90.0);
path->AddArc((REAL)rcClient.left, (REAL)rcClient.top + rcClient.Height() - nRadius * 2, (REAL)nRadius * 2, (REAL)nRadius * 2, 90.0, 90.0);
path->CloseFigure();
g.DrawPath(&pen, path);//这里绘制的是矩形边框,如果是绘制实心的,DrawPath换成FillPath即可
delete path;
path = NULL;