• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

How do I get a client machine's system font?

I'm distributing a program which contains some command buttons. The captions for these buttons must be written in the client's system font.

How do I dynamically get the user's system font please?


1 Solution
I suppose the font is stored in the registry, if it is, you can use this to get it:

Public Function GetRegKey(KeyRoot As HKEYS, KeyName As String, SubKeyRef As String, EmptyRead As Variant) As String
    Dim i               As Long                                 ' Loop Counter                              '
    Dim rc              As Long                                 ' Return Code                               '
    Dim hKey            As Long                                 ' Handle To An Open Registry Key            '
    Dim hDepth          As Long                                 '                                           '
    Dim sKeyVal         As String                               '                                           '
    Dim lKeyValType     As Long                                 ' Data Type Of A Registry Key               '
    Dim tmpVal          As String                               ' Tempory Storage For A Registry Key Value  '
    Dim KeyValSize      As Long                                 ' Size Of Registry Key Variable             '
    ' Open RegKey Under KeyRoot {HKeY_LOCAL_MACHINe...}         '
    rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey)  ' Open Registry Key                        '
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyerror              ' Handle error...                           '
    tmpVal = String$(1024, 0)                                   ' Allocate Variable Space                   '
    KeyValSize = 1024                                           ' Mark Variable Size                        '
    ' Retrieve Registry Key Value...                            '
    rc = RegQueryValueEx(hKey, SubKeyRef, 0, lKeyValType, tmpVal, KeyValSize)    ' Get/Create Key Value
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyerror              ' Handle errors
    tmpVal = Left$(tmpVal, InStr(tmpVal, Chr(0)) - 1)

    ' Determine Key Value Type For Conversion...                '
    Select Case lKeyValType                                     ' Search Data Types...
    Case REG_SZ, REG_EXPAND_SZ                                  ' String Registry Key Data Type
        sKeyVal = tmpVal                                        ' Copy String Value
    Case REG_DWORD                                              ' Double Word Registry Key Data Type
        For i = Len(tmpVal) To 1 Step -1                        ' Convert each Bit
            sKeyVal = sKeyVal + Hex(Asc(Mid(tmpVal, i, 1)))     ' Build Value Char. By Char.
        sKeyVal = Format$("&h" + sKeyVal)                       ' Convert Double Word To String
    End Select
    GetRegKey = sKeyVal                                         ' Return Value
    rc = RegCloseKey(hKey)                                      ' Close Registry Key
    Exit Function                                               ' Exit
GetKeyerror:    ' Cleanup After An error Has Occured...         '
    GetRegKey = EmptyRead                                       ' Set Return Val To empty String
    rc = RegCloseKey(hKey)                                      ' Close Registry Key
End Function
gizzAuthor Commented:
Yes - silly me !
What registry key?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now