Solved

Determine fixed width fonts on users machine

Posted on 2008-06-12
7
407 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

770 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