Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get Name of Installed Font using API (Vb API)

    Get Name of Installed Font using API

    I can temporarily install a font file using the AddFontResource lib, but how do I get the name of the font that I just installed? I need to know the name of the font so that I can call it when I automate Word. I think I need to use the GetTextFace lib, but I don't fully understand how to use this function; Here is the Windows API declaration:

    Private Declare Function GetTextFace Lib "gdi32" Alias "GetTextFaceA" (ByVal hdc As Long, ByVal nCount As Long, ByVal lpFacename As String) As Long

    In Dan Appleman's Win32 API book, it says the "hdc" is to be a handle to a device context- what does this mean!?! Can someone breakdown this function and explain its parts? I am guessing that the lpFacename holds a string that the font name is dumped to and nCount sets the size of this string- why?.

    A little guidance is much appreciated!

    Thank you!

    --Llyal

    PS - I have found that the AddFontResource only temporarily installs a font (a machine re-boot will remove them); this is with Windows 2000; are there no APIs that will allow me to permanently install and uninstall fonts?

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts

    Re: Get Name of Installed Font using API (Vb API)

    First, that function doesn't do what you think it does, and I don't recall offhand what the right one is -- I may be able to find it tomorrow.

    Jeff Prosise explained it this way:
    "When a Windows program draws to a screen, a printer, or another output device, it doesn't communicate directly with the device as an MS-DOS program is apt to do. Rather, the Windows program draws to a logical "display surface" represented by a device context (DC). Deep inside Windows, a device context is a data structure containing fields that describe everything the GDI needs to know about the display surface and the context in which it is being used..."

    The following is from a C++ viewpoint. I'm not sure you can do the same thing in VB...

    You can make copies of a DC and modify them before displaying them. If your function receives a copy of a DC and needs to add some text to it, you may need to find out what face is already selected there. That's what GetTextFace is for: you pass in the DC (actually a handle to the DC, hence hDC) and a buffer that can hold a string. The nCount parameter says how big the buffer is. When the function returns, the buffer contains the name of the selected font in the DC.

    The MS documentation is at <A target="_blank" HREF=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_3jtx.asp>http://msdn.microsoft.com/library/default....ontext_3jtx.asp</A>, but again, that's based on C++ and may be hard to apply to VB.

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get Name of Installed Font using API (Vb API)

    Jay,

    Thanks for the input- it looks like getting the font name is not easy; this probably explains why I have not seen much about this on the internet;

    I could be taking the wrong approach; what I could do is use Word- I could enumerate through the installed fonts in Word, remember them, install the font, then enumerate through the installed fonts again, find the "extra" font and get its name;

    You can see how this will be slow for 3000+ fonts, but it is better than nothing;

    Thanks for the help!

    --Llyal

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts

    Re: Get Name of Installed Font using API (Vb API)

    3000+ fonts????

    Anything much over 1000 installed fonts makes Windows crawl on its knees <img src=/S/snail.gif border=0 alt=snail width=21 height=17> and then fall over. <img src=/S/puke.gif border=0 alt=puke width=60 height=15> Mostly I see recommendations to keep it down around 250, using a font manager if necessary.

  5. #5
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get Name of Installed Font using API (Vb API)

    Jay,

    When you "permanently" install fonts, you are absolutely correct; I couldn't install more than several hundred fonts this way;

    But I have found that by using the APIs and installing the fonts temporarily, I could install 3800+ fonts and manipulate Word and other apps with no great problems; and the computer will revert itself back to the "permanently" installed fonts upons a re-boot (without having to unistall all the temp fonts);

    This is an interesting workaround to a windows limitation;

    Try it, you will see for yourself!

    --Llyal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •