use*_*006 5 c c++ windows console winapi
如何在运行时确保命令提示符的当前字体是默认的Raster字体?我正在使用C++和WinApi.
现在我已经使用GetConsoleFontEx();和SetConsoleFontEx();,但我一直没能找到的正确的价值CONSOLE_FONT_INFOEX的FaceName财产.我在网上找到了一些字体设置为Lucida和/或Consolas的例子,但这不是我想要的.
这是我当前代码的片段:
COORD fs = {8, 8};
CONSOLE_FONT_INFOEX cfie = {0};
cfie.cbSize = sizeof(cfie);
GetCurrentConsoleFontEx(hOut, 0, &cfie);
char fn[] = "Raster"; // Not really doing anything
strcpy_s((char*)cfie.FaceName, 32, fn); // Not sure if this is right
cfie.dwFontSize.X = fs.X;
cfie.dwFontSize.Y = fs.Y;
SetCurrentConsoleFontEx(hOut, 0, &cfie);
Run Code Online (Sandbox Code Playgroud)
我已经测试了返回值SetCurrentConsoleFontEx(),并且它非零,表示调用成功.但是,字体不会改变.
适应MS例子中SetCurrentConsoleFontEx(),这似乎工作.请注意,Enter按下提示时,整个控制台会更改字体.
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** args)
{
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = 20;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
printf("A quick brown fox jumps over the lazy dog\n");
printf("Setting to Lucida Console: press <Enter> ");
getchar();
wcscpy(cfi.FaceName, L"Lucida Console");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
printf("Setting to Consolas: press <Enter> ");
getchar();
wcscpy(cfi.FaceName, L"Consolas");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
printf("Press <Enter> to exit");
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3890 次 |
| 最近记录: |