使用AddFontResource()临时添加到系统字体表中的字体的C++查找索引,以便在控制台中使用
C++ Finding Index for Font temporarily added to System Font Table with AddFontResource() to use in Console
我正在尝试临时安装一种字体,以便在带有的win32控制台中使用
int AddFontResource(LPCTSTR lpszFilename);
和
BOOL WINAPI SetConsoleFont(HANDLE hOutput, DWORD fontIndex)
我从这个网站上获得了这个功能。
尽管这两个函数似乎都很好用,但我不知道如何找到添加的字体索引来与SetConsoleFont
一起使用。
AddFontResource
不返回临时字体的索引值或关键字。
这是我的相关代码:
#include "Level.h"
#include "ConsoleFont.h" //acquired from above mentioned site
#include <Windows.h>
//-------------------------------------------------------------------------------
void init();
void cleanup();
int main()
{
FileManager *pFileManager = new FileManager(); //unrelated
Level *lvl1 = new Level("filename",pFileManager); //unrelated
///TEMPORARY PLANNING
// using add font resource. how can i get this fonts index value?
int err = AddFontResource(L"Files/gamefont.fnt");
if (err == 0)
{
MessageBox(NULL,L"loading font failed",L"Error",0);
}
else
{
wchar_t message[100];
swprintf_s(message,100,L"AddFontResource returned: %d",err);
MessageBox(NULL,LPTSTR(message),L"error",0);
}
SendMessage(HWND_BROADCAST, WM_FONTCHANGE,0,0);
//acquiring handle to current active screen buffer
HANDLE tempHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if (tempHandle == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,L"Failed to aquire Screen Buffer handle",L"Error",0);
}
//I dont know what to set this to. this is the crux of the problem.
DWORD fontIndex = 1;
if (FALSE == SetConsoleFont(tempHandle,fontIndex))
{
MessageBox(NULL,L"loading console font failed",L"Error",0);
}
//draws a house when in correct font
std::cout<<"!!!!!!!!#n"
<<"!!!!!!!!!n"
<<"! !! !! !n"
<<"!!!!!!!!!n"
<<"! !! !! !n"
<<"!!!!!!!!!n"
<<"! !! !! !n"
<<"!!!!!!!!!n"
<<"! !! !! !#n"
<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
///PLANNING OVERS
bool quit = false;
while(!quit)
{
//still to be implemented
}
err = RemoveFontResource(L"Files/gamefont.fnt");
if (err==0)
{
MessageBox(NULL,L"removing font failed",L"Error",0);
}
return 0;
}
我不知道如何找到我的新字体的索引值,甚至不知道使用我目前的方法是否可行。
如果有人知道或有更好的方法,请帮我。感谢任何帮助或提示。必须能够在win32控制台中使用自定义字体,而无需篡改注册表。我确信:(
不幸的是,您进入了Win API的黑暗世界。没有用于控制台字体表查找的文档(或者至少我永远找不到(。您可以尝试方法"GetNumberOfConsoleFonts(("来查看返回的内容。我认为索引10处的字体是Lucida Console。你得四处走走。此外,这可能不适用于您的操作系统版本。在XP上为我工作。从未尝试过其他任何东西。老实说,它也从未在XP上完全运行过。
对于注册表,
字体注册在这里:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionFonts
控制台注册表在这里:
HKEY_CURRENT_USERConsole
如果您最终修改了注册表,这些更改可能不会立即反映出来。您需要重新启动控制台或发送一条特殊的WM_*消息(对不起,不记得名称(。
如果你能找到一个解决方案/解决方法,那就太好了:(
int err = AddFontResource(L"Files/gamefont.fnt");
if (err == 0)
{
MessageBox(NULL,L"loading font failed",L"Error",0);
}
else
{
wchar_t message[100];
swprintf_s(message,100,L"AddFontResource returned: %d",err);
MessageBox(NULL,LPTSTR(message),L"error",0);
}
这是错误的AddFontResource返回加载的字体数,所以ELSE中的代码没有意义。
相关文章:
- 数组索引的值没有增加
- 在C++中测量postscript字体宽度
- 芬威克树(BIT).找到具有给定累积频率的最小索引,单位为 O(logN)
- 查找最接近的大于当前数字的数字的索引
- 在C++中调整向量中的索引
- 重载元组索引运算符-C++
- 给定一个向量,如何找到该向量的所有子集和的原始索引
- 为std::string的某个索引赋值
- 并行用于C++17中数组索引范围内的循环
- 如何在Directwrite中获得给定字体的可用OpenType功能
- 跟随整数索引列表的自定义类迭代器
- 如何在for循环中包含两个索引值的测试条件
- D3D11-将混合权重和索引传递到顶点着色器
- 将转换字符键入 int 以用作向量C++的索引
- 在 C++ 中访问数组负索引处的内存不会返回垃圾
- 如何为圆环创建索引
- 在子集化后将包含索引号的列表列表映射到标准索引序列
- 查找字符在两个索引之间出现的次数
- Azure Kinect 使用正文索引映射裁剪正文
- 使用AddFontResource()临时添加到系统字体表中的字体的C++查找索引,以便在控制台中使用