为什么我不能将字体文件复制到c:\Windows\Fonts认为复制文件
Why i can't copy a font file to c:WindowsFonts thought CopyFile
我想在我的系统中安装一个新字体,但我的代码出现了问题,我找不出我犯了什么错误。在我调用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
下列出字体文件名。
您可能需要考虑在安装程序中执行这些步骤,因为安装程序通常具有必要的权限。
相关文章:
- 如何使用位字段将数据从二进制文件复制到结构中?
- 将文件复制到自定义位置,存在字符串转换问题
- 无法将整个文本文件复制到字符数组
- 使用 Libssh 将文件从服务器复制到客户端:分配文件复制目标路径时出现问题
- 将文本从一个文件复制到另一个c++流时出错
- 如何检查文件复制和写入是否成功
- 将文件复制到 pro/pri 文件中的新目录
- C++可以从文本文件复制并粘贴到打开的Word程序中
- 如何使用 c++ 文件系统库将文件复制到另一个目录
- 将.bin输入文件复制到 linux 中
- CMake:将头文件复制到输出目录
- 如何将文件复制到另一个文件中,但是用用户输入的单词替换单词
- 仅将所需的数据从一个大文件复制到另一个大文件
- catkin_make无法创建可执行文件,并自动将标题文件复制到DEVEL
- QT-将文件复制到AppData
- 将文件复制到另一个目录不起作用
- 使用boost递归地将给定目录中每个最低级别文件夹的文件复制到另一个目录-C++
- 在 c++ 中将整个.txt文件复制到 char 数组中
- 将二进制文件复制到C++中的远程位置
- 我试图运行将文本从一个文件复制到另一个文件的程序