Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Tips & tricks

#281 - Installera ett nytt typsnitt på en dator

Postat 2000-12-22 19:41:57 av Pelle Johansson i Kategori Programmering, C#, Kommandon med 0 Kommentarer

Public Function InstallTTFont(strSourcePath As String, strFontFileName As String, Optional bolShowError As Boolean) As Long
Dim sFontDir As String
Dim sFontName As String
Dim sFOTFile As String
Dim sRegKey As String
Dim sWinDir As String

Dim lDisplay As Long
Dim lFileNum As Long
Dim lLastError As Long
Dim lResult As Long
Dim lRetVal As Long
Dim lErrCntr As Long

Dim tSecAtt As SECURITY_ATTRIBUTES

sWinDir = GetWindowsDir
sFontDir = sWinDir & "FONTS\"
sFOTFile = sFontDir & Left(strFontFileName, Len(strFontFileName) - 4) + ".FOT"
tSecAtt.nLength = 0
tSecAtt.lpSecurityDescriptor = 0
tSecAtt.bInheritHandle = 0

'Copy the fontfile to the FONTS folder
If FileIsNewerVersion(strSourcePath, strFontFileName, sFontDir, strFontFileName) Then
'We've got the newer version, so we should install it
lErrCntr = 0
On Error GoTo InUse 'when the file is in use
FileCopy AddDirSep(strSourcePath) & strFontFileName, sFontDir & strFontFileName
On Error GoTo 0

'(Re)Create the resource file for the font
If Dir(sFOTFile) <> "" Then
'Delete the resource file
Kill sFOTFile
End If
lRetVal = CreateScalableFontResource(0, sFOTFile, strFontFileName, sFontDir)
If lRetVal = 0 Then
If bolShowError Then
lLastError = GetLastError()
If lLastError = 80 Then
MsgBox "Font file " & sFontDir & strFontFileName & "already exists."
ElseIf lLastError <> 0 Then
MsgBox "Error " & Str(lLastError)
End If
End If
Exit Function
End If

'Get the font's name from the resource file
sFontName = GetFontName(sFOTFile)

'Add the font to the system font table.
lRetVal = AddFontResource(sFOTFile)
If lRetVal = 0 Then
If bolShowError Then
lLastError = GetLastError()
If lLastError = 87 Then
MsgBox "Incorrect Parameter"
ElseIf lLastError <> 0 Then
MsgBox "Error " & Str(lLastError)
End If
End If
Exit Function
End If

'Make the font persistent across reboots.
If GetWindowsVersion = wvWindowsNT Then
sRegKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
Else
sRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts"
End If
lRetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, sRegKey, 0, "REG_SZ", _
0, KEY_ALL_ACCESS, tSecAtt, lResult, lDisplay)
'Uncomment the following line to display information
'MsgBox "Key handle : " & lResult & vbCrLf & "Key " & IIf(lDisplay = 1, "created.", "opened (already existed)."), vbOKOnly + vbInformation, "Registry"
lRetVal = RegSetValueEx(lResult, sFontName, 0, 1, strFontFileName, Len(strFontFileName))
'Close the key. Don't keep it open longer than necessary.
lRetVal = RegCloseKey(lResult)
'Notify all the other application a new font has been added.
lRetVal = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
If lRetVal = 0 Then
If bolShowError Then
lLastError = GetLastError()
MsgBox "Error " & Str(lLastError)
End If
End If
'Delete the resource file
Kill sFOTFile
'OK to calling sub
InstallTTFont = 1
Else
'OK to calling sub
InstallTTFont = 2
End If
Exit Function

InUse:
lErrCntr = lErrCntr + 1
If lErrCntr = 2 Then
'We still can't copy the file, so the system
'should do it for us while rebooting
Call ReplaceSystemFile(AddDirSep(strSourcePath) & strFontFileName, sFontDir & strFontFileName)
If bolShowError Then
MsgBox "The font you try to install is currently in use." & vbCrLf & _
"Your computer must be rebooted in order to install it...", vbOKOnly + vbExclamation, "Font installation"
End If
'Inform calling sub of necessary reboot
InstallTTFont = 3
Exit Function
End If
'Try to unregister the font, ...
Call UnregisterFont(sFontDir, strFontFileName)
'... kill the file, ...
Kill sFontDir & strFontFileName
'... and retry copying
Resume
End Function
Public Sub ShutdownSystem(eType As eShutDown)
If Not (eType = shtLogOff Or eType = shtForceLogOff) Then
If GetWindowsVersion = wvWindowsNT Then
Call AdjustToken
End If
End If
Call ExitWindowsEx(eType, &HFFFF)
End Sub

Sample:
Size:

Nyligen

  • 09:09 Vill du köpa medicinska tester?
  • 12:47 Vem beviljar assistansen – kommune
  • 14:17 Någon med erfarenhet av hemstädnin
  • 14:14 Bör man använda sig av en båtförme
  • 14:12 Finns det någon intressant hundblo
  • 14:25 Tips på verktyg för att skapa QR-k
  • 14:23 Tips på verktyg för att skapa QR-k
  • 20:52 Fungerer innskuddsbonuser egentlig

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 569 158
27 952
271 704
1 037
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies