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

推荐订阅源

WordPress大学
WordPress大学
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
G
Google Developers Blog
博客园_首页
有赞技术团队
有赞技术团队
V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题

博客园 - Michael Zhao

easyWeb2Pic -- 在IE浏览器中,将整个网页保存为BMP, JPEG/JPG, GIF, PNG或者TIFF图片 PeopleSoft Intergration Broker 设置及实列 网页保存利器——easyWebSave介绍 象IE收藏夹那样管理你从Web保存的文档(2) 网页保存利器——easyWebSave介绍 象IE收藏夹那样管理你从Web保存的文档(1) 网页保存利器——easyWebSave介绍 综述 Sharepoint中身份转换问题 Microsoft Sharepoint Service Access 2003 PeopleSoft 客户端安装 MFC ATL/WTL的一个技巧 上网浏览必备利器 -- easy Web Save easy Web Save 有人用过吗?可以把在网页的选择保存成HTML Complete, HTML Text Only, 甚至Word. 感觉挺方便的。 RES Protocol Inno Setup,有人用过吗? 免费的Installer 和 免费的Pascal Script Engine. Creating a Dialog-based App(转载) Unicode-enabling Microsoft C/C++ Source Code(转载) Int,Float,Char *,CString之间的转换(转载) Adding Entries to the Standard Context Menu(转载 from msdn) 你经常使用Baidu.com吗?
Building Unicode applications in MFC(转载)
Michael Zhao · 2005-05-13 · via 博客园 - Michael Zhao

What's The Point?
Windows NT4 and 2K run on Unicode. A great many of the net API functions provided by Microsoft® require Unicode and translating strings in and out of Unicode just to push them through these functions is a real pain. Building an application in Unicode not only allows easier access to these functions, but also creates code that runs optimally on NT operating systems.

NOTE - western releases of W9x don't support unicode. All releases of W9x only support a limited set of administrative net API calls which, as well as being ASCII, are often structured differently to their NT equivalents. The help files are fairly useless on leading you through the differences. The best way is to examine the respective header files for the function structures.

Project Settings
The first thing to ensure is that you have included the necessary Unicode libraries when installing your copy of Microsoft Visual Studio®. If you didn't do this when you first installed the tool, it's time to go back and remedy the omission.

Now you can go ahead and get the App Wizard to build you a project. Don't worry about Unicode for the moment, just work your way through the wizard as normal.

Once you've got a basic project up and running, all you need to do to make it build in Unicode is to tweak a couple of project settings. For debug builds, change the preprocessor directive to that shown below:

For release builds, change the preprocessor directives to that shown below:

If what you see in the preprocessor definitions box is substantially different from what you see above, don't panic. All you are trying to do is replace "_MBCS" with "_UNICODE" at the end of the string.

Finally you need to change the entry point symbol in the linker options:

Now the application will build using the Unicode libraries.

But this is only the first step. Now that the application builds in Unicode, you can't go on using the same old ASCII-type functions you always did. A little more refinement is required and here are a few hints on how to do it.

Unicode Programming
First of all, use MFC classes, particularly CStrings, wherever possible. They are overloaded to deal with both ASCII and Unicode.

When using string literals, you need to use the _T( ) macro to get the necessary conversion e.g.

AfxMessageBox(_T("This is a converted Unicode string literal"));

When using printf or the CString.Format() member function, the whole quoted section must be encapsulated by the _T( ) macro:

CString sExample;
sExample.Format(_T("Function failed, error code is %d"), GetLastError());

Don't use char[] types, use TCHAR[] instead (if you can't use a CString).

Below is a brief summary of some standard C++ function calls and their Unicode equivalents.

ASCII Unicode
strlen wcslen
strcpy wcscpy
itoa itow
atoi _wtoi
printf wprintf








And that, as they say, is all there is to it!