article in MSDNからのコピー貼り付けである「シンプルな」ストレートフォワードコードは出力を生成しません。私は、座標が正しいことを確認するために、いくつかの行(プレーンなGDIで描画)を追加しました。これらの行はうまく動作します。MFCアプリケーション内のGdiplus :: PathGradientBrushは描画されません
コードはSTATIC
コントロールの背景を変更しており、描画はOnPaint
ハンドラーで実行されます。 OnCtlColor
は、このSTATIC
コントロールのNULL_BRUSH
を返すように拡張されているため、フレームワークによるペイントオーバーはありません。
GDI +のオブジェクトとメソッドの状態をチェックすると(デバッガとログ経由で)、すべてが正常であることがわかります。私は迷っています。このパズルを解くのを手伝ってください。
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);