Sur le sujet, j'ai quelques codes dans ma collection (Windows uniquement).
MSDN a écrit :AddFontResource Function
Any application that adds or removes fonts from the system font table should notify other windows of the change by sending a WM_FONTCHANGE message to all top-level windows in the operating system. The application should send this message by calling the SendMessage function and setting the hwnd parameter to HWND_BROADCAST.
When an application no longer needs a font resource that it loaded by calling the AddFontResource function, it must remove that resource by calling the RemoveFontResource function.
This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry.
Code : Tout sélectionner
;
; AddFontMemResourceEx()
;
i.l = 1
notok = #True
If OpenLibrary(1, "Gdi32.dll")
proc.l = IsFunction(1, "AddFontMemResourceEx")
If proc
CallFunction(1, "AddFontMemResourceEx", ?font1_start, ?font1_end - ?font1_start, 0, @i)
notok = #False
EndIf
CloseLibrary(1)
EndIf
If notok
If CreateFile(0, "fixed_01.ttf")
WriteData(?font1_start, ?font1_end - ?font1_start)
CloseFile(0)
AddFontResource_("fixed_01.ttf")
SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE,0,0)
Else
MessageRequester("Fehler", "Konnte eine Resource nicht laden")
End
EndIf
EndIf
LoadFont(#fnt_small, "fixed_v01", 6)
;...
DataSection
font1_start:
IncludeBinary "Data\fixed_01.ttf"
font1_end:
EndDataSection
Code : Tout sélectionner
;
; AddFontResource
;
EnableExplicit
Define Result.l
Define i.l
Result = AddFontResource_("DIMITRI_.TTF")
SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE,0,0)
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
EditorGadget(0, 8, 8, 306, 133)
For i = 0 To 5
AddGadgetItem(0,i,"Line "+Str(i))
Next
SetGadgetFont(0,LoadFont(0,"DIMITRI",10))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
RemoveFontResource_("DIMITRI_.TTF")
SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE,0,0)