I believe what my code complies to LoadImage
specification, but despite of explicitly specified dimensions, loaded image is largest non-PNG icon.
procedure TForm1.FormCreate(Sender: TObject);
begin
Image1.Picture.Icon.Handle := LoadImage(
0,
MakeIntResource(OIC_SHIELD),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_SHARED
);
Win32Check(Image1.Picture.Icon.HandleAllocated);
OutputDebugString(PChar(Format('%d×%d', [
Image1.Picture.Icon.Width,
Image1.Picture.Icon.Height
]))); // 128×128
end;
Note: i prefer to be compliant to newer LoadImage
semantics rather than to rely on the explicit module and resource id (essentially falling back to LoadIcon
semantics) as specified in the answer to this question.
Quotes from LoadImage
specs are exactly outlining my problem with mutually exclusive LoadImage behaviours (either fail or use previously loaded stock resource, ignoring desired dimensions) - see Adrian McCarthy's answer.
While OIC_SHIELD
is Windows 6.0+ specific, the same happens with other stock icons (OIC_xxx constants) present in Windows since version 4.0.