为什么我不能将字体文件复制到c:\Windows\Fonts认为复制文件

Why i can't copy a font file to c:WindowsFonts thought CopyFile

本文关键字:文件 复制 Windows Fonts 不能 字体 为什么      更新时间:2023-10-16

我想在我的系统中安装一个新字体,但我的代码出现了问题,我找不出我犯了什么错误。在我调用CopyFile后,该文件在C:\Windows\Fonts中不存在。你能给我一些建议吗?非常感谢。这是我的代码:

`//the source file
string sSourceDir = "F:\my_job\font\";
//the file name
string sFontFileName = "jdqw.TTF";
string sFontName = "jdqw";
TCHAR sWinDir[MAX_PATH];
GetWindowsDirectory(sWinDir, MAX_PATH);
string sFontDir(sWinDir);
//make the path like C:\Windows\Fonts
sFontDir += "\Fonts\";
string sFOTFile = sFontDir;
sFOTFile += sFontFileName.substr(0, sFontFileName.length() - 4);
sFOTFile += ".FOT";
string source = sSourceDir;
string dest = sFontDir;
source += sFontFileName;
dest += sFontFileName;
//copy file
cout << source.c_str() << "   " << dest.c_str() << endl;
cout << CopyFile(source.c_str(), dest.c_str(), FALSE) << endl;
cout << GetLastError() << endl;`

Michael Kaplan有一个很好的描述。简而言之,您不能也不应该在那里复制文件,因为它是一个虚拟视图。相反,使用适当的方法:调用AddFontResourceEx,传递适当的标志。如果字体在系统范围内可用,则广播WM_FONTCHANGE。要永久安装字体,您需要管理员权限(即UAC提升),因为您需要在HKLMSOFTWAREMicrosoftWindows NTCurrentVersionFonts下列出字体文件名。

您可能需要考虑在安装程序中执行这些步骤,因为安装程序通常具有必要的权限。