title: SetWindowRgn from GDI+ region
body: <p>I'm Building a MFC C++ app. I have a need to render a window to the shape of a  dynamic string. To archive this, I did the following:</p>
  
  <ol>
  <li>Use GDI+ to render the text using <code>GraphicsPath</code> and <code>AddString</code> in GDI+</li>
  <li>Create a <code>Region</code> object from <code>GraphicsPath</code></li>
  <li>Convert <code>Region</code> to <code>CRng</code> and use <code>SetWindowRgn</code> to set the window shape</li>
  </ol>
  
  <p>Here is the code:</p>
  
  <p>In <code>OnInitDialog</code>:</p>
  
  <pre><code>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), &amp;fontFamily, FontStyleRegular, 14, 
  Gdiplus::Point(0,16), &amp;strformat );
  Region myRgn(&amp;path);    
  
  CRng rgn;
  rgn.FromHandle(myRgn.GetHRGN(&amp;graphics));
  SetWindowRgn(rgn,TRUE) ;
  </code></pre>
  
  <p>In <code>OnPaint</code></p>
  
  <pre><code>RECT rect;
  GetWindowRect(&amp;rect);
  CBrush brush;
  brush.CreateSolidBrush(color);
  paint_dc.FillRect(&amp;rect, &amp;brush);
  </code></pre>
  
  <p>The problem is that I'm not seeing anything being displayed. Any comments?</p>