function AddResource(sResource : PAnsiChar): Integer;
var
UseStyle, hMain,
nIndex , nCount: Integer;
hImage : Cardinal;
i: Integer;
begin
nCount := 0;
GetShortPathName(sResource, @zTmp, SIZEOF(zTmp));
for i := 0 to high(zTmp) do
begin
zTmp[i] := UpperCase(zTmp[i])[1];
end;
hMain := wMainWindow(0);
UseStyle := WS_CHILD or LBS_HASSTRINGS;
hLISTFNAME := GetMainItem(ID_LISTFNAME);
if hLISTFNAME = 0 then
hLISTFNAME := CreateWindowEx(0, 'LISTBOX', nil,
UseStyle, 0, 0, 0, 0, hMain, ID_LISTFNAME, GetInstance, nil);
hLISTIMAGE := GetMainItem(ID_LISTIMAGE);
if hLISTIMAGE = 0 then
hLISTIMAGE := CreateWindowEx(0, 'LISTBOX', nil,
UseStyle, 0, 0, 0, 0, hMain, ID_LISTIMAGE, GetInstance, nil);
if hLISTFNAME <> 0 then
begin
nIndex := SendMessage(hLISTFNAME, LB_FINDSTRING, -1, integer(@zTmp));
if nIndex > -1 then // gleicher Eintrag gefunden
begin
SendMessage(hLISTIMAGE, LB_GETTEXT, nIndex, integer(@zData));
hImage := StrLen(zData);
// lese den string ein
SendMessage(hLISTFNAME, LB_GETTEXT, nIndex, integer(@zTmp));
// lösche den alten Eintrag bevor er aktualisiert wird
SendMessage(hLISTFNAME, LB_DELETESTRING, nIndex, 0);
SendMessage(hLISTIMAGE, LB_DELETESTRING, nIndex, 0);
sResource := PChar(RightStr(string(zTmp), 5));
// zTmp := sResource + RightStr('0000' + LTrim(IntToStr(nCount)), 4);
if SendMessage(hLISTFNAME, LB_ADDSTRING, 0, integer(@zTmp)) < 0 then
hImage := 0 ;
if SendMessage(hLISTIMAGE, LB_ADDSTRING, 0, integer(@zData)) < 0 then
hImage := 0;
end else
begin
// kein eintrag gefunden addieren
hImage := GDI_CreateImageFromFile((sResource));
if hImage <> 0 then
begin
// zTmp := PChar(zTmp + '0001');
if SendMessage(hLISTFNAME, LB_ADDSTRING, 0, integer(@zTmp)) < 0 then
GDI_DisposeImage(hImage);
if hImage <> 0 then
begin
// zData := PChar(IntToStr(hImage));
if SendMessage(hLISTIMAGE, LB_ADDSTRING, 0, integer(@zTmp)) < 0 then
hImage := 0;
end;
end;
end;
end;
Result := hImage;
end;