以下のコードを使用してC#コードを使用してフォントをインストールしようとしています。
InstallFontを呼び出しても、例外はスローされず、1が返されます。これは、フォントがインストールされていることを示していると思います。ただし、Windows FontsフォルダーまたはInstalledFontCollectionをチェックしたときに、インストールされているフォントのリストにフォントが表示されません。また、ソフトウェアにも表示されません。インストール後にコンピューターを再起動しようとしましたが、まだ利用できません。
Windowsエクスプローラーでダブルクリックし、[フォントのインストール]をクリックしてファイルを手動でインストールすると、問題なくインストールされます。
Windows 7 64ビットオペレーティングシステムでC#、Visual Studio 2010、Microsoft .NETFramework4.0を使用しています。
どんな助けでも大歓迎です。
どうもありがとう、ポール
マニフェストファイルには次のものが含まれます。
requestedExecutionLevel level="requireAdministrator" uiAccess="false"
アプリケーションコード:
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
[DllImport("gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)]
public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
public static int InstallFont()
{
InstalledFontCollection ifc = new InstalledFontCollection();
if (ifc.Families.Any(item => item.Name == "Arial Narrow"))
return 100; // Font already installed
string filename = @"C:\Users\username\Downloads\ARIALN.TTF";
const int WM_FONTCHANGE = 0x001D;
const int HWND_BROADCAST = 0xffff;
int added = AddFontResource(filename);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
return added;
}