开发者

Delphi7 CustomImageList problem

I've run into the following problem:

My Delphi7 program runs smoothly on most computers running WinXP/Vista/7 BUT on some older Windows XP installs (only a few) I'm getting the following problem:

I have a system image list, and I'm adding my own icons to a copy of the system image list. Upon adding my icons I get an "Invalid image size." EInvalidOperation error.

Here is the code in question:

function GetSystemLargeIconsLis开发者_运维百科t: 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

To make the problem worse, I'm using the TPngImageList component, but according to the code, it just seems to call the standard Delphi function:

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;

I've recently found out that on one of the computers that have this problem, either uxtheme.dll or explorer.exe has been patched with some Windows-skinning program.

So I suppose that somebody or a program is hacking the system image list in a way that is making my Delphi program crash.

Any ideas on how to fix this?

Thanks!


One thing you could try would be to load your icon into a separate tBitmap, then resize it before adding it into the image list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜