This an excellent demonstration of why you should NOT use WinAPI functions without reading and understanding the documentation.
The documentation for LoadIconWithScaleDown clearly explains what the parameters are and how to use them. There is zero reason to use GetModuleFileName
, and the parameter where you're passing it in is wrong anyway, which the documentation clearly states.
Here are examples for using the function both ways, first to load an icon from an external disk file and then to load from an icon resource in your application. It was compiled and tested under Delphi 10 Seattle and works, provided the file or resource exist where you're using it.
uses
CommCtrl;
var
hIco: HICON;
Ico: TIcon;
NewWidth, NewHeight: Integer;
begin
NewWidth := 16;
NewHeight := 16;
if Succeeded(LoadIconWithScaleDown(0,
'C:ImagesSomeFile.ico',
NewWidth, NewHeight, hIco)) then
begin
Ico := TIcon.Create;
Ico.Handle := hIco;
// Do whatever with the icon. Clean up is left to you
end;
if Succeeded(LoadIconWithScaleDown(hInstance,
'MYRESOURCENAME',
NewWidth, NewHeight, hIco)) then
begin
// See code above
end;
end;
(And no, the issue was not that you needed to call InitCommonControlsEx
first. Including CommCtrl does the necessary initialization for you.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…