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

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 热门话题
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky
J
Java Code Geeks
腾讯CDC
博客园 - 聂微东
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Last Week in AI
Last Week in AI
量子位
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Securelist
AWS News Blog
AWS News Blog
GbyAI
GbyAI
L
LINUX DO - 最新话题
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
Y
Y Combinator Blog
W
WeLiveSecurity
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Proofpoint News Feed
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
V
V2EX
N
News and Events Feed by Topic
Google DeepMind News
Google DeepMind News
D
Docker
The Hacker News
The Hacker News
A
About on SuperTechFans
Security Latest
Security Latest
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
博客园_首页
H
Hacker News: Front Page

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