susan110622 2014-12-21 04:16 采纳率: 0%
浏览 2990

如何在VB6.0中用代码加载系统字体

就是通过组合框能够把系统中的字体全部加载出来,不知道是要用什么代码!

  • 写回答

4条回答

  • threenewbee 2014-12-21 04:22
    关注
    Option Explicit
    
     Private Sub Form_Load()
       Module1.FillComboWithFonts Combo1
     End Sub 
    
     Add a module, Module1, to the project and add the following code to the module. 
    
    Option Explicit
    
     'Font enumeration types
     Public Const LF_FACESIZE = 32
     Public Const LF_FULLFACESIZE = 64
    
     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
    
     ' ntmFlags field flags
     Public Const NTM_REGULAR = &H40&
     Public Const NTM_BOLD = &H20&
     Public Const NTM_ITALIC = &H1&
    
     ' tmPitchAndFamily flags
     Public Const TMPF_FIXED_PITCH = &H1
    
     Public Const TMPF_VECTOR = &H2
     Public Const TMPF_DEVICE = &H8
     Public Const TMPF_TRUETYPE = &H4
    
     Public Const ELF_VERSION = 0
     Public Const ELF_CULTURE_LATIN = 0
    
     ' EnumFonts Masks
     Public Const RASTER_FONTTYPE = &H1
     Public Const DEVICE_FONTTYPE = &H2
     Public Const TRUETYPE_FONTTYPE = &H4
    
     Declare Function EnumFontFamilies Lib "gdi32" Alias _
        "EnumFontFamiliesA" _
        (ByVal hDC As Long, ByVal lpszFamily As String, _
        ByVal lpEnumFontFamProc As Long, LParam As Any) As Long Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, _
        ByVal hDC As Long) As Long
    
     Function EnumFontFamProc(lpNLF As LOGFONT, lpNTM As NEWTEXTMETRIC, _
        ByVal FontType As Long, LParam As ListBox) As Long
     Dim FaceName As String
     Dim FullName As String
       FaceName = StrConv(lpNLF.lfFaceName, vbUnicode)
       LParam.AddItem Left$(FaceName, InStr(FaceName, vbNullChar) - 1)
       EnumFontFamProc = 1
    
     End Function
    
     Sub FillComboWithFonts(CB As ComboBox)
     Dim hDC As Long
       CB.Clear
       hDC = GetDC(CB.hWnd)
       EnumFontFamilies hDC, vbNullString, AddressOf EnumFontFamProc, CB
       ReleaseDC CB.hWnd, hDC
     End Sub  
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用