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;