我正在构建一个 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);
问题是我没有看到任何显示的内容。任何意见?