首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Delphi7 CustomImageList问题

Delphi7 CustomImageList问题
EN

Stack Overflow用户
提问于 2010-10-29 02:10:45
回答 1查看 825关注 0票数 2

我遇到了以下问题:

我的Delphi7程序在大多数运行WinXP/Vista/7的计算机上运行得很流畅,但在一些较旧的Windows XP安装程序(只有几个)上,我遇到了以下问题:

我有一个系统镜像列表,并且我正在将我自己的图标添加到系统镜像列表的副本中。在添加我的图标时,我得到一个“无效的图像大小”。EInvalidOperation错误。

下面是有问题的代码:

代码语言:javascript
复制
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函数:

代码语言:javascript
复制
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程序崩溃。

有什么办法解决这个问题吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-29 02:18:03

您可以尝试的一件事是将图标加载到单独的tBitmap中,然后在将其添加到图像列表之前调整其大小。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4045884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档