C++ 如何更改控制台字体?

C++ 如何更改控制台字体?,c++,unicode,windows-xp,console,codepages,C++,Unicode,Windows Xp,Console,Codepages,我在Windows XP控制台中的输出Unicode有问题。 (Microsoft Windows XP[版本5.1.2600]) 第一个代码是(来自) 我的代码页是65001(CP_UTF8)。除外Ⴂ, 每封信看起来都不错。但是Ⴂ 它看起来像正方形。 Console的默认字体“Lucida Console”没有该字母的字体。 因此,我下载了一些其他字体,可以呈现Ⴂ 正确,但我无法更改(VisualStudio2005项目)控制台字体 我更改了HKEY_CURRENT_USER\Console

我在Windows XP控制台中的输出Unicode有问题。 (Microsoft Windows XP[版本5.1.2600]) 第一个代码是(来自)


我的代码页是65001(CP_UTF8)。除外Ⴂ, 每封信看起来都不错。但是Ⴂ 它看起来像正方形。 Console的默认字体“Lucida Console”没有该字母的字体。 因此,我下载了一些其他字体,可以呈现Ⴂ 正确,但我无法更改(VisualStudio2005项目)控制台字体

我更改了HKEY_CURRENT_USER\Console\%SystemRoot%\u system32\u cmd.exe\FontName,但当我检查提示符的属性->字体时,它设置为“Lucida Console”。 有没有办法用API更改控制台字体

下一个代码就是我尝试的代码。但它不起作用。救命啊

#include "stdafx.h" #include "Windows.h" #include using namespace std; // Conventional wisdom is retarded, aka What the @#%&* is _O_U16TEXT? // http://www.siao2.com/2008/03/18/8306597.aspx int main() { locale::global(locale("")); // Windows Command Prompt use code page 850, // probably for backwards compatibility with old DOS programs. // Unicode at the Windows command prompt (C++; .Net; Java) // http://illegalargumentexception.blogspot.com/2009/04/i18n-unicode-at-windows-command-prompt.html // INFO: SetConsoleOutputCP Only Effective with Unicode Fonts // http://support.microsoft.com/kb/99795 // Undocumented API : SetConsoleFont // http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html typedef BOOL (WINAPI *FN_SETCONSOLEFONT)(HANDLE, DWORD); FN_SETCONSOLEFONT SetConsoleFont; HMODULE hm = GetModuleHandle(_T("KERNEL32.DLL")); SetConsoleFont = (FN_SETCONSOLEFONT) GetProcAddress(hm, "SetConsoleFont"); int fontIndex = 10; // 10 is known to identify Lucida Console (a Unicode font) BOOL bRet = SetConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE), fontIndex); // http://stackoverflow.com/questions/1922294/using-unicode-font-in-c-console-app //const UINT codePage = CP_UTF8; // const UINT codePage = 1200; // 1200(utf-16 Unicode) SetConsoleOutputCP(codePage); wchar_t s[] = L"èéøÞǽлљΣæča\n"; int bufferSize = WideCharToMultiByte(codePage, 0, s, -1, NULL, 0, NULL, NULL); char* m = new char[bufferSize]; WideCharToMultiByte(codePage, 0, s, -1, m, bufferSize, NULL, NULL); // 0x00000459 "No mapping for the Unicode character exists in the target multi-byte code page." wprintf(L"%S", m); // it doesn't work wprintf(L"%s", s); // it work a bit // after L'Ⴂ' letter, wcout failed! wcout #包括“stdafx.h” #包括“Windows.h” #包括 使用名称空间std; //传统智慧是迟钝的,也就是说,%&*是什么? // http://www.siao2.com/2008/03/18/8306597.aspx int main(){ 区域设置::全局(区域设置(“”); //Windows命令提示符使用代码页850, //可能是为了向后兼容旧的DOS程序。 //Windows命令提示符下的Unicode(C++;.Net;Java) // http://illegalargumentexception.blogspot.com/2009/04/i18n-unicode-at-windows-command-prompt.html //信息:SetConsoleOutputCP仅对Unicode字体有效 // http://support.microsoft.com/kb/99795 //未记录的API:SetConsoleFont // http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html typedef BOOL(WINAPI*FN_SETCONSOLEFONT)(句柄,DWORD); FN_SETCONSOLEFONT SETCONSOLEFONT; HMODULE hm=GetModuleHandle(_T(“KERNEL32.DLL”); SetConsoleFont=(FN_SetConsoleFont)GetProcAddress(hm,“SetConsoleFont”); int fontIndex=10;//10已知可识别Lucida控制台(Unicode字体) BOOL-bRet=SetConsoleFont(GetStdHandle(标准输出句柄),fontfindex); // http://stackoverflow.com/questions/1922294/using-unicode-font-in-c-console-app //consuint codePage=CP_UTF8// const UINT codePage=1200;//1200(utf-16 Unicode) SetConsoleOutputCP(代码页); wchar_t s[]=L“èèèèèèèèèèèèèèè23; int bufferSize=WideCharToMultiByte(代码页,0,s,-1,NULL,0,NULL,NULL); char*m=新字符[bufferSize]; WideChartMultiByte(代码页,0,s,-1,m,缓冲区大小,NULL,NULL); //0x00000459“目标多字节代码页中不存在Unicode字符的映射。” wprintf(L“%S”,m);//它不工作 wprintf(L“%s”,s);//它可以工作一点 //在我死后Ⴂ' 信,wcout失败! wcout
顺便说一句,当我把“include”放在“code tag”中时,带有in(fcntl.h)的部分消失了。我如何放置系统include?

通过谷歌在这里找到这些说明:

默认情况下,上的属性 cmd.exe窗口允许您选择 光栅字体或Lucida控制台。 您可以将其他单空格字体添加到 通过注册表查看列表

在regedit中,导航到

HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\
Console\TrueTypeFont

请注意,Lucida Console已经在运行 在该键下,名称为“0”

使用名称添加新的sting值 “00”(是的,这是必需的名称) 并将数据设置为 monospace字体已安装在中 您的C:\Windows\Fonts文件夹。在此 例如,我添加了Consolas字体 似乎需要额外的条目 名称“000”、“0000”等,如 “1”和“2”不起作用,对皮特来说 为什么

打开一个新的cmd窗口,右键单击 在系统菜单上,选择属性 |字体,还有新添加的 字体

我这样做是因为我想要更多 我的PowerShell的可读字体 窗户,自从我花了一些 是时候盯着它看了

资料来源:ferncrk.com

我按照说明,将Console作为cmd的默认字体。它按预期工作


请注意,它只接受单间距字体。

谢谢您更改字体。但是,我找不到任何可以显示L'的unicode固定间距字体Ⴂ' (x10a0)。Lucida Console将其显示为[]。我发现了一种名为Everson Mono的字体,支持格鲁吉亚语,但出于某种原因,cmd会自动拒绝它。您可能会更幸运地将其带到superuser.com。这不是编程问题,而是Windows配置的问题。SetConsoleOutputCP(1200)返回false,因为不接受1200作为有效代码页。 #include "stdafx.h" #include "Windows.h" #include using namespace std; // Conventional wisdom is retarded, aka What the @#%&* is _O_U16TEXT? // http://www.siao2.com/2008/03/18/8306597.aspx int main() { locale::global(locale("")); // Windows Command Prompt use code page 850, // probably for backwards compatibility with old DOS programs. // Unicode at the Windows command prompt (C++; .Net; Java) // http://illegalargumentexception.blogspot.com/2009/04/i18n-unicode-at-windows-command-prompt.html // INFO: SetConsoleOutputCP Only Effective with Unicode Fonts // http://support.microsoft.com/kb/99795 // Undocumented API : SetConsoleFont // http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html typedef BOOL (WINAPI *FN_SETCONSOLEFONT)(HANDLE, DWORD); FN_SETCONSOLEFONT SetConsoleFont; HMODULE hm = GetModuleHandle(_T("KERNEL32.DLL")); SetConsoleFont = (FN_SETCONSOLEFONT) GetProcAddress(hm, "SetConsoleFont"); int fontIndex = 10; // 10 is known to identify Lucida Console (a Unicode font) BOOL bRet = SetConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE), fontIndex); // http://stackoverflow.com/questions/1922294/using-unicode-font-in-c-console-app //const UINT codePage = CP_UTF8; // const UINT codePage = 1200; // 1200(utf-16 Unicode) SetConsoleOutputCP(codePage); wchar_t s[] = L"èéøÞǽлљΣæča\n"; int bufferSize = WideCharToMultiByte(codePage, 0, s, -1, NULL, 0, NULL, NULL); char* m = new char[bufferSize]; WideCharToMultiByte(codePage, 0, s, -1, m, bufferSize, NULL, NULL); // 0x00000459 "No mapping for the Unicode character exists in the target multi-byte code page." wprintf(L"%S", m); // it doesn't work wprintf(L"%s", s); // it work a bit // after L'Ⴂ' letter, wcout failed! wcout