- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试临时安装一种字体以在 win32 控制台中使用
int AddFontResource(LPCTSTR lpszFilename);
和
BOOL WINAPI SetConsoleFont(HANDLE hOutput, DWORD fontIndex)
我从 this 得到这个函数网站。
虽然这两个函数似乎都可以正常工作,但我不知道如何找到添加的字体索引以与 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_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
控制台注册表在这里:
HKEY_CURRENT_USER\Console
如果您最终修改注册表,所做的更改可能不会立即反射(reflect)出来。您需要重新启动控制台或发送特殊的 WM_* 消息(抱歉不记得名字了)。
如果您能找到解决方案/解决方法,那就太好了:)
关于C++ 使用 AddFontResource() 临时添加到系统字体表中以在控制台中使用的字体查找索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15733596/
我目前正尝试在一堆服务器上安装字体。我已经能够使用脚本来复制字体并将它们“安装”到服务器上,但我需要能够访问字体而无需必须关闭服务器或注销帐户。 我发现 Windows AddFontResource
可以看到here , 函数 AddFontResource()要求应用程序发送 WM_FONTCHANGE向系统中的所有顶层窗口发送消息,但 AddFontResourceEx()功能不需要这个。为什
我正在尝试临时安装一种字体以在 win32 控制台中使用 int AddFontResource(LPCTSTR lpszFilename); 和 BOOL WINAPI SetConsoleFont
我正在尝试将控制台字体更改为自定义字体,但这段特定的代码片段似乎没有完成任何事情,尽管这是我在尝试在 Internet 上寻找解决方案时想到的。我通过手动安装并将其添加到带有注册表的控制台,仅使用此自
我正在使用 AddFontResource函数为当前登录 session 在本地安装字体。 private void installFont(string fontPath) { IntPtr H
我正在维护 .NET 3.5 应用程序。在应用程序启动期间,从工作目录中读取许多字体并在 Windows 中注册。我们对每个字体文件使用 AddFontResource(string lpFileNa
我正在尝试使用以下代码使用 C# 代码安装字体。 调用 InstallFont 不会抛出任何异常并返回 1。我认为这表明它已经安装了字体。但是,无论是在 Windows 字体文件夹中还是在检查 Ins
如何在 Linux 上安装自定义字体,直接从 C++ 或使用 system命令? 我的意思是像 AddFontResource 这样的方式在窗口中。 最佳答案 答案取决于分发和运行程序的工作流程。如果
我是一名优秀的程序员,十分优秀!