Recent

Author Topic: Help on Font Instalation & Execute External Program  (Read 4609 times)

RobinHoo

  • New member
  • *
  • Posts: 10
Help on Font Instalation & Execute External Program
« on: June 02, 2009, 05:51:51 am »
Hi, All

Since I'm newer to the lazarus, and I'm trying to coding a small program under WinCE. But I got some problem, need someone here give me a hand.

1. Install a ttf file and use the font in it.
I'm trying to use a truetype font coming with my program, let's see font.ttf. And I want my label shows the font as the font file contents. What I have done is that use AddFontResource to add the font and broadcast the message in form create and remove it while form destroy. I pasted the code bellow.
Code: [Select]
procedure TfmPlatform.FormCreate(Sender: TObject);
var
Error,i:Integer;
reg:TRegistry;
DC: HDC;
List:TstringList;
begin
     For i:=0 to 16 do PageObj[i]:=TStringList.Create;
     Error:=AddFontResource(pWideChar(Application.Location+'Resource\font.ttf'));
if Error<>0 then
ShowMessage('Font Not Installed');
SendMessage(HWND_BroadCast,WM_Fontchange,0,0);
end;

procedure TfmPlatform.FormDestroy(Sender: TObject);
begin
  RemoveFontResource(pWideChar(Application.Location+'Resource\font.ttf'));
  SendMessage(HWND_BroadCast,WM_Fontchange, 0 , 0 );
end;

But I don't why I can not display the font by using it as the Font.Name of label. Anyone has any sample code of that?

Label1.Font.Name:='Dorid Sans Fallback';

2. Execute External Program

Lazarus suggests using TProcess or TProcessUTF8 to run external program. But I never got it work. The Aprocess.Execute will return a exception of error code 87. And I tried shellexecute as the following code, still no lucky. I know the SysUtils.ExecuteProcess works but it will wait the external program running till it's terminated.
Anyone got any good idea on it?
Code: [Select]
procedure ShellExecute(FileName: string);
var
  info: SHELLEXECUTEINFO;
begin
    showmessage(FileName);
    FillChar(info, SizeOf(info), 0);
    info.cbSize := SizeOf(info);
    info.lpFile := PWideChar(FileName);
    info.lpVerb := 'open';
    info.fMask  := $c;
    info.dwHotKey := 0;
    info.hIcon := 0;
    info.hInstApp := 0;
    info.hkeyClass := 0;
    info.hProcess := 0;
    info.hwnd := 0;
    info.lpClass := '';
    info.lpDirectory := '';
    info.lpIDList := nil;
    info.lpParameters := '';
    info.nShow := SW_SHOW;
    ShellExecuteEx(@info);
end;
ShellExecute(Application.Location+'notepad.exe');
« Last Edit: June 03, 2009, 01:17:25 am by RobinHoo »