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

推荐订阅源

WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
月光博客
月光博客
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
IT之家
IT之家
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
爱范儿
爱范儿

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