1、在获取文字宽度的时候用
gph.MeasureString(str,wcslen(str)-1,&font,PointF(50.0,50.0),&rtf);
获得的宽度会偏大。换成下面的代码后即可:
2、
StringFormat strFormat = StringFormat::GenericTypographic();
strFormat.SetAlignment(StringAlignmentNear);
gph.MeasureString(str,str.GetLength()-9,&font,rt,&strFormat,&rcBou);
BLENDFUNCTION blendFunc32bpp;
blendFunc32bpp.AlphaFormat = AC_SRC_ALPHA;
blendFunc32bpp.BlendFlags = 0;
blendFunc32bpp.BlendOp = AC_SRC_OVER;
blendFunc32bpp.SourceConstantAlpha = 255; // alpha值
HDC hDC = GetDC(NULL);
int ret = UpdateLayeredWindow(m_hCompWnd, hDC, &SrcPt, &psize, hMemDC, &DestPt, 0, &blendFunc32bpp, ULW_ALPHA);
之后调用DrawString是由于传进去的Brush没有设置alpha值时默认为255,所以画出来的字会透明,只要将alpha改为254问题解决。