Autor Beitrag
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 20.06.03 22:51 
Hallo,

ich habe in meiner anwendung ein Icon eingebunden, das mehrere Auflösungen unterstützt (also mehrere verschieden große Icons in einer ICO-Datei). Wenn ich es jetzt aus der Reeource in ein TImage lade, wird es trotzdem immer mit 32x32 angezeigt. Leider sieht es erst ab 64x64 richtig schön aus. Wie kann ich also ein Icon mit einer bestimmten Auflösung laden?

_________________
Life is a bad adventure, but the graphic is really good!
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: So 06.07.03 00:45 
Mit der Windows-API-Funktion LoadImage. Dann musst Du's allerdings auch mit DrawIconEx zeichnen (glaube ich zumindest... ich schätze mal, das TIcon würde es mit einem 64x64-Icon nicht hinbekommen). Also statt des TImages nimmst Du eine PaintBox, und für das OnPaint-Event folgenden Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.PaintBox1Paint(Sender: TObject);
var theIco: HICON;
begin
  theIco := LoadImage(hInstance, 'MAINICON', IMAGE_ICON, 64,64, LR_DEFAULTCOLOR or LR_SHARED);
  DrawIconEx(TPaintBox(Sender).Canvas.Handle, 0,0, theIco, 64,6400, DI_NORMAL);
end;
Hab's allerdings nicht mit 'nem 64x64-Icon getestet... sag mal Bescheid, ob's geht!

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: So 06.07.03 10:41 
Hallo,

super, es klappt! :D

Du hast Recht, es klappt nur, wenn man mir drawIconEx() zeichnet. aber d as mach tja nix. Danke nochmals!

EDIT: Habe grade in der Online-Doku nachgeschlagen:
1) Man darf NICHT als "Shared" laden, wenn das Icon mehrere Auflösungen hat
2) Muss ich das Icon freen? mit FreeIcon(), oder ist das hier nicht nötig?

_________________
Life is a bad adventure, but the graphic is really good!
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: So 06.07.03 19:03 
Hmm... also dann würde ich sagen, um es ganz korrekt zu machen, speicher das Handle in einer globalen Variable (oder einem Feld in der TForm), führ LoadImage nur einmal bei OnCreate aus, und ruf FreeIcon bei OnDestroy auf. Wenn dann immer noch alles funktioniert, wäre die Lösung wahrscheinlich sauberer :)

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: So 06.07.03 19:49 
Hallo,

also, wenn ich es lade, und dann destroye, dann wird es NICHT mehr gerendert. Fazit: DestroyIcon() wird benötigt. Oder was meinst du?

_________________
Life is a bad adventure, but the graphic is really good!
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Mo 07.07.03 00:06 
Also Du solltest es bei Form1.OnCreate laden, bei PaintBox1.OnPaint (oder wie die Paintbox auch heißt) per DrawIconEx zeichnen, und bei Form1.OnDestroy wieder freigeben, wie auch immer (was sagt Microsoft dazu?).
Wenn das nicht mehr klappt, probier mal, das LR_SHARED wieder aufzunehmen, bei mir ging's mal nur mit LR_SHARED, und nicht ohne...
Und wenn's dann immernoch nicht klappt, nimm halt die erste Version wieder, so wie ich's gepostet hatte. Vielleicht muss man es gar nicht freigeben, sondern Windows macht das automatisch, wenn das zugehörige Programm geschlossen wird.

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Andreas Pfau Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Mo 07.07.03 16:09 
Hallo,

nun, es geht ja so. Ich lade ohne Shared. DestroyIcon() funzt. Danke für deine Hilfe!

PS: Wenn du es selber probieren willst, aber kein Icon hast, hol' dir mit 'nem ResHacker das Icon von MSWordXP, das hat 64x64. Dann kannst du ja selber rumtüfteln.

_________________
Life is a bad adventure, but the graphic is really good!