我遇到了以下问题:
我的Delphi7程序在大多数运行WinXP/Vista/7的计算机上运行得很流畅,但在一些较旧的Windows XP安装程序(只有几个)上,我遇到了以下问题:
我有一个系统镜像列表,并且我正在将我自己的图标添加到系统镜像列表的副本中。在添加我的图标时,我得到一个“无效的图像大小”。EInvalidOperation错误。
下面是有问题的代码:
function GetSystemLargeIconsList: TCustomImageList;
// This gets the system image list.
var
SysIL: HImageList;
SFI: TSHFileInfo;
MyImages: TCustomImageList;
begin
SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
if SysIL <> 0 then begin
MyImages:=TCustomImageList.Create(nil);
// Assign the system list to the component
MyImages.Handle := SysIL;
// The following prevents the image list handle from being
// destroyed when the component is.
MyImages.ShareImages := TRUE;
Result:=MyImages;
end;
end;
var
DocumentImgList: TCustomImageList;
IconToAdd: TIcon;
begin
DocumentImgList:=GetSystemLargeIconsList;
Documents.LargeImages:=DocumentImgList;
Documents.SmallImages:=DocumentImgList;
IconToAdd:=TIcon.Create;
DocumentListIcons.GetIcon(0, IconToAdd);
DocumentImgList.AddIcon(IconToAdd); ----> this is the line of the exception更糟糕的是,我使用了TPngImageList组件,但根据代码,它似乎只是调用标准的Delphi函数:
if TObject(Self) is TPngImageList
then if Image = nil
...
else begin
Patch := FindMethodPatch('AddIcon');
if Patch <> nil
then begin
Patch.BeginInvokeOldMethod;
try
Result := TCustomImageList(Self).AddIcon(Image); ----> this is where the exception happens
finally
Patch.FinishInvokeOldMethod;
end;
end
else Result := -1;
end;我最近发现,在其中一台有这个问题的电脑上,uxtheme.dll或explorer.exe已经用一些换皮程序打了补丁。
所以我猜想是某人或某个程序正在以某种方式入侵系统镜像列表,从而导致我的Delphi程序崩溃。
有什么办法解决这个问题吗?
谢谢!
发布于 2010-10-29 02:18:03
您可以尝试的一件事是将图标加载到单独的tBitmap中,然后在将其添加到图像列表之前调整其大小。
https://stackoverflow.com/questions/4045884
复制相似问题