MFC C++ アプリを構築しています。ウィンドウを動的文字列の形状にレンダリングする必要があります。これをアーカイブするために、次のことを行いました。
- GDI+ を使用して、 GDI + を使用
GraphicsPath
してテキストをレンダリングするAddString
Region
からオブジェクトを作成するGraphicsPath
- に変換
Region
しCRng
て使用SetWindowRgn
し、ウィンドウの形状を設定します
コードは次のとおりです。
でOnInitDialog
:
CClientDC dc(this);
Graphics graphics(dc.GetSafeHdc());
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
GraphicsPath path;
FontFamily fontFamily(L"Arial");
StringFormat strformat;
wchar_t pszbuf[] = L"testString";
path.AddString(pszbuf, wcslen(pszbuf), &fontFamily, FontStyleRegular, 14,
Gdiplus::Point(0,16), &strformat );
Region myRgn(&path);
CRng rgn;
rgn.FromHandle(myRgn.GetHRGN(&graphics));
SetWindowRgn(rgn,TRUE) ;
のOnPaint
RECT rect;
GetWindowRect(&rect);
CBrush brush;
brush.CreateSolidBrush(color);
paint_dc.FillRect(&rect, &brush);
問題は、何も表示されていないことです。コメントはありますか?