Регистрация шрифта средствами VB6

Узнай цену своей работы

Формулировка задачи:

Всем привет! Ткните носом. попадалась на глаза тема. Не могу найти...

Решение задачи: «Регистрация шрифта средствами VB6»

textual
Листинг программы
  1. Option Explicit
  2.  
  3. Private Declare Function AddFontResource Lib "gdi32.dll" Alias "AddFontResourceA" (ByVal lpFileName As String) As Long
  4. Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
  5.  
  6. Private Sub Command1_Click()
  7.    
  8.                     Dim WshShell        As Object
  9.                     Dim FontPath        As String
  10.                     Dim retCodes        As Long
  11.                     Dim intI            As Integer
  12.                     Dim intISucsCopy    As Integer
  13.                     Dim intISucsRegs    As Integer
  14.                     Dim intIErrCopy     As Integer
  15.                     Dim intIErrRegs     As Integer
  16.                     Dim intFreeNoom     As Integer
  17.    
  18.    
  19.     Set WshShell = CreateObject("WScript.Shell")
  20.     FontPath = WshShell.SpecialFolders("Fonts") ' определяем системную папку со шрифтами
  21.    intFreeNoom = FreeFile
  22.    
  23.    
  24.     Open App.Path & "\InstFont.log" For Append As #intFreeNoom  ' лог файл
  25.      
  26.       Print #intFreeNoom, ""
  27.       Print #intFreeNoom, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  28.       Print #intFreeNoom, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start LOG ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  29.       Print #intFreeNoom, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  30.       Print #intFreeNoom, "Date - "; Date
  31.       Print #intFreeNoom, "Time - "; Time
  32.       Print #intFreeNoom, ""
  33.      
  34.       For intI = 0 To File1.ListCount - 1
  35.          
  36.                  '
  37.                 ' копируем шрифты в системную папку
  38.                 '
  39.                
  40.                  retCodes = CopyFile(App.Path & "\" & File1.List(intI), FontPath & "\" & File1.List(intI), 0)
  41.                  
  42.                     '
  43.                    ' пишем лог
  44.                    '
  45.                    
  46.                     If retCodes = 0 Then
  47.                        Print #intFreeNoom, "Copy files - " & App.Path & "\" & File1.List(intI) & " to " & FontPath & "\" & File1.List(intI) & " { Error }"
  48.                        intIErrCopy = intIErrCopy + 1
  49.                     Else
  50.                        Print #intFreeNoom, "Copy files - " & App.Path & "\" & File1.List(intI) & " to " & FontPath & "\" & File1.List(intI) & " { Success }"
  51.                        intISucsCopy = intISucsCopy + 1
  52.                     End If
  53.                  
  54.                 '
  55.                ' пробуем зарегистрировать
  56.                '
  57.                    
  58.                 retCodes = AddFontResource(FontPath & "\" & File1.List(intI))
  59.                
  60.                     '
  61.                    ' пишем лог
  62.                    '
  63.                
  64.                
  65.                     If retCodes = 0 Then
  66.                       Print #intFreeNoom, "Reg. files  - " & FontPath & "\" & File1.List(intI) & " { Error }"
  67.                       intIErrRegs = intIErrRegs + 1
  68.                     Else
  69.                        Print #intFreeNoom, "Reg.files  - " & FontPath & "\" & File1.List(intI) & " { Success }"
  70.                        intISucsRegs = intISucsRegs + 1
  71.                     End If
  72.                    
  73.                     Print #intFreeNoom, ""
  74.       Next intI
  75.            
  76.         Print #intFreeNoom, "Total files        : " & File1.ListCount
  77.         Print #intFreeNoom, "Success copy files : " & intISucsCopy
  78.         Print #intFreeNoom, "Error copy files   : " & intIErrCopy
  79.         Print #intFreeNoom, "Success Reg files  : " & intISucsRegs
  80.         Print #intFreeNoom, "Error Reg files    : " & intIErrRegs
  81.    
  82.     Close #intFreeNoom
  83.            
  84.             '
  85.            ' результаты в студию....
  86.            '
  87.        
  88.         Shell "notepad.exe" & " " & App.Path & "\InstFont.log"
  89.     End
  90.    
  91. End Sub
  92.  
  93. Private Sub Form_Load()
  94.     File1.Pattern = "*.ttf"
  95.     If File1.ListCount = 0 Then Command1.Enabled = False
  96.     Label2.Caption = "Foud Font:" & File1.ListCount
  97. End Sub
  98.  
  99. Private Sub Text1_Change()
  100.     File1.Pattern = Text1
  101.     If File1.ListCount = 0 Then Command1.Enabled = False Else Command1.Enabled = True
  102.     Label2.Caption = "Foud Font:" & File1.ListCount
  103. End Sub

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

9   голосов , оценка 3.667 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут