Embedding a font in delphi

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 01:28:46

Yes, you can save it as a resource in the EXE file, and on user's pc, you can extract it as a file using a TResourceStream instance. Then you can call AddFontResource API function. At last, you should send a WM_FONTCHANGE message to all top-level windows in the system (Check Remark section of AddFontResource description in MSDN website).

If you need an example code, let me know.

In my opinion the most easy way is to use AddFontMemResourceEx in case the font is embedded as a resource into the EXE. It allows loading the font directly from memory, no need to save the font to file.

Code Example:

function LoadResourceFont( const ResourceName : string ) : boolean;
var
   ResStream : tResourceStream;
   FontsCount : integer;
   hFont : tHandle;
begin
   ResStream := tResourceStream.Create(hInstance, ResourceName, RT_RCDATA);
   hFont := AddFontMemResourceEx(ResStream.Memory, ResStream.Size, nil, @FontsCount);
   result := (hFont <> 0);
   ResStream.Free();
end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!