Autor Beitrag
Coder84
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 08.01.04 12:42 
Wie kann ich das Icon einer EXE-Datei ändern ?
mk3
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Do 08.01.04 13:21 
Project/Options/Application/ Load Icon...

Grüße
mk
Coder84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 08.01.04 13:47 
*g* Ich meinte nicht die EXE-Datei meines Delphi-Programms. Ich wollte viel mehr das Icon einer fremden EXE-Datei ändern über mein Delphi-Programm ändern.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Do 08.01.04 13:47 
ich glaub er will zur laufzeit das icon einer externen Exe dauerhaft ändern

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
Coder84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 08.01.04 13:59 
Zur laufzeit meines Programmes, ja.
Das ich das Icon eines Programmes nich ändern kann wärend es läuft ist mir schon klar.

also nochmal ganz ganau:
Mein Programm soll nach einem Klick auf einen Button das Icon einer anderen (nicht im speicher befindlichen) EXE-Datei dauerhaft ändern.

Hab dazu schonmal nen versuch gewagt, aber irgendwie klappt das nicht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);
var Ico:TIcon;
    hInst:THandle;
begin
   ico:=TIcon.Create;
   ico.LoadFromFile('D:\TEST.ICO');
   Image1.Picture.Icon:=Ico;
   hInst:=BeginUpdateResource('D:\TEST.EXE', False);
   if hInst > 0 then
    begin
     UpdateResource(hInst, RT_ICON, 'MAINICON', LANG_NEUTRAL, @ico , SizeOf(ico));
     EndUpdateResource(hInst, False);
    end;
end;
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Do 08.01.04 14:10 
Ich glaube das ist, wenn überhaupt, nur sehr sehr schwierig lösbar...
Es würde mcih allerdings erfruen wenn mir einer das gegenteil erweist *gg*

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
Coder84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 08.01.04 14:28 
hab die Zeihle mit dem UpdateRecource jetzt wie folgt abgeändert:
ausblenden Delphi-Quelltext
1:
UpdateResource(hInst, RT_ICON, MAKEINTRESOURCE(1), LANG_NEUTRAL, @ico , SizeOf(ico));					

Jetzt ändert sich zwar das Icon, aber auf das Standart Windows/DOS Icon und nicht auf das was eigendlich geplant war. Man könnte quasi sagen ich hab das Icon gekillt. Würde mich freuen, wenn mir jemand sagen könnte, woran das liegt.

Mein Verdacht:
Der letzt Parameter, da bin ich mir nocht ganz sicher ob der stimmt. Befürchte fast das muss ich anders machen.
Coder84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 08.01.04 16:31 
Hab mal das C-Beispiel von MSDN nach Delphi übersetzt und an meine bedürfnisse angepasst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button1Click(Sender: TObject);
var hExe, hRes,  hResLoad, hUpdateRes : THandle;
    lpResLock                         : Pointer;
begin
 hExe:=LoadLibrary('source.exe');
 hRes:=FindResource(hExe,MAKEINTRESOURCE(1),RT_ICON);
 hResLoad:=LoadResource(hExe, hRes);
 lpResLock:=LockResource(hResLoad);
 hUpdateRes := BeginUpdateResource('destination.exe', FALSE);
 UpdateResource(hUpdateRes, RT_ICON, MAKEINTRESOURCE(1),  LANG_NEUTRAL, lpResLock, SizeOfResource(hExe,hRes));
 EndUpdateResource(hUpdateRes, False);
end;


Der hacken an der sache ist, das jetzt das Icon von der "destination.exe" dem der "source.exe" entspricht, ich wollte es aber aus einer ICO-Datei auslesen lassen.
ChatFix hat folgendes geschrieben:

Ich glaube das ist, wenn überhaupt, nur sehr sehr schwierig lösbar...
Es würde mcih allerdings erfruen wenn mir einer das gegenteil erweist *gg*


Wie du siehst, ist es nicht soooo schwer, auch wenn ich es bisher nicht gaschafft hab das Icon aus einer ICO-Datei zu nutzen.