Solved

Determine fixed width fonts on users machine

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now