Results 1 to 6 of 6

Thread: [RESOLVED] Get title bar font

Threaded View

  1. #1

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Resolved [RESOLVED] Get title bar font

    I need to get both the font name and size of the title bar font. The following code from here gets me most of the way:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Const LF_FACESIZE = 32
    4. Private Const SPI_GETNONCLIENTMETRICS = 41
    5.  
    6. Private Type LOGFONT
    7.     lfHeight As Long
    8.     lfWidth As Long
    9.     lfEscapement As Long
    10.     lfOrientation As Long
    11.     lfWeight As Long
    12.     lfItalic As Byte
    13.     lfUnderline As Byte
    14.     lfStrikeOut As Byte
    15.     lfCharSet As Byte
    16.     lfOutPrecision As Byte
    17.     lfClipPrecision As Byte
    18.     lfQuality As Byte
    19.     lfPitchAndFamily As Byte
    20.     lfFaceName(1 To LF_FACESIZE) As Byte
    21. End Type
    22.  
    23. Private Type NONCLIENTMETRICS
    24.     cbSize As Long
    25.     iBorderWidth As Long
    26.     iScrollWidth As Long
    27.     iScrollHeight As Long
    28.     iCaptionWidth As Long
    29.     iCaptionHeight As Long
    30.     lfCaptionFont As LOGFONT
    31.     iSMCaptionWidth As Long
    32.     iSMCaptionHeight As Long
    33.     lfSMCaptionFont As LOGFONT
    34.     iMenuWidth As Long
    35.     iMenuHeight As Long
    36.     lfMenuFont As LOGFONT
    37.     lfStatusFont As LOGFONT
    38.     lfMessageFont As LOGFONT
    39. End Type
    40.  
    41. Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
    42.  
    43. Public Function ActiveTitleBarFontName()
    44.     Dim s As String
    45.     Dim i As Byte
    46.     Dim ncm As NONCLIENTMETRICS
    47.     Dim sdfont As StdFont
    48.    
    49.     ncm.cbSize = Len(ncm)
    50.     If SystemParametersInfo(41, ncm.cbSize, ncm, 0) Then
    51.         s = StrConv(ncm.lfCaptionFont.lfFaceName, vbUnicode)
    52.         i = InStr(s, vbNullChar)
    53.         If i > 0 Then s = Left(s, i - 1)
    54.     End If
    55.     ActiveTitleBarFontName = s
    56. End Function
    I must be a little slow, though, because I can't figure out how to determine the font size from that structure. On my system the ActiveTitleBar font is Tahoma 8, but the lfCaptionFont structure has the following values:

    lfHeight = -11
    lfWeight = 700

    Little help?
    Last edited by Ellis Dee; Jan 27th, 2010 at 08:52 PM.

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