DELPHI 制作FONT资源文件时,有可能会报 "brcc32 exited with code 1" ,最终选择不用font 而使用:RCDATA制作资源
例如:
AR_01 RCDATA "AR_01 Regular.ttf"
ZR_01 RCDATA "ZR_01 Regular.ttf"
新建一个DLL程序,添加刚才的资源文件,直接编译成DLL文件
=========================================================================
接下来就是调用字体资源
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);
//ResHandle := FindResource(DllHandle, MAKEINTRESOURCE(1), RT_FONT);
ResHandle := FindResource(DllHandle, MAKEINTRESOURCE(FontName), RT_RCDATA);
if ResHandle = 0 then
begin
ShowMessage('ResHandle');
RaiseLastOSError;
end;
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;
procedure TForm1.Button1Click(Sender: TObject);
var
FontName: PChar;
FontHandle: THandle;
begin
FontName := 'AR_01';
LoadFontFromDll('ZaiRe.dll' , FontName);
FontHandle := CreateFont(0, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,
FontName);
if FontHandle = 0 then
RaiseLastOSError;Label1.Caption:=Edit1.Text;
label1.Font.Handle:=FontHandle;
label1.Font.Size:=72;
end;
完美解决!