一些WinAPI 处理 字符的函数和连接(GetACP和SetThreadLocale最重要,还有SetConsoleCP)
虽然东西都是现成的。但是也要脑子里有个概念。
// 地区与语言
GetACP 取得 ANSI code page,法语XP+设置中文内核 = 936 // ShowMessage(IntToStr(GetACP));
GetThreadLocale 法语XP+设置中文内核 = 2052,纯法语 1036 // ShowMessage(IntToStr(GetThreadLocale));
SetThreadLocale
SetConsoleCP
ConvertDefaultLocale
SetLocaleInfo
GetLocaleInfo
GetLocaleInfoEx
GetCPInfo
MAKELCID
GetSystemDefaultLCID = 2052
GetUserDefaultLCID = 2052
LCIDToLocaleName
GetUserDefaultLocaleName // vista
GetSystemDefaultLocaleName
GetSystemDefaultLocaleName
LCIDToLocaleName
LCMapStringEx
National Language Support Functions
http://msdn.microsoft.com/en-us/library/windows/desktop/dd319081(v=vs.85).aspx
Code Page Identifiers
http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx
GetCharABCWidths
GetCharWidth32
--------------------------------------------------------------------------------------------------------
After googling a lot, I saw that lot of people have problems displaying unicode on the console. But I didn't found a solution.
I read that :
1. the console font must be set to lucida TT.
2. the code page must be forced to 1252 (or 65001 for utf-8).
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- QTextStream qStdOut(stdout, QIODevice::WriteOnly);
- DWORD dwWritten;
- // 1st try: replace oem with ascii
- #ifdef _WIN32
- std::cout << "Switch input to Ascii CodePage (1252): " << (::SetConsoleCP(::GetACP())?"ok":"fail") << std::endl;
- std::cout << "Switch output to Ascii CodePage (1252): " << (::SetConsoleOutputCP(::GetACP())?"ok":"fail") << std::endl;
- std::cout << "Current input CodePage: " << (unsigned int)::GetConsoleCP() << std::endl;
- std::cout << "Current output CodePage: " << (unsigned int)::GetConsoleOutputCP() << std::endl;
- #endif
- qStdOut.flush();
- qStdOut.setCodec("UTF-16");
- qStdOut.flush();
- std::cout << "cout: " << (char*)unicodeString.utf16() << std::endl;
- std::cout << "cout: " << (char*)(unicodeString.toUtf8().constData()) << std::endl;
- std::wcout << L"wcout: " << (wchar_t*)unicodeString.utf16() << std::endl;
- std::wcout << L"wcout: " << (char*)(unicodeString.toUtf8().constData()) << std::endl;
- printf("printf: %ls\n", unicodeString.utf16());
- wprintf(L"wprintf: %ls\n", unicodeString.utf16());
- #ifdef _WIN32
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"WriteConsoleW: ", 15, &dwWritten, NULL);
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), (unicodeString + '\n').utf16(), unicodeString.length()+1, &dwWritten, NULL);
- #endif
- // 2nd try : set CP to utf-16
- #ifdef _WIN32
- std::cout << "\nSet input CP to ucs2: " << (::SetConsoleCP(1200)?"ok":"fail") << std::endl;
- std::cout << "Set output CP to ucs2: " << (::SetConsoleOutputCP(1200)?"ok":"fail") << std::endl;
- std::cout << "Current input codepage: " << (unsigned int)::GetConsoleCP() << std::endl;
- std::cout << "Current output codepage: " << (unsigned int)::GetConsoleOutputCP() << std::endl;
- #endif
- qStdOut.flush();
- std::cout << "cout: " << (char*)unicodeString.utf16() << std::endl;
- std::wcout << L"wcout: " << (wchar_t*)unicodeString.utf16() << std::endl;
- printf("printf: %ls\n", unicodeString.utf16());
- wprintf(L"wprintf: %ls\n", unicodeString.utf16());
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"WriteConsoleW: ", 15, &dwWritten, NULL);
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), (unicodeString + '\n').utf16(), unicodeString.length()+1, &dwWritten, NULL);
- // 3rd try : set CP to utf-8
- #ifdef _WIN32
- std::cout << "\nSet input CP to utf-8: " << (::SetConsoleCP(65001)?"ok":"fail") << std::endl;
- std::cout << "Set output CP to utf-8: " << (::SetConsoleOutputCP(65001)?"ok":"fail") << std::endl;
- std::cout << "Current input codepage: " << (unsigned int)::GetConsoleCP() << std::endl;
- std::cout << "Current output codepage: " << (unsigned int)::GetConsoleOutputCP() << std::endl;
- #endif
- qStdOut.setCodec("UTF-8");
- qStdOut.flush();
- std::cout << "cout: " << (char*)unicodeString.toUtf8().constData() << std::endl;
- std::wcout << L"wcout: " << (char*)unicodeString.toUtf8().constData() << std::endl;
- printf("printf: %ls\n", unicodeString.toUtf8().constData());
- wprintf(L"wprintf: %ls\n", unicodeString.toUtf8().constData());
- #ifdef _WIN32
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"WriteConsoleW: ", 15, &dwWritten, NULL);
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), (unicodeString + '\n').utf16(), unicodeString.length()+1, &dwWritten, NULL);
- #endif
- return a.exec();
- }
The resulting output is awfull...
- Switch input to Ascii CodePage (1252): ok
- Switch output to Ascii CodePage (1252): ok
- Current input CodePage: 1252
- Current output CodePage: 1252
- QTextStream: ?
- Q T e x t S t r e a m : ˆ—
- cout: ˆ—
- cout: 鞈
- wcout: printf:
- wprintf: WriteConsoleW: 鞈
- Set input CP to ucs2: fail
- Set output CP to ucs2: fail
- Current input codepage: 1252
- Current output codepage: 1252
- Q T e x t S t r e a m : ˆ—
- cout: ˆ—
- printf:
- wprintf: WriteConsoleW: 鞈
- Set input CP to utf-8: ok
- Set output CP to utf-8: ok
- Current input codepage: 65001
- Current output codepage: 65001
- QTextStream: 鞈
- cout: printf:
- wprintf: WriteConsoleW: 鞈
http://www.qtcentre.org/threads/2344-Unicode-on-(Win32)-console
一些WinAPI 处理 字符的函数和连接(GetACP和SetThreadLocale最重要,还有SetConsoleCP)的更多相关文章
- 字符数组函数,连接strcat 复制函数strcpy 比较函数strcmp 长度函数 strlen
之前我们学习数据类型的时候,有一个类型 char ,这个类型允许我们在里边放一个字符 char variable1='o'; char variable2='k'; #include <iost ...
- DB2字符处理函数
转自:http://www.blogjava.net/bingle/archive/2007/07/11/129681.html ----------------------------------- ...
- 数据库Oracle字符处理函数
练习字符处理函数(数据库表都是从1开始),我们用到一张"伪表" dual: dual 表:dual 是一张只有一个字段,一行记录的表.dual 表也称之为'伪表',因为他不存储主题 ...
- dedecms功能性函数封装(XSS过滤、编码、浏览器XSS hack、字符操作函数)
dedecms虽然有诸多漏洞,但不可否认确实是一个很不错的内容管理系统(cms),其他也不乏很多功能实用性的函数,以下就部分列举,持续更新,不作过多说明.使用时需部分修改,你懂的 1.XSS过滤. f ...
- ctype.h库函数----字符操作函数
在c++中使用时: #include <cctype> 字符判断函数 1.isalnum函数--判断是否是英文字母或数字字符,如果是,则返回非0值,如果不是,则返回0. 函数参数 :可以 ...
- strtr和str_replace字符替换函数
(一)strtr是字符替换函数 (1)单个字符替换: <?php echo strtr("abba", "ab", "10"),&qu ...
- 【C++实现python字符串函数库】二:字符串匹配函数startswith与endswith
[C++实现python字符串函数库]字符串匹配函数startswith与endswith 这两个函数用于匹配字符串的开头或末尾,判断是否包含另一个字符串,它们返回bool值.startswith() ...
- MySQL中concat函数(连接字符串)
MySQL中concat函数使用方法:CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...
- C语言字符串匹配函数
C语言字符串匹配函数,保存有需要时可以用: #include <stdio.h> #include <stdlib.h> #include <string.h> # ...
随机推荐
- 前端面试题常考&必考之--跨域的解决办法
1.为啥出现跨域??? 在制定Html规则时,为了安全的考虑,一个源的脚本(网页,网站)不能与另一个源的资源进行交互, 所以就引发一个词叫做“同源策略”. 同源策略:同源策略是一种约定,它是浏览器最核 ...
- mysql LIKE通配符 语法
mysql LIKE通配符 语法 作用:用于在 WHERE 子句中搜索列中的指定模式.惠州大理石平板 语法:SELECT column_name(s) FROM table_name WHERE co ...
- Element ui 中的表格数据格式转换
- 洛谷 P3496 BZOJ 2079 [POI2010]GIL-Guilds
题目描述 King Byteasar faces a serious matter. Two competing trade organisations, The Tailors Guild and ...
- uploadify上传插件参数的一些设置
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [CERC2016]:凸轮廓线Convex Contour(模拟+数学)
题目描述 一些几何图形整齐地在一个网格图上从左往右排成一列.它们占据了连续的一段横行,每个位置恰好一个几何图形.每个图形是以下的三种之一:$1.$一个恰好充满单个格子的正方形.$2.$一个内切于单个格 ...
- [CSP-S模拟测试]:玩具(概率DP)
题目描述 这个故事发生在很久以前,在$IcePrincess\text{_}1968$和$IcePrince\text{_}1968$都还在上幼儿园的时候. $IcePrince\text{_}196 ...
- 论文keywords和规则匹配的baseline
详细的思路可以参照小论文树立0317 关键词分为以下几类: t/****一些通用的过滤词,这些通用的过滤词可以使用和节目一起出现的词语,结合tf-idf看出来么?*****/ public st ...
- 解决axios异步问题
- k8s上的基础概念和术语
kubernetes基本概念和术语 kubeernetes中的大部分概念如Node,Pod,Replication Controller ,Serverce等都可以看作一种“资源对象”,几乎所有的 ...