问题描述
无法弄清楚为什么这段代码无效。 没有提到我需要设置cbSize属性。我记得在另一个函数上看到它需要,我猜这是Windows API中的常见做法。
Couldn't figure out why this code wasn't working. The documentation didn't mention that I needed to set the cbSize property. I remember seeing it needed on another function, and I'm guessing that's common practice in the Windows API.
#include <Windows.h>
#include <iostream>
int main()
{
CONSOLE_FONT_INFOEX cfo;
cfo.cbSize = sizeof(CONSOLE_FONT_INFOEX); //Forgot this line. Here's the bug.
if(!::GetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfo)) {
std::wcout << GetLastError() << std::endl;
return -1;
}
std::wcout << cfo.FaceName << std::endl;
return 0;
}
推荐答案
您好,
感谢您在此发帖。
Thank you for posting here.
>>无法弄清楚为什么此代码无效。文档没有提到我需要设置cbSize属性。我记得在另一个函数上看到它需要,我猜这是Windows API中的常见做法。
>>Couldn't figure out why this code wasn't working. The documentation didn't mention that I needed to set the cbSize property. I remember seeing it needed on another function, and I'm guessing that's common practice in the Windows API.
CONSOLE_FONT_INFOEX结构接收到请求的字体信息和结构包含cbsize, 这个结构的大小,以字节为单位。我建议你可以参考这个
链接,或等待 。$
The CONSOLE_FONT_INFOEX structure receives the requested font information and the structure contains cbsize, which is the size of this structure, in bytes. I suggest you could refer to thislink, or wait for the feedback.
祝福,
Jeanine Zhang
Jeanine Zhang
这篇关于GetCurrentConsoleFontEx:我做错了什么? NVM,发现它。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!