虽然东西都是现成的。但是也要脑子里有个概念。

// 地区与语言
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).

Qt Code:

  1. int main(int argc, char *argv[])
  2. {
  3. QCoreApplication a(argc, argv);
  4. QString unicodeString(QChar(0x9788));
  5. QTextStream qStdOut(stdout, QIODevice::WriteOnly);
  6. DWORD dwWritten;
  7.  
  8. // 1st try: replace oem with ascii
  9. #ifdef _WIN32
  10. std::cout << "Switch input to Ascii CodePage (1252): " << (::SetConsoleCP(::GetACP())?"ok":"fail") << std::endl;
  11. std::cout << "Switch output to Ascii CodePage (1252): " << (::SetConsoleOutputCP(::GetACP())?"ok":"fail") << std::endl;
  12. std::cout << "Current input CodePage: " << (unsigned int)::GetConsoleCP() << std::endl;
  13. std::cout << "Current output CodePage: " << (unsigned int)::GetConsoleOutputCP() << std::endl;
  14. #endif
  15. qStdOut << QString("QTextStream: ") << unicodeString << QChar('\n');
  16. qStdOut.flush();
  17. qStdOut.setCodec("UTF-16");
  18. qStdOut << QString("QTextStream: ") << unicodeString << QChar('\n');
  19. qStdOut.flush();
  20. std::cout << "cout: " << (char*)unicodeString.utf16() << std::endl;
  21. std::cout << "cout: " << (char*)(unicodeString.toUtf8().constData()) << std::endl;
  22. std::wcout << L"wcout: " << (wchar_t*)unicodeString.utf16() << std::endl;
  23. std::wcout << L"wcout: " << (char*)(unicodeString.toUtf8().constData()) << std::endl;
  24. printf("printf: %ls\n", unicodeString.utf16());
  25. wprintf(L"wprintf: %ls\n", unicodeString.utf16());
  26. #ifdef _WIN32
  27. WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"WriteConsoleW: ", 15, &dwWritten, NULL);
  28. WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), (unicodeString + '\n').utf16(), unicodeString.length()+1, &dwWritten, NULL);
  29. #endif
  30.  
  31. // 2nd try : set CP to utf-16
  32. #ifdef _WIN32
  33. std::cout << "\nSet input CP to ucs2: " << (::SetConsoleCP(1200)?"ok":"fail") << std::endl;
  34. std::cout << "Set output CP to ucs2: " << (::SetConsoleOutputCP(1200)?"ok":"fail") << std::endl;
  35. std::cout << "Current input codepage: " << (unsigned int)::GetConsoleCP() << std::endl;
  36. std::cout << "Current output codepage: " << (unsigned int)::GetConsoleOutputCP() << std::endl;
  37. #endif
  38. qStdOut << QString("QTextStream: ") << unicodeString << QChar('\n');
  39. qStdOut.flush();
  40. std::cout << "cout: " << (char*)unicodeString.utf16() << std::endl;
  41. std::wcout << L"wcout: " << (wchar_t*)unicodeString.utf16() << std::endl;
  42. printf("printf: %ls\n", unicodeString.utf16());
  43. wprintf(L"wprintf: %ls\n", unicodeString.utf16());
  44. WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"WriteConsoleW: ", 15, &dwWritten, NULL);
  45. WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), (unicodeString + '\n').utf16(), unicodeString.length()+1, &dwWritten, NULL);
  46.  
  47. // 3rd try : set CP to utf-8
  48. #ifdef _WIN32
  49. std::cout << "\nSet input CP to utf-8: " << (::SetConsoleCP(65001)?"ok":"fail") << std::endl;
  50. std::cout << "Set output CP to utf-8: " << (::SetConsoleOutputCP(65001)?"ok":"fail") << std::endl;
  51. std::cout << "Current input codepage: " << (unsigned int)::GetConsoleCP() << std::endl;
  52. std::cout << "Current output codepage: " << (unsigned int)::GetConsoleOutputCP() << std::endl;
  53. #endif
  54. qStdOut.setCodec("UTF-8");
  55. qStdOut << QString("QTextStream: ") << unicodeString << QChar('\n');
  56. qStdOut.flush();
  57. std::cout << "cout: " << (char*)unicodeString.toUtf8().constData() << std::endl;
  58. std::wcout << L"wcout: " << (char*)unicodeString.toUtf8().constData() << std::endl;
  59. printf("printf: %ls\n", unicodeString.toUtf8().constData());
  60. wprintf(L"wprintf: %ls\n", unicodeString.toUtf8().constData());
  61. #ifdef _WIN32
  62. WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"WriteConsoleW: ", 15, &dwWritten, NULL);
  63. WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), (unicodeString + '\n').utf16(), unicodeString.length()+1, &dwWritten, NULL);
  64. #endif
  65.  
  66. return a.exec();
  67. }
To copy to clipboard, switch view to plain text mode 

The resulting output is awfull...

Qt Code:

    1. Switch input to Ascii CodePage (1252): ok
    2. Switch output to Ascii CodePage (1252): ok
    3. Current input CodePage: 1252
    4. Current output CodePage: 1252
    5. Q T e x t S t r e a m : ˆ—
    6. cout: ˆ—
    7. cout: 鞈
    8. wcout: printf:
    9. wprintf: WriteConsoleW: 鞈
    10.  
    11. Set input CP to ucs2: fail
    12. Set output CP to ucs2: fail
    13. Current input codepage: 1252
    14. Current output codepage: 1252
    15. Q T e x t S t r e a m : ˆ—
    16. cout: ˆ—
    17. printf:
    18. wprintf: WriteConsoleW: 鞈
    19.  
    20. Set input CP to utf-8: ok
    21. Set output CP to utf-8: ok
    22. Current input codepage: 65001
    23. Current output codepage: 65001
    24. cout: printf:
    25. wprintf: WriteConsoleW: 鞈

http://www.qtcentre.org/threads/2344-Unicode-on-(Win32)-console

一些WinAPI 处理 字符的函数和连接(GetACP和SetThreadLocale最重要,还有SetConsoleCP)的更多相关文章

  1. 字符数组函数,连接strcat 复制函数strcpy 比较函数strcmp 长度函数 strlen

    之前我们学习数据类型的时候,有一个类型 char ,这个类型允许我们在里边放一个字符 char variable1='o'; char variable2='k'; #include <iost ...

  2. DB2字符处理函数

    转自:http://www.blogjava.net/bingle/archive/2007/07/11/129681.html ----------------------------------- ...

  3. 数据库Oracle字符处理函数

    练习字符处理函数(数据库表都是从1开始),我们用到一张"伪表" dual: dual 表:dual 是一张只有一个字段,一行记录的表.dual 表也称之为'伪表',因为他不存储主题 ...

  4. dedecms功能性函数封装(XSS过滤、编码、浏览器XSS hack、字符操作函数)

    dedecms虽然有诸多漏洞,但不可否认确实是一个很不错的内容管理系统(cms),其他也不乏很多功能实用性的函数,以下就部分列举,持续更新,不作过多说明.使用时需部分修改,你懂的 1.XSS过滤. f ...

  5. ctype.h库函数----字符操作函数

    在c++中使用时:  #include <cctype> 字符判断函数 1.isalnum函数--判断是否是英文字母或数字字符,如果是,则返回非0值,如果不是,则返回0. 函数参数 :可以 ...

  6. strtr和str_replace字符替换函数

    (一)strtr是字符替换函数 (1)单个字符替换: <?php echo strtr("abba", "ab", "10"),&qu ...

  7. 【C++实现python字符串函数库】二:字符串匹配函数startswith与endswith

    [C++实现python字符串函数库]字符串匹配函数startswith与endswith 这两个函数用于匹配字符串的开头或末尾,判断是否包含另一个字符串,它们返回bool值.startswith() ...

  8. MySQL中concat函数(连接字符串)

    MySQL中concat函数使用方法:CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...

  9. C语言字符串匹配函数

    C语言字符串匹配函数,保存有需要时可以用: #include <stdio.h> #include <stdlib.h> #include <string.h> # ...

随机推荐

  1. Percona Xtrabackup备份mysql大数据库(完整备份与增量备份)

    Percona Xtrabackup备份mysql大数据库(完整备份与增量备份)     文章目录 [隐藏] Xtrabackup简介 Xtrabackup安装 Xtrabackup工具介绍 inno ...

  2. python连接数据库自动发邮件

    python连接数据库实现自动发邮件 1.运行环境 redhat6 + python3.6 + crontab + Oracle客户端 2.用到的模块  3.操作步骤 (1)安装python3.6参考 ...

  3. LeetCode--142--环形链表II(python)

    给定一个链表,返回链表开始入环的第一个节点. 如果链表无环,则返回 null. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). 如果 pos 是 - ...

  4. postman-参数化

    1.txt 1.如图第一行为变量名,下面行为对应的值 2.设置 Pre-request-Script 参数 data为文件名,username.password自定义参数名:在Tests最好加上断言 ...

  5. HTML和CSS遇到的细节问题

    一.列表项标记窜出div盒子 列表项标记窜出盒子,是因为设置了 *; } ,消除了<li>元素的默认外边距. 结解决方法:消除*{}选择器或是设置外边距 列表项目标记与边距有关 二.div ...

  6. 用二叉树进行排序 x (从小到大)

    先输入n,表示拥有多少个数: 第二行输入1-n个数,然后开始排序 输出从小到大的排序. ----------------------------------------------代码~------- ...

  7. 小程序中css3实现优惠券

    效果如下: css3实现优惠券 知识储备 颜色渐变 linear-gradient() css伪类 :before :after index.wxss .app { /* padding: 20rpx ...

  8. VMware 15 搭建MacOS 10.14教程

    写于2018.12.23 教程原文链接:https://pan.baidu.com/s/1wvNYg_MQH_lwewKbpCQ5_Q ———————————————————————————————— ...

  9. php正则匹配汉字提取其它信息剔除和验证邮箱

    正则匹配汉字提取其它信息剔除demo <?php //提取字符串中的汉字其余信息剔除 $str='te,st 测 .试,.,.?!::·…~&@#,.?!:;.……-&@#“” ...

  10. python 调用C++ DLL,传递int,char,char*,数组和多维数组

    ctypes 数据类型和 C数据类型 对照表 ctypes type C type Python type c_bool _Bool bool (1) c_char char 1-character ...