Einzelnen Beitrag anzeigen

Benutzerbild von FriFra
FriFra

Registriert seit: 19. Apr 2003
1.291 Beiträge
 
Delphi 2005 Professional
 
#1

Icons verbrauchen alle Resourcen...

  Alt 25. Jan 2004, 01:26
Ich weiss, dass ich irgendwo etwas falsch mache, zumindest fängt bei wiederholter Ausführung der folgenden Funktion der Rechner irgendwann komplett an zu spinnen... obwohl eigentlich alles jeweils korrekt freigegeben wird.

Delphi-Quellcode:
procedure TForm1.SetIcon(Loading, Ignoring, Stopped, Plugin:
  boolean);
  function CombineIcons(FrontIcon, BackIcon: HIcon): HIcon;
  var
    WinDC: HDC;
    FrontInfo: TIconInfo;
    FrontDC: HDC;
    FrontSv: HBITMAP;
    BackInfo: TIconInfo;
    BackDC: HDC;
    BackSv: HBITMAP;
    BmpObj: tagBitmap;
  begin
    WinDC := GetDC(0);

    GetIconInfo(FrontIcon, FrontInfo);
    FrontDC := CreateCompatibleDC(WinDC);
    FrontSv := SelectObject(FrontDC, FrontInfo.hbmMask);

    GetIconInfo(BackIcon, BackInfo);
    BackDC := CreateCompatibleDC(WinDC);
    BackSv := SelectObject(BackDC, BackInfo.hbmMask);

    GetObject(FrontInfo.hbmMask, SizeOf(BmpObj), @BmpObj);
    BitBlt(BackDC, 0, 0, BmpObj.bmWidth, BmpObj.bmHeight, FrontDC, 0, 0,
      SRCAND);

    SelectObject(BackDC, BackInfo.hbmColor);
    DrawIconEx(BackDC, 0, 0, FrontIcon, 0, 0, 0, 0, DI_NORMAL);

    Result := CreateIconIndirect(BackInfo);

    SelectObject(FrontDC, FrontSv);
    DeleteDC(FrontDC);
    SelectObject(BackDC, BackSv);
    DeleteDC(BackDC);
    ReleaseDC(0, WinDC);
    DeleteObject(FrontInfo.hbmColor);
    DeleteObject(FrontInfo.hbmMask);
    DeleteObject(BackInfo.hbmColor);
    DeleteObject(BackInfo.hbmMask);
    DeleteObject(FrontSv);
    DeleteObject(BackSv);
  end;
var
  RS: TResourceStream;
  sI: string;
  Ico: array[0..8] of TIcon;
  n: integer;
begin
  for n := 0 to High(Ico) do
    Ico[n] := TIcon.Create;

  try
    StrPLCopy(IconData.szTip, '[' + Label2.Caption + ']'#13 + 'WAN-IP: ' +
      Edit3.Text + #13 + 'LAN-IP: ' + Edit4.Text, 63);

    if G_IP = '0.0.0.0'#0 then
      sI := 'I_Inactive'
    else if G_IP = '0.0.0.0then
      sI := 'I_Offline'
    else
      sI := 'I_Online';
    try
      RS := TResourceStream.Create(0, sI + GetIconSufix, RT_RCDATA);
      RS.Position := 0;
      Ico[0].LoadFromStream(RS);
    finally
      RS.Free;
    end;

    { Ladeanzeige }
    if Loading then
      sI := 'I_Loading'
    else
      sI := 'I_Blank';
    try
      RS := TResourceStream.Create(0, sI + GetIconSufix, RT_RCDATA);
      RS.Position := 0;
      Ico[1].LoadFromStream(RS);
    finally
      RS.Free;
    end;
    Ico[2].Handle := CombineIcons(Ico[1].Handle, Ico[0].Handle);

    if Ignoring then
      sI := 'I_Ignoring'
    else
      sI := 'I_Blank';
    try
      RS := TResourceStream.Create(0, sI + GetIconSufix, RT_RCDATA);
      RS.Position := 0;
      Ico[3].LoadFromStream(RS);
    finally
      RS.Free;
    end;
    Ico[4].Handle := CombineIcons(Ico[3].Handle, Ico[2].Handle);

    if Stopped then
      sI := 'I_Stop'
    else
      sI := 'I_Blank';
    try
      RS := TResourceStream.Create(0, sI + GetIconSufix, RT_RCDATA);
      RS.Position := 0;
      Ico[5].LoadFromStream(RS);
    finally
      RS.Free;
    end;
    Ico[6].Handle := CombineIcons(Ico[5].Handle, Ico[4].Handle);

    if Plugin then
      sI := 'I_Plugin'
    else
      sI := 'I_Blank';
    try
      RS := TResourceStream.Create(0, sI + GetIconSufix, RT_RCDATA);
      RS.Position := 0;
      Ico[7].LoadFromStream(RS);
    finally
      RS.Free;
    end;
    Ico[8].Handle := CombineIcons(Ico[7].Handle, Ico[6].Handle);

    DestroyIcon(TNA_Icon.Handle);
    TNA_Icon.Assign(Ico[8]);
    DestroyIcon(IconData.hIcon);
    IconData.hIcon := TNA_Icon.Handle;

    { Statusanzeige }
    DestroyIcon(Image1.Picture.Icon.Handle);
    Image1.Picture.Icon.Handle := IconData.hIcon;
    Image1.Repaint;
    Edit3.Text := G_IP;
    Label7.Caption := G_IT;

    if G_IP = '0.0.0.0'#0 then
      Label2.Caption := 'undefined'
    else if G_IP = '0.0.0.0then
      Label2.Caption := 'Offline'
    else
      Label2.Caption := 'Online';

    if IsMinimized = True then
      Shell_NotifyIcon(NIM_MODIFY, @IconData);

  finally
    for n := 0 to High(Ico) do
    begin
      Ico[n].ReleaseHandle;
      DestroyIcon(Ico[n].Handle);
      FreeAndNil(Ico[n]);
    end;
    IconReady := True;
  end;
end;
Update: Ich verwende jetzt einen Array of Icon um eine bessere Übersichtlichkeit zu erreichen
Elektronische Bauelemente funktionieren mit Rauch. Kommt der Rauch raus, geht das Bauteil nicht mehr.
  Mit Zitat antworten Zitat