“article in MSDN”主要是一个复制粘贴的“简单”直接代码不会产生任何输出。我已经添加了几行(用普通的GDI绘图)以确保坐标正确 - 这些行工作得很好。MFC应用程序中的Gdiplus :: PathGradientBrush不绘制
代码正在更改STATIC
控件的背景,并在OnPaint
处理程序中执行绘图。 OnCtlColor
增加了返回NULL_BRUSH
这个STATIC
控制,所以没有画架完成的框架。
检查GDI +对象和方法(在调试器中并通过日志记录)的状态显示一切正常。我很茫然,请帮助解决这个难题。
下面是相关的代码(除去错误处理和static_cast
的我有\ W4):
CPaintDC dc(this);
Graphics graphics(dc);
CRect rc;
GetDlgItem(IDC_STATIC_GS_COLOR)->GetWindowRect(&rc); // the STATIC to paint
ScreenToClient(&rc);
// GDI+ uses real numbers, not integers
const Rect gdirc = Rect(rc.left, rc.top, rc.Width(), rc.Height());
// next 2 lines work just fine - painting a RED background
const SolidBrush solidBrush((ARGB)Color::Red);
graphics.FillRectangle(&solidBrush, gdirc);
const PointF sz(rc.Width() - 1, rc.Height() - 1);
PointF pts[] = {PointF(0, 0), PointF(sz.X, 0), PointF(sz.X, sz.Y), PointF(0, sz.Y)};
PathGradientBrush brush(pts, 4);
Color colors[] = {Color(0, 0, 0), Color(255, 0, 0), Color(0, 255, 0), Color(0, 0, 255)};
int count = 4;
brush.SetSurroundColors(colors, &count);
brush.SetCenterColor(Color(128, 128, 128));
// !!!!! this doesn't fail, returns a status OK, and has NO EFFECT on the image :(
const auto status = graphics.FillRectangle(&brush, gdirc);
// this draws a smaller inner GREEN rectangle, works as expected
rc.DeflateRect(20, 20);
dc.FillSolidRect(&rc, m_rgb);