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

推荐订阅源

GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
G
Google Developers Blog
D
Docker
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
T
The Blog of Author Tim Ferriss
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
I
InfoQ
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News

博客园 - 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