2010-10-28 22 views
2

我碰到以下問題:Delphi7的CustomImageList問題

我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已經修補了一些Windows皮膚程序。

所以我想有人或一個程序正在黑客系統圖像列表的方式,使我的Delphi程序崩潰。

關於如何解決此問題的任何想法?

謝謝!

回答

0

有一兩件事你可以嘗試將你的圖標加載到一個單獨的tBitmap,然後將其添加到圖像列表之前調整其大小。

+0

問題是我無法正確地測試它...我的代碼嚴重依賴於上述(因爲它適用於XP/Vista和7),即使我重寫它也不能保證它可以工作..我很確定這是一個Delphi7問題!這就是爲什麼我問如果有人看到過類似的東西... – Steve 2010-10-29 07:12:56

+0

如果你不能測試它,那麼你怎麼知道錯誤發生在哪條線?包裹成調用getIcon一個單獨的功能似乎並不像一個有風險的解決方案,因爲你應該能夠確認與不遇到問題機器正確的行爲。然後在一個測試它。 – skamradt 2010-10-29 16:42:47

+0

我使用EurekaLog來跟蹤錯誤 - 它給我回行號。你可以給你的解決方案的一些示例代碼?這可以正確使用具有透明背景的圖標嗎? – Steve 2010-10-29 17:26:19