Solved

Determine fixed width fonts on users machine

Posted on 2008-06-12
7
409 Views
Last Modified: 2010-05-18
I have created a richtextbox that a user can type over underlines with-out erasing the underline or increasing the lines sentence lenght Like this:
In the keypress event
If mnuUnderlineTyping.Checked = True Then
myrtf1.SelUnderline = True
SendKeys "{Delete}"

End If
This works perfect if the line was created using a fixed width font when creating the line. The line is created by using .selunderline = true and using the space bar.
I have found that almost all pc's have the following fixed width fonts:
Courier New and Lucida Console some pc' may have more or users can dowload and add more. The program loads all the users fonts into a combo box. Now i want to add another combobox that only displays fixed width fonts.
How?
0
Comment
Question by:isnoend2001
  • 2
  • 2
7 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21773514
Here is a previous answer in C#:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_21566129.html

you can translate to vb.net, please ask if you have some difficulty
0
 

Author Comment

by:isnoend2001
ID: 21773814
Thanks jaime_olivares:
That looks like what i need, but i am using vb6 and don't know about converting it>
0
 

Accepted Solution

by:
isnoend2001 earned 0 total points
ID: 21776116
Option Explicit
in form
Private Sub Form_Load()
Dim LF As LOGFONT
    'set graphics mode to persistent
    Me.AutoRedraw = True
    'enumerates the fonts
    EnumFontFamiliesEx Me.hdc, LF, AddressOf EnumFontFamProc, ByVal 0&, 0

End Sub


in module
Public Const TMPF_FIXED_PITCH = &H1

Public Const LF_FACESIZE = 32 '

Type LOGFONT
    lfHeight As Long
    lfWidth As Long
    lfEscapement As Long
    lfOrientation As Long
    lfWeight As Long
    lfItalic As Byte
    lfUnderline As Byte
    lfStrikeOut As Byte
    lfCharSet As Byte
    lfOutPrecision As Byte
    lfClipPrecision As Byte
    lfQuality As Byte
    lfPitchAndFamily As Byte
    lfFaceName(LF_FACESIZE) As Byte

End Type '

Type NEWTEXTMETRIC
    tmHeight As Long
    tmAscent As Long
    tmDescent As Long
    tmInternalLeading As Long
    tmExternalLeading As Long
    tmAveCharWidth As Long
    tmMaxCharWidth As Long
    tmWeight As Long
    tmOverhang As Long
    tmDigitizedAspectX As Long
    tmDigitizedAspectY As Long
    tmFirstChar As Byte
    tmLastChar As Byte
    tmDefaultChar As Byte
    tmBreakChar As Byte
    tmItalic As Byte
    tmUnderlined As Byte
    tmStruckOut As Byte
    tmPitchAndFamily As Byte
    tmCharSet As Byte
    ntmFlags As Long
    ntmSizeEM As Long
    ntmCellHeight As Long
    ntmAveWidth As Long
End Type

Declare Function EnumFontFamiliesEx Lib "gdi32" _
        Alias "EnumFontFamiliesExA" (ByVal hdc As Long, _
                                     lpLogFont As LOGFONT, _
                                     ByVal lpEnumFontProc As Long, _
                                     ByVal LParam As Long, _
                                     ByVal dw As Long) As Long

Function EnumFontFamProc(lpNLF As LOGFONT, lpNTM As NEWTEXTMETRIC, ByVal FontType As Long, LParam As Long) As Long

    Dim FaceName As String

    'print the form on Form1

    If (lpNLF.lfPitchAndFamily And _
       TMPF_FIXED_PITCH) = TMPF_FIXED_PITCH Then

        'convert the returned string to Unicode

        FaceName = StrConv(lpNLF.lfFaceName, vbUnicode)

        'Form1.Print Left$(FaceName, InStr(FaceName, vbNullChar) - 1)
       
    End If

    'continue enumeration

    EnumFontFamProc = 1

End Function
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21776117
no objection
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question