Gdiplus::DrawString

本文转自:http://blog.csdn.net/hgy413/article/details/6758834

 

1.犯了一个错误:

Brush(RGB(255,0,0));这样写程序不会报错,然后很悲剧的怎么也显示不出文字,记录下,以后不要再犯了。

 

 

自己写的示例代码:

  1. CPaintDC dc(this);  
  2.   
  3.         Graphics g(dc.GetSafeHdc());  
  4.   
  5.         //---------------------------------------  
  6.         // fontFamily第一个参数是用来定义  
  7.         // 宋体、楷体、仿宋、黑体、隶书以及幼圆等多种字样  
  8.         // 特别说明:Gdi+不支持OpenType字体,吃了一次亏了  
  9.         //---------------------------------------  
  10.         FontFamily fontFamily(L"幼圆");   
  11.   
  12.         //---------------------------------------  
  13.         // font四个参数,第二个:字体高度,单位由第四个决定  
  14.         // 第三个:字体风格:  
  15.         //    FontStyleRegular(正常)、  
  16.         //  FontStyleBold(加粗)、  
  17.         //  FontStyleItalic(斜体)、  
  18.         //  FontStyleBoldItalic (粗斜体)、  
  19.         //  FontStyleUnderline(下划线)  
  20.         //  FontStyleStrikeout(删除线)  
  21.         // 第四个:UnitDisplay(1/75英寸)、  
  22.         //  UnitPixel(像素)、  
  23.         //  UnitPoint(点)、一点约折合为1/72英寸  
  24.         //  UnitInch(英寸)、  
  25.         //  UnitDocument(1/300英寸)、  
  26.         //  UnitMillimeter(毫米)  
  27.         //---------------------------------------  
  28.         Gdiplus::Font font(&fontFamily, 12, FontStyleRegular, UnitPixel);  
  29.   
  30.         //---------------------------------------  
  31.         // 这是为了和以前的GDI字体  
  32.         // font两个参数:  
  33.         //  HDC, LOGFONT  
  34.         //---------------------------------------  
  35.         LOGFONT lf;  
  36.         ::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);  
  37.         memcpy(lf.lfFaceName, "Arial", 5) ;  
  38.         lf.lfHeight = 13 ;  
  39.   
  40.         Gdiplus::Font Gdi_font(dc.GetSafeHdc(), &lf);  
  41.   
  42.         //-----------------------------------------  
  43.         //stringformat主要用以下的函数来控制文本的显示方式  
  44.         // SetAlignment  
  45.         //-----------------------------------------  
  46.         StringFormat stringformat;  
  47.   
  48.   
  49.         //-----------------------------------------  
  50.         //  StringAlignmentNear(左对齐或右对齐,取决于书写方向是从左到右还是从右到左)、  
  51.         //  StringAlignmentCenter(水平居中)  
  52.         //  StringAlignmentFar(两端对齐)。  
  53.         //  默认都不影响垂直  
  54.         //-----------------------------------------  
  55.         stringformat.SetAlignment(StringAlignmentCenter);  
  56.   
  57.         //-----------------------------------------  
  58.         // 和SetAlignment对应,为竖直的设置  
  59.         //-----------------------------------------  
  60.         stringformat.SetLineAlignment(StringAlignmentCenter);  
  61.   
  62.         //------------------------------------------  
  63.         // SolidBrush  
  64.         // HatchBrush(阴影画刷)  
  65.         // TextureBrush(纹理画刷):使用图像来填充形状的内部。无法继承此类  
  66.         // LinearGradientBrush(渐变画刷)  
  67.         // 注意,用的是Color初始化,不要用RGB初始化,不会报错,但绘不出来!  
  68.         //------------------------------------------  
  69.         SolidBrush brush(Color(255, 255, 0, 0));  
  70.   
  71.         CRect rcClient ;  
  72.         GetClientRect(rcClient);  
  73.   
  74.         //------------------------------------------  
  75.         // SetTextRenderingHint控制文本输出的质量  
  76.         //------------------------------------------  
  77.         g.SetTextRenderingHint(TextRenderingHintAntiAlias);  
  78.   
  79.   
  80.         //------------------------------------------  
  81.         // 一种是point ,一种是rect控制输出  
  82.         //------------------------------------------  
  83.   
  84.         g.DrawString(TEXT("1234"), -1, &font,  
  85.             RectF(0, 0, rcClient.Width(), rcClient.Height()), &stringformat, &brush);  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值