[英]How can I get a list of installed fonts on Windows including font style using c++
[英]Why i can't copy a font file to c:\Windows\Fonts 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提升),因為您需要在HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts
出字體文件名。
您可能要考慮從安裝程序執行這些步驟,因為通常以必需的權限運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.