Results 1 to 8 of 8

Thread: getting the font folder on windows

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    getting the font folder on windows

    i need to find the font folder programatically on windows and put all the fonts into a listbox on my program

    but how can i find the font folder??

    on my machine its C:\windows\fonts

    but its different on other peoples

    can someone help me

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: getting the font folder on windows

    Try this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
    4. "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    5.  
    6. Private Sub Command1_Click()
    7.     Dim strSave As String, strPath As String
    8.         strSave = String(200, Chr$(0))
    9.         strPath = Left$(strSave, GetWindowsDirectory(strSave, Len(strSave))) & "\Fonts"
    10.             MsgBox strPath
    11. End Sub
    Fonts is always the same.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: getting the font folder on windows

    thanks

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: getting the font folder on windows

    here's how to get it outright:
    VB Code:
    1. Private Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" _
    2.     (ByVal hwnd As Long, ByVal pszPath As String, ByVal csidl As Long, ByVal fCreate As Long) As Long
    3.  
    4. Private Const CSIDL_FONTS = &H14&
    5.  
    6. Private Sub Form_Load()
    7.     Debug.Print GetFolderPath(CSIDL_FONTS)
    8. End Sub
    9.  
    10. Private Function GetFolderPath(ByVal lID As Long) As String
    11.     Dim sPath As String
    12.     sPath = Space$(260)
    13.     SHGetSpecialFolderPath Me.hwnd, sPath, lID, False
    14.     GetFolderPath = Left$(sPath, InStr(sPath, vbNullChar) - 1)
    15. End Function

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: getting the font folder on windows

    Quote Originally Posted by gavio
    ...Fonts is always the same.
    Not necessary - there is a more precise way to determine any special folder path:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const CSIDL_FONTS = &H14
    4. Private Const MAX_PATH = 260
    5. Private Const NOERROR = 0
    6.  
    7. Private Type SHTEMID
    8.     cb As Long
    9.     abID As Byte
    10. End Type
    11.  
    12. Private Type ITEMIDLIST
    13.     mkid As SHTEMID
    14. End Type
    15.  
    16. Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
    17.     (ByVal hwndOwner As Long, _
    18.     ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
    19.  
    20. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
    21.     Alias "SHGetPathFromIDListA" _
    22.     (ByVal pidl As Long, ByVal pszPath As String) As Long
    23.  
    24. Private Function GetSpecialfolder(CSIDL As Long) As String
    25. Dim res As Long
    26. Dim IDL As ITEMIDLIST
    27. Dim sPath As String
    28.  
    29.     'Get the special folder
    30.     res = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    31.     If res = NOERROR Then
    32.         'Create a buffer
    33.         sPath = Space$(512)
    34.         'Get the path from the IDList
    35.         res = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath)
    36.         'Remove the unnecessary chr$(0)'s
    37.         GetSpecialfolder = Left$(sPath, InStr(sPath, Chr$(0)) - 1)
    38.         Exit Function
    39.     End If
    40.     GetSpecialfolder = ""
    41.  
    42. End Function
    43.  
    44. Private Sub Command1_Click()
    45.     Debug.Print GetSpecialfolder(CSIDL_FONTS)
    46. End Sub

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: getting the font folder on windows

    Quote Originally Posted by Pouncer
    i need to find the font folder programatically on windows and put all the fonts into a listbox on my program
    If that is all you want to do, then you don't need to know where the Fonts folder is
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim i As Long
    3.     For i = 0 To Screen.FontCount - 1
    4.         List1.AddItem Screen.Fonts(i)
    5.     Next    
    6. End Sub

  7. #7

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: getting the font folder on windows

    Quote Originally Posted by RhinoBull
    ... and to take it a bit further here a very nice sample:

    Enumerate Windows Fonts with Font Preview
    Cool! I had not run into this tidbit before.

    Randy is The Man!

Posting Permissions

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



Click Here to Expand Forum to Full Width