locked
InstalledFontCollection Familes not showing fonts added to system using AddFontResource RRS feed

  • Question

  • The situation is that we are loading fonts into the user's session using the AddFontResource call and sending a WM_FONTCHANGE.  We can successfully see the font in WordPad and other processes running in the user's session.

    However, when we go through the Families collection using .NET code we do not see the fonts.

    Has anyone else seen this behavior before?  Any workarounds other than loading the fonts into the .NET process using a PrivateFontCollection?

    Monday, April 4, 2016 8:12 PM

All replies

  • Hi Damon,

    >>However, when we go through the Families collection using .NET code we do not see the fonts.

    Do you have some code that you could show us to illustrate what you are trying to achieve? Or are you just talking in vague general terms about how you might go about writing some kind of code.

    What's your project type? WPF, winfrom or any others?

    If you have any updates, please let me know.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 5, 2016 3:29 AM
  • First half (loading font) is just two steps.  We do this from a separate program (non-managed code) run during the login script.  Step 1, call AddFontResource and pass it the file name to the font.  Second, do a SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) to tell all processes that we loaded the font.

    At this point, Wordpad and other applications running in the user's session can see the font.  (We see the font in Wordpad's dropdown and can use it in a new blank document)  It is also visible in Office applications, Notepad, etc.

    Now, we launch a .NET application.  We can recreate this issue with the sample code provided on the FontFamily.Properties documentation located at https://msdn.microsoft.com/en-us/library/system.drawing.fontfamily.families%28v=vs.110%29.aspx.  All it does it loop through the FontFamily.Families members and add the name to a listbox. 

    This code does NOT list the font that is visible from the other processes.

    Tuesday, April 5, 2016 6:06 AM
  • Hi Damon,

    When checking the MSDN Library article for AddFontResource():

    In remarks section:

    This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry.

    The InstalledFontCollection class only enumerates fonts that are actually installed and omits the temporary ones.  Writing the registry keys and copying the file to c:\windows\fonts is very much an installer duty.  Microsoft does not document how to do that, other than going to through the Control Panel.  If you want to take a shot at it, the registry key is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts

    Hope this helps!

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Wednesday, April 6, 2016 8:14 AM
    Wednesday, April 6, 2016 8:13 AM
  • My goal with this is specifically to NOT install the fonts into the C:\Windows\Fonts directory since I only want the font files available within that particular user's session.

    My curiosity is that I can use the AddFontResource to load the fonts successfully.  They show up in Wordpad, Office, various other programs.  However, my .NET code doesn't see the font family.

    I understand that InstalledFontCollection references the system-installed fonts in C:\Windows\Fonts.  Is there a different collection that would represent all the fonts loaded in the user's session, including those loaded via AddFontResource?

    Wednesday, April 6, 2016 3:43 PM