RE: Install font from ClickOnce application
- From: jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Fri, 22 Sep 2006 08:24:31 GMT
Hi Thomas,
Thanks for the feedback.
Actually, ClickOnce is only a deployment technology, it does not offer any
support for font installation currently, since this operation requires
extra coding. We have to code the font installation logic in the
application. So this question is not a ClickOnce specific.
Based on my test using the code snippet below, after I called InstallFont,
the Word application can use the font without any problem, so I think it
should work for Excel application. But without restarting the application,
the .Net winform application still can not use it. , do you get different
result? My testing machine is Win2003 SP1.
private void button1_Click(object sender, EventArgs e)
{
InstallFont();
}
internal static void InstallFont()
{
string fontsPath = GetFontsPath();
string ttfFile = System.IO.Path.Combine(fontsPath, "cookiehollow.ttf");
System.IO.File.Copy(@"C:\cookiehollow.ttf", ttfFile);
int ret;
if (System.IO.File.Exists(ttfFile))
{
//Add font resource
ret = AddFontResource(ttfFile);
//Add registry entry so the font is also available next session
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Fonts",
"Cookie Hollow Regular (TrueType)", "cookiehollow.ttf",
RegistryValueKind.String);
//Broadcast to let all top-level windows know about change
ret = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, new IntPtr(0), new
IntPtr(0));
}
}
// PInvoke to look up fonts path
[System.Runtime.InteropServices.DllImport("shfolder.dll", CharSet =
System.Runtime.InteropServices.CharSet.Auto)]
private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, StringBuilder lpszPath);
private const int CSIDL_FONTS = 0x0014;
private const int MAX_PATH = 260;
private static string GetFontsPath()
{
StringBuilder sb = new StringBuilder(MAX_PATH);
SHGetFolderPath(IntPtr.Zero, CSIDL_FONTS, IntPtr.Zero, 0, sb);
return sb.ToString();
}
// PInvoke to 'register' fonts and broadcast addition
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern int AddFontResource(string lpszFilename);
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern int CreateScalableFontResource(uint fdwHidden, string
lpszFontRes, string lpszFontFile, string lpszCurrentPath);
private static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
private const uint WM_FONTCHANGE = 0x001D;
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet
=System.Runtime.InteropServices.CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
private void button2_Click(object sender, EventArgs e)
{
this.button2.Font = new Font("CookieHollow", 10, FontStyle.Regular);
}
Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- RE: Install font from ClickOnce application
- From: Thomas Taylor
- RE: Install font from ClickOnce application
- References:
- RE: Install font from ClickOnce application
- From: "Jeffrey Tan[MSFT]"
- RE: Install font from ClickOnce application
- From: Thomas Taylor
- RE: Install font from ClickOnce application
- Prev by Date: Re: Openning Access DB throuhg system.diagnostics.process.start
- Next by Date: Interesting problem with SmtpClient in background thread
- Previous by thread: RE: Install font from ClickOnce application
- Next by thread: RE: Install font from ClickOnce application
- Index(es):