Delphi - Change taskbar icon

妖精的绣舞 提交于 2020-01-05 08:48:55

问题


I have main .exe app and .dll with form. From .exe I can create and show form from the .dll, but it has no taskbar icon (and the small one at the top left). I want to load this icon from another DLL. How can I do it please?


回答1:


Here are the things that you need to do. I've not included much detail because your question has little detail and there's no way for me to know exactly how you would fit all this into your program. The point is to make it clear at a high level what you need to do.

Load the DLL containing the resource

Do this using LoadLibrary or LoadLibraryEx. Use the former if you need to call code in the DLL. Otherwise use the latter passing LOAD_LIBRARY_AS_IMAGE_RESOURCE. Both of these functions yield a module handle, HMODULE.

Load the icon from the DLL

Pass the HMODULE to LoadIcon or LoadImage to load the icon from a resource. These will yield an HICON. Assign that to the Handle property of an instance of TIcon.

Assign the icon to the form

Assign the icon object that you obtained in the previous step to the Icon property of your form.




回答2:


Thank you very much. I tried something like Form.Icon.Assign(Icon);, but it created AV error message. Here is working code:

procedure TformOptions.FormCreate(Sender: TObject);
var
  lib: THandle;
  icon: TIcon;
begin
  icon := TIcon.Create;
  lib := LoadLibrary('res.dll');
  if lib > 0 then icon.Handle := LoadIcon(lib, 'ICON2');
  if icon.Handle > 0 then Application.Icon.Assign(icon);
  icon.Free;
  FreeLibrary(lib);
end;


来源:https://stackoverflow.com/questions/31350774/delphi-change-taskbar-icon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!