2
votes

I'm creating an application for Windows and OS X using Firemonkey Framework with Delphi 10.2 Tokyo and can't set application or form icon dynamically.

In VCL project I've used following code:

Form1.Icon.LoadFromFile()

or

Application.Icon.LoadFromFile()

But there are no such properties or methods in FMX. Is there any way to set project icon otherwise than in Project -> Options menu?

2

2 Answers

0
votes

Add to your uses list {$IFDEF WIN32}WinApi.Windows,FMX.Platform.Win,{$ENDIF}

procedure setFormIcon(Form: TForm; FileName: String);
  var Icon : NativeUInt;
begin
  {$IFDEF WIN32}
  ICON := LoadImage(0,PWideChar(Filename),IMAGE_ICON,0,0,LR_LOADFROMFILE OR LR_DEFAULTSIZE OR LR_SHARED);
  SetClassLong(FmxHandleToHWND(Form.Handle), GCL_HICON, icon);
  {$ENDIF}
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
  setFormIcon(Form1,'my icon path.ico');
end;
0
votes

In the 10.2 Rio sources, I see that the function TPlatformWin.CreateWindow, which is used to create a window in the Windows, have only this line to provide a window's icon:

WindowClass.hIcon := LoadIconW(MainInstance, PChar('MAINICON'));

And function TPlatformWin.CreateAppHandle have an absolutely same code! So, we have not a direct way to set app or form icon through FireMonkey components.

At Windows You still can use WinAPI message WM_SETICON (SendMessage(Handle, WM_SETICON, ICON_BIG, MyIconHandle);), but I have not tried that and do not know any troubles in this way.

Also in Windows we may use TTaskbarBase and TPreviewClipRegion classes to the more precise and functional way of TaskBar interactions.

P.S. I do not know, what we have for same requirements at OS X.