Gdiplus::Font font(_T("微软雅黑"), (Gdiplus::REAL)130);
Gdiplus::RectF orgin(0.0f, 100.0f, nWidth, 200.0f);
Gdiplus::StringFormat stringformat;
stringformat.SetAlignment(Gdiplus::StringAlignmentCenter);
//stringformat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 255, 0, 0));
graphics.DrawString(strFailedContent.c_str(), -1, &font, orgin, &stringformat, &solidBrush);

  函数如下

float GetTextWidthFloor(const wstring& strText, const Gdiplus::Font& font)
{
Gdiplus::StringFormat stringformat(Gdiplus::StringAlignmentNear); Gdiplus::GraphicsPath graphicsPathObj;
Gdiplus::FontFamily fontfamily;
font.GetFamily(&fontfamily); Gdiplus::RectF rcBound;
graphicsPathObj.AddString(strText.c_str(), -1, &fontfamily, font.GetStyle(), font.GetSize(), Gdiplus::PointF(0, 0), &stringformat);
graphicsPathObj.GetBounds(&rcBound); return (float)(rcBound.Width);
} int GetTextWidth(const wstring& strText, const Gdiplus::Font& font)
{
// calculate spaces width of text head
// due to gdiplus do not care about it
int nHeadSpace = 0;
int nLen = strText.size();
for (int i=0; i<nLen; ++i)
{
if (0x20 == strText.at(i))
nHeadSpace++;
else{
break;
}
} // calculate space width
static float fSpaceWidth = 0.0f;
if ((fSpaceWidth >= -0.00001f && fSpaceWidth <= 0.00001f) && nHeadSpace > 0)
{
fSpaceWidth = GetTextWidthFloor(_T("a b"), font) - GetTextWidthFloor(_T("ab"), font);
} float fResult = GetTextWidthFloor(strText, font) + (float)nHeadSpace * fSpaceWidth; return (int)fResult + 1;
}

  

最新文章

  1. 微信小程序体验(2):驴妈妈景区门票即买即游
  2. mysql基础语法及拓展到web中的sql注入
  3. 详解FindBugs的各项检测器 .
  4. 【译文】 C#面向对象的基本概念 (Basic C# OOP Concept) 第一部分(类,对象,变量,方法,访问修饰符)
  5. 安装CDH4 (Cloudera Distribution Hadoop)步骤
  6. SWFUpload下载地址
  7. Javascript学习6 - 类、对象、继承
  8. Spring Boot中使用 Spring Security 构建权限系统
  9. springmvc流程图
  10. springMVC工作过程
  11. 基于react可无限向内部添加节点的tree
  12. Java实现一个双向链表的倒置功能
  13. Delphi IdHTTP1下载文件防止假死 (
  14. mooc《数据结构》 习题1.8 二分查找
  15. POJ2289 Jamie&#39;s Contact Groups(二分图多重匹配)
  16. Delphi 完全时尚手册之 Visual Style 篇 (界面不错) 转自http://blog.csdn.net/iseekcode/article/details/4733229
  17. resin 4.0.xx 版破解方法
  18. mac下的一些操作
  19. Codeforces Round #357 (Div. 2) A. A Good Contest 水题
  20. 超全面的JavaWeb笔记day09&lt;Servlet&amp;GenericServlet&amp;HttpServlet&amp;ServletContext&gt;

热门文章

  1. Kubernetes——YAML文件
  2. FieldByName().AsFloat只可以保留四位小数,四位以上应使用Value
  3. 命令打开java控制面板
  4. gitlab实现webhook触发jenkins 自动,构建,测试,push webhook构子 总结
  5. 转《Python爬虫学习系列教程》学习笔记
  6. 管理和安装 chart【转】
  7. &#39;/&#39;和‘/*’差异造成的No mapping found for HTTP request with URI [/springMVC/welcome.jsp] in DispatcherServlet with name &#39;springmvc&#39;
  8. Day6-T3
  9. Service总结
  10. torch.nn.Conv2d()使用