AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Icon ersetzen funktioniert nicht

Ein Thema von Uncle Cracker · begonnen am 16. Jul 2004 · letzter Beitrag vom 16. Jul 2004
 
Benutzerbild von Uncle Cracker
Uncle Cracker

Registriert seit: 30. Mär 2003
Ort: Freital
694 Beiträge
 
#1

Icon ersetzen funktioniert nicht

  Alt 16. Jul 2004, 11:04
Ich habe jetzt 2 Methoden probiert das Icon einer anderen selbsterstellten Delphi Anwendung zuändern, aber keine davon hat funktioniert, was muss ich denn noch machen?

Hier mal die beiden Funktionen:

Delphi-Quellcode:
type
  PICONDIRENTRYCOMMON = ^ICONDIRENTRYCOMMON;
  ICONDIRENTRYCOMMON = packed record
    bWidth: Byte; // Width, in pixels, of the image
    bHeight: Byte; // Height, in pixels, of the image
    bColorCount: Byte; // Number of colors in image (0 if >=8bpp)
    bReserved: Byte; // Reserved ( must be 0)
    wPlanes: Word; // Color Planes
    wBitCount: Word; // Bits per pixel
    dwBytesInRes: DWord; // How many bytes in this resource?
  end;
  PICONDIRENTRY = ^ICONDIRENTRY;
  ICONDIRENTRY = packed record
    common: ICONDIRENTRYCOMMON;
    dwImageOffset: DWord; // Where in the file is this image?
  end;
  PICONDIR = ^ICONDIR;
  ICONDIR = packed record
    idReserved: Word; // Reserved (must be 0)
    idType: Word; // Resource Type (1 for icons)
    idCount: Word; // How many images?
    idEntries: ICONDIRENTRY; // An entry for each image (idCount of 'em)
  end;
  PGRPICONDIRENTRY = ^GRPICONDIRENTRY;
  GRPICONDIRENTRY = packed record
    common: ICONDIRENTRYCOMMON;
    nID: Word; // the ID
  end;
  PGRPICONDIR = ^GRPICONDIR;
  GRPICONDIR = packed record
    idReserved: Word; // Reserved (must be 0)
    idType: Word; // Resource type (1 for icons)
    idCount: Word; // How many images?
    idEntries: GRPICONDIRENTRY; // The entries for each image
  end;
function UpdateApplicationIcon(icofile: PChar; exefile: PChar; resID:PcHar; LangID:DWORD): Boolean;
var
  hInst,hFile: THandle;
  id: ICONDIR;
  pid: PICONDIR;
  pgid: PGRPICONDIR;
  uRead: DWord;
  nSize: DWord;
  pvFile: PByte;
begin
  result := False;
  hFile := CreateFile(icofile, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  if hFile <> INVALID_HANDLE_VALUE then
  try
    ReadFile(hFile, id, sizeof(id), uRead, nil);
    SetFilePointer(hFile, 0, nil, FILE_BEGIN);
    GetMem(pid, sizeof(ICONDIR) + sizeof(ICONDIRENTRY));
    GetMem(pgid, sizeof(GRPICONDIR) + sizeof(GRPICONDIRENTRY));
    ReadFile(hFile, pid^, sizeof(ICONDIR) + sizeof(ICONDIRENTRY), uRead, nil);
    move(pid^, pgid^, sizeof(GRPICONDIR));
    pgid^.idEntries.common := pid^.idEntries.common;
    pgid^.idEntries.nID := 1;
    nSize := pid^.idEntries.common.dwBytesInRes;
    GetMem(pvFile, nSize);
    SetFilePointer(hFile, pid^.idEntries.dwImageOffset, nil, FILE_BEGIN);
    ReadFile(hFile, pvFile^, nSize, uRead, nil);
    hInst := BeginUpdateResource(exefile, False);
    if hInst <> 0 then
    try
      result:=UpdateResource(hInst, RT_ICON, resID, LangID, pvFile, nSize);
    finally
      EndUpdateResource(hInst, False);
    end;
    FreeMem(pvFile);
    FreeMem(pgid);
    FreeMem(pid);
  finally
    CloseHandle(hFile);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if UpdateApplicationIcon('Test.ico', 'Test.exe', MAKEINTRESOURCE(1), 1031) then
  Showmessage('Icon successfully updated') else Showmessage('Icon update failed Errorcode:', GetLastError);
end;
Als Fehlercode habe ich bei der oberen Funktion '0' erhalten.
Hier meine andere Methode, diese funktioniert ebenfalls nicht

Delphi-Quellcode:
function ErsetzeICO(Datei, ICO: string): Boolean;
var
   stream : TFilestream;
   hInst: THandle;
   ptr : Pointer;

begin
  result := false;
   Stream := TFileStream.Create(ICO,fmOpenRead);
   getmem (ptr,Stream.size+1);
   try
      Stream.Seek(0,sofrombeginning);
      stream.read(ptr^,Stream.size);
      hInst:=BeginUpdateResource(Pchar(Datei), true);
      if hInst > 0 then
         begin
         UpdateResource(hInst, RT_Icon, MAKEINTRESOURCE(1),
         1031,ptr,Stream.size);
         EndUpdateResource(hInst, False);
         result := true;
         end;
   finally
      freemem (ptr,Stream.size+1);
      stream.Free;
   end;
end;

Weiß vielleicht jemand, warum das Icon der EXE nicht ersetzt wird? Oder kennt vielleicht noch jemand eine andere Funktion zum ersetzten eines Icons?


Danke UC
I wish it was legal to marry software because I'm madly in love with Delphi...
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz