Nachdem die Datenübertragung nun einigermaßen funktioniert gibt es Probleme beim Auspacken des Icons:
Code:
function TX11TBNA.ImgList_AddIcon (HIcon : HIcon) : Integer;
var tmp : TIcon;
begin
tmp := TIcon.Create;
try
tmp.Handle := hIcon; // <===
result := ImageList1.AddIcon(tmp);
if result=-1 then // auf jeden Fall prüfen, damit man weiss was Sache ist
ShowMessage('AddIcon failed !'); // anzeigen oder sonstwie protokollieren
finally
tmp.Free;
end;
end;
procedure TX11TBNA.WMCopyData(var Msg: TWMCopyData);
var tmp: TBNApaket; lPtmp: ^TBNApaket;
lpmsg : DWord;
lpData : PNotifyIconData;
begin
lptmp := Msg.CopyDataStruct.lpData;
tmp := lptmp^;
lpmsg := tmp.msg;
lpdata := @tmp.Data;
AddIcon (lpmsg, lpdata);
end;
function TX11TBNA.AddIcon (dwMessage: DWORD; lpData: PNotifyIconData) : Boolean;
var i, imgpos : Integer; tmp : TIcon;
begin
imgpos := -1;
For i := 0 to Listview1.Items.Count-1 do
if (StrToInt (Listview1.Items[i].SubItems[0]) = lpData.Wnd) and
(StrToInt (Listview1.Items[i].SubItems[1]) = lpData.uID) then
imgpos := I;
if dwMessage = NIM_ADD then begin
ShowMessage ('ADD');
If imgpos < 0 then
with Listview1.Items.Add do begin
ImageIndex := ImgList_AddIcon (lpData.hIcon);
Caption := lpdata.szTip;
SubItems.Add (IntToStr(lpdata.uID));
SubItems.Add (IntToStr(lpdata.Wnd));
end;
end
else
if dwMessage = NIM_MODIFY then begin
ShowMessage ('Modify');
If imgpos > -1 then
with ListView1.Items [i] do begin
ImageIndex := ImgList_AddIcon (lpData.hIcon);
Caption := lpdata.szTip;
SubItems.Add (IntToStr(lpdata.uID));
SubItems.Add (IntToStr(lpdata.Wnd));
end
else
with Listview1.Items.Add do begin
ImageIndex := ImgList_AddIcon (lpData.hIcon);
Caption := lpdata.szTip;
SubItems.Add (IntToStr(lpdata.uID));
SubItems.Add (IntToStr(lpdata.Wnd));
end;
end
else
if dwMessage = NIM_DELETE then begin
ShowMessage ('Delete');
If imgpos > -1 then
ListView1.Items.Delete (imgpos);
end
else ShowMessage ('Command not found!');
end;
In der function ImgList_AddIcon scheint Imagelist1.AddIcon immer -1 zurückzugeben... Warum?