层窗口(WS_EX_LAYERED),先用DrawImage画了一张PNG图片上去当背景
然后用DrawString在上面写字
Font font(L"宋体",12,FontStyleRegular,UnitPixel);
StringFormat strFormat;
SolidBrush brush(Color(0xff,0,0,0));
graphics.DrawString(L"test string",-1,&font,PointF(0,0),&strFormat,&brush);
发现写出来的字把图片给透明了,相当于在图片上挖了个洞 BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
blend.SourceConstantAlpha = 255; ::UpdateLayeredWindow(m_hWnd,...,RGB(0,0,0),&blend,ULW_ALPHA);

解决方案 »

  1.   

    没用过GDI+的,不知道用没有SetBkMode之类的函数?
      

  2.   

    SolidBrush brush(Color::Transparent);试试
      

  3.   

    to goodboyws:
    Color::Transparent,不行
      

  4.   

    还发现一个有趣的现象,FontStyle用FontStyleBold和FontStyleItalic都能正确的画出黑色的字,而用默认的FontStyleRegular确是透明的
      

  5.   

    自己解决了
    Can I cancel this???
      

  6.   

    问题的原因是:
    层窗口(WS_EX_LAYERED),用UpdateLayeredWindow输出的文字(用常规方法输出的:TextOut、DrawText、DrawString...),并且设置了AC_SRC_ALPHA和ULW_ALPHA,就会存在这种错误解决方案就是:
    用GraphicsPath来代替文字输出
    path.AddString(...);
    pGraph->FillPath(&brush,&path);这样,默认的输出的文字质量很差,可以设置Graphics的SmoothingMode为SmoothingModeHighQuality