Autor Beitrag
klezmor
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: So 02.10.05 15:14 
Hallo bei meinem Porgramm soll sich die eigene exefile in ein anderes Verzeichnis mit neuem icon kopieren.
Der neue icon muss jedoch schon in der exefile irgendwo vorliegen, kann also nicht aus irgendeinem verzeichnis geladen werden.
Weiß jemand wie das gehen soll?

noch ein zusatz es gibt doch sicher in der delphi lib oder der api
einpaar icons, die ich über units einbinden könnte kennt von euch jemand eine unit, mit icons.

MFG Klezmor



Moderiert von user profile iconKlabautermann: Topics zusammengefasst.
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mo 03.10.05 09:04 
MhhKompliziert also Icons müssen ja als Resourcen ind der .EXE vorliegen, was anderes macht auch iconlist nicht. Das Anwendungscon ist meines Wissens nach immer das unter 0-Mainicon.

Also entweder patchst du das binär oder es ist irgendwo in der .EXE ein Verweis welches Resourceicon als Anwendungsicon verwendet werden soll(glaub ich aber weniger).
Einfacher wäre es sicherlich das Icon der Startmenüverknüpfung zu ändern aber ich spekuliere mal das du so eine Art "Tarnfunktion" bauen willst?


Kompilierte Delph Units können Icons haben, unkompilierte müssen ide per Compilerschalter als Resourcedatei einbinden. Andere Executables können Resourcen enthalten, wo in den Standartwindowssdateien findest du unter:
www.windowsdevcenter...VB_icons.html?page=3

Laden Tust du die immer mit LoadResource oder so.
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 03.10.05 11:22 
Ist wirklich nicht einfach - es gibt dafür die API-Funktion UpdateResource, hier der MSDN-Link zur Beschreibung von Microsoft:
msdn.microsoft.com/l...2_Updating_Resources

Problem bei Icons ist, dass sie nicht aus einer Ressource sondern aus mehreren bestehen - dem Verzeichnis und den einzelnen Icons.

Ressourcen vom Typ RT_GROUPICON haben am Anfang 6 Bytes die folgende Struktur:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
const
  IMAGE_ICON = 1;
  IMAGE_CURSOR = 2;

type
  PIconDirHeader = ^TIconDirHeader;
  TIconDirHeader = packed record
    idReserved: word;                  // Always 0
    idType: word;                      // Type of image: IMAGE_...
    idCount: word;                     // Number of icons/cursors
  end;


und danach kommt idCount mal die Struktur:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type
  PIconResDirEntry = ^TIconResDirEntry;
  TIconResDirEntry = packed record
    bWidth: byte;                      // Width (pixel)
    bHeight: byte;                     // Height (pixel)
    bColorCount: byte;                 // Number of colors (if < 256, else 0)
    bReserved: byte;                   // Always 0
    wPlanes: word;                     // Icons: Number of planes (ignore, 0)
                                       // Cursors: Hotspot X-position (pixel)
    wBitCount: word;                   // Icons: Number of bits/pixel (maybe 0)
                                       // Cursors: Hotspot Y-position (pixel)
    dwBytesInRes: longint;             // Image size in file
    nResId: word;                      // Numerical ID of the icon resource
  end;


hier steht in nResId die Nummer der Ressource vom Typ RT_ICON für den Verzeichniseintrag.

Das Verzeichnis (RT_GROUPICON) sowie die Einzelbilder (RT_ICON) musst du dann alle via UpdateResource kopieren. Problem wird hier sein, dass das neue Icon ggf. mehr oder weniger Einzelbilder hat als das alte. Du könntest die alten aber einfach drin stehen lassen und statt dessen neu Nummerieren.

Vielleicht findest du im Internet ja ein Beispiel, wenn du nach UpdateResource und RT_GROUPICON suchst.
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 03.10.05 11:37 
Gibt es keinen einfacheren weg? Z.B.ein icon in einer Form zu speichern.
Ich habe mir überlegt, das icon über die timage komponente auf die Form zu ziehen, aber wenn ich der application per application.icon:='myicon'; das versteckte icon der Form zuweisen möchte, geht dies nicht, da da myicon ja vom typ Timage und nicht vom typ Ticon ist.
Gibt es vielleicht eine typumwandlung von Timage nach Ticon, das müsst ja dann funktionieren oder?
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 03.10.05 12:05 
Formular-Icons speichert Delphi als Binärstream in der Formular-Ressource (DFM-Datei) ab und nicht als eigene Ressource.

Außerdem würde die Zuweisung "Application.Icon := irgendwas" nur für die Laufzeit funktionieren und nicht das Icon beständig wechseln (das geht übrigens, wenn du ein Icon in eine RC/RES-Datei einbindest, diese per {$R icon.res} in dein Projekt einbindest und dann per "Application.Icon := LoadIcon(hInstance, 'Name');" zuweist).

Das im Explorer angezeigte (ich denke, dass du das meinst) ist die erste Ressource vom Typ RT_GROUPICON, die in der EXE gefunden wird. Schau dir das Ganze mal mit dem Resource Hacker an.
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 03.10.05 12:38 
ich habe mit dem iconeditior eine resourcefile erstellt und abgespeichert sie heiß:
myicon.res
nun binde ich sie mit dem befehl {$R myicon.res} in die unit meines projektes ein.
Rufe ich nun den befehl Application.Icon := LoadIcon(hInstance, 'myicon'); im form.create ereignis auf so kommt folgende fehlermeldung:
[Error] Unit1.pas(112): Incompatible types: 'TIcon' and 'HICON' Was kann ich tun?
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 03.10.05 12:40 
Sorry, mein Fehler

ausblenden Delphi-Quelltext
1:
Application.Icon.LoadFromResourceName(hInstance, 'myicon');					
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 03.10.05 12:49 
bei mir kommt jetzt die fehlermeldung :
[Error] Unit1.pas(112): Undeclared identifier: 'LoadFromResourceName' seltsam liegt das an meiner delphiversion, oder muss ich noch eine uses einbinden?
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 03.10.05 12:57 
Ich habe das gefühl, dass ich die methode LoadFromResourceName nicht auf application.icon anwenden kann. aber wie soll ichs dann machen?
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 03.10.05 13:04 
Normal sollte das aber gehen!

TIcon ist in Graphics.pas deklariert und hat dort die public Eigenschaft LoadFromResourceName - sicher, dass du es richtig geschrieben hast (Vervollständigung ausprobiert)?
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 03.10.05 13:13 
Ja ich habe schon alles versucht, aber scheinbar hat ticon doch nicht diese methode.
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 03.10.05 13:14 
ich finde die unit graphics.pas gar nicht nur die compilierten graphic.dcu liegt das möglicherweise daran?
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 03.10.05 13:34 
Probierst du's mit D3 oder D6?

Ansonsten versuche:
ausblenden Delphi-Quelltext
1:
Application.Icon.Handle := LoadIcon(hInstance, 'myicon');					
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 03.10.05 15:08 
funktioniert auch nicht.er compiliert zwar, aber zur laufzeit ändert sich der icon nicht.
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 03.10.05 20:18 
Welches Icon denn?

Application.Icon ist das Icon der Anwendung (im Taskbar)
Application.MainForm.Icon ist das Icon des Hauptformulars

Beides hat nichts mit dem Icon der EXE-Datei zu tun. Der Explorer zeigt immer das Icon mit dem alphabetisch kleinsten Namen an - nenne deins 'AAAA' und dann müsste die Anwendung eben das Icon zeigen - das kannst du dann aber auch einfacher in den Projekteigenschaften einstellen.
klezmor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Sa 08.10.05 19:46 
Ja das ist mir auch klar, dass ich das in den Projekeigenschaften einstellen kann, aber ich will ja das icon der kopierten exefile zur laufzeit ändern ändern.
Heißt wärend mein Programm läuft, soll das icon einer xbeliebigen exefile verändert werden.
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: So 09.10.05 21:49 
Mir fällt da wirklich nur ein das Icon manuell zu patchen.

1.Kopie der .EXE anlegen lassen
2.Kopie Offset des Icons anfahren
3.Iconbereich ersetzen lassen
4.Anwendung beenden und über 2.Programm Orginal überschreiben lassen

Ist aber relativ dirty, was anderes fällt mir da wirklich nicht ein, da bin ich mit dem PE Format nicht sooo vertraut.
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 10.10.05 00:02 
user profile icondigi_c hat folgendes geschrieben:
Ist aber relativ dirty, was anderes fällt mir da wirklich nicht ein, da bin ich mit dem PE Format nicht sooo vertraut.

Musst du auch nicht, dafür gibt's die API-Funktion Suche im MSDN UPDATERESOURCE (der Link und weitere Hinweise stehen schon oben).

Was das Ganze kompliziert macht, ist ganz einfach die Tatsache, dass ein Icon in der EXE-Datei nicht nur eine Ressource ist, sondern aus dem RT_ICONDIR Verzeichnis besteht und jedes Einzelbild ein RT_ICON Eintrag ist.