delphi – 我如何临时加载字体?

前端之家收集整理的这篇文章主要介绍了delphi – 我如何临时加载字体?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在我的程序中临时加载一些字体.最好从dll资源文件.

解决方法

这里是Delphi版本:
procedure LoadFontFromDll(const DllName,FontName: PWideChar);
var
  DllHandle: HMODULE;
  ResHandle: HRSRC;
  ResSize,NbFontAdded: Cardinal;
  ResAddr: HGLOBAL;
begin
  DllHandle := LoadLibrary(DllName);
  if DllHandle = 0 then
    RaiseLastOSError;
  ResHandle := FindResource(DllHandle,FontName,RT_FONT);
  if ResHandle = 0 then
    RaiseLastOSError;
  ResAddr := LoadResource(DllHandle,ResHandle);
  if ResAddr = 0 then
    RaiseLastOSError;
  ResSize := SizeOfResource(DllHandle,ResHandle);
  if ResSize = 0 then
    RaiseLastOSError;
  if 0 = AddFontMemResourceEx(Pointer(ResAddr),ResSize,nil,@NbFontAdded) then
    RaiseLastOSError;
end;

被使用像:

var
  FontName: PChar;
  FontHandle: THandle;
...
  FontName := 'DEJAVUSANS';
  LoadFontFromDll('Project1.dll',FontName);
  FontHandle := CreateFont(0,FW_NORMAL,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,FontName);
  if FontHandle = 0 then
    RaiseLastOSError;
原文链接:https://www.f2er.com/delphi/101389.html

猜你在找的Delphi相关文章