惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
D
DataBreaches.Net
腾讯CDC
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
罗磊的独立博客
月光博客
月光博客
MyScale Blog
MyScale Blog
U
Unit 42
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
G
Google Developers Blog
博客园 - 【当耐特】
D
Docker
I
InfoQ
雷峰网
雷峰网

博客园 - RayG

How to get data from Oracle DB in silverlight via WCF ? [Copied] 80 VC++ tips [Copied]The GDI Coordinate Systems My Cheating Death solution in VC++ 3 given points, get the angle between two lines trouble shoot about using BindLayer in MapX with C# [原创] 计算几何常用算法(转) Trouble shooting about installation of ArcSDE 9.2 File type transform between ArcGIS and other major type - RayG [Tips] How to converting a Coverage to a Shapefile ? - RayG [Tips] How to Add New field into Shapefile attribute table in ArcGIS ? 子非鱼,安知鱼之乐? [GuanRui] My program implement on Symbian S60 (#1: File IO) - RayG My XNA HitBee small game [GuanRui]How to open Path browse dialog in VBA of ArcGIS Desktop ? [Ray] My GPS (卫星定位接收器) tracker program on Symbian OS Binary Tree ANSI C Implement (2) - RayG Binary Tree ANSI C Implement (1) Graph & Topology & Shortest path
[Ray]How to use CString to create a font family - RayG
RayG · 2009-07-10 · via 博客园 - RayG

Keywords: GDI+ , VC++ ,  CString , WCHAR , FontFamily , Convert

As we all know,in GID plus, when we want to create a new font , we should do something like this :

      FontFamily  fontFamily(L"隶书");

      Font    font( &fontFamily, 24, FontStyleRegular, UnitPixel );  

The problem is , the declare of this function is const WCHAR *,   Maybe you will encount an compile error like this :

 error C2664: '__thiscall Gdiplus::FontFamily::Gdiplus::FontFamily(const unsigned short *,const class Gdiplus::FontCollection *)' : 

cannot convert parameter 1 from 'class CString' to 'const unsigned short *'

what if we want to create a new font with CString parameters like 

CString strMyFontName;

FontFamily fontFamily(strMyFontName);

Just follow these steps to make it work:

CString strMyFontName("微软雅黑");  

string fface=(string)strMyFontName;

WCHAR *wfface = new WCHAR[fface.length()+1];

if(!MultiByteToWideChar(CP_ACP,0,fface.c_str(),static_cast<int>(fface.length())+1,wfface,static_cast<int>(fface.length())+1))

{

TRACE0("Error creating text actor.");

}

else

{

FontFamily fontFmly(wfface);

Font  font(&fontFmly, 12, FontStyleRegular, UnitPixel);

And don't forget to add include <string> in the top of the cpp file.  

Ray

2009-7