AGB  ·  Datenschutz  ·  Impressum  







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

Application.Icon setzen

Ein Thema von freimatz · begonnen am 6. Apr 2018 · letzter Beitrag vom 9. Apr 2018
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    
freimatz

Registriert seit: 20. Mai 2010
1.380 Beiträge
 
Delphi 11 Alexandria
 
#1

Application.Icon setzen

  Alt 6. Apr 2018, 18:24
Hallo,
in meiner App erscheint zuerst ein SpashScreen. Das ist eine einfache TForm. Das Hauptformular wird erst später geladen. Ich möchte nun dass in der Taskleiste nun gleich ein Icon und der Titel erscheint.
Beim Titel klappt das mit Application.Titel recht gut, beim Icon gelingt es mir nicht.
Wie macht man das am Besten, woran kann es liegen?
Letzter Versuch war:
Delphi-Quellcode:
       
       Icon := TIcon.Create;
       try
         SplashForm.cxImageListMainIcon.GetIcon(0, Icon);
         Application.Icon.Assign(Icon);
       finally
         Icon.Free;
       end;
cxImageListMainIcon ist dabei einem Imagelist. Mit einem TImage gings auch nicht. Auch nicht mit SplashForm.Icon.
Für Ideen oder eine Lösung wäre ich dankbar.
  Mit Zitat antworten Zitat
günni0
(Gast)

n/a Beiträge
 
#2

AW: Application.Icon setzen

  Alt 6. Apr 2018, 18:42
Application.Icon := SplashForm.cxImageListMainIcon.GetIcon(0, Icon);
sollte eigentlich funktionieren.

Geändert von günni0 ( 6. Apr 2018 um 18:54 Uhr)
  Mit Zitat antworten Zitat
freimatz

Registriert seit: 20. Mai 2010
1.380 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Application.Icon setzen

  Alt 6. Apr 2018, 18:52
Danke. Leider Nein: [DCC Fehler] Fm_Splash.pas(70): E2010 Inkompatible Typen: 'TIcon' und 'procedure, untyped pointer or untyped parameter': GetIcon ist keine function.
(PS.: gegooglet habe ich auch schon lange.)
  Mit Zitat antworten Zitat
günni0
(Gast)

n/a Beiträge
 
#4

AW: Application.Icon setzen

  Alt 6. Apr 2018, 18:53
Mein Fehler. So natürlich:

Delphi-Quellcode:
IconX := SplashForm.cxImageListMainIcon.GetIcon(0, Icon);

Application.Icon := IconX;
  Mit Zitat antworten Zitat
freimatz

Registriert seit: 20. Mai 2010
1.380 Beiträge
 
Delphi 11 Alexandria
 
#5

AW: Application.Icon setzen

  Alt 6. Apr 2018, 21:33
Sorry, dadurch wird GetIcon immer noch nicht zu einer function
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Application.Icon setzen

  Alt 6. Apr 2018, 22:21
So hole ich mir zur Laufzeit Icons aus der Resource:

Delphi-Quellcode:
{$R MYICONS.RES}

procedure TForm1.Button1Click(Sender: TObject);
var
  h : hIcon;
begin
  h := LoadIcon(hInstance, 'ICON_1');
  Application.Icon.Handle := h;
  InvalidateRect(Application.Handle, nil, true);
end;
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
günni0
(Gast)

n/a Beiträge
 
#7

AW: Application.Icon setzen

  Alt 6. Apr 2018, 22:24
Na dann jetzt aber nochmal richtig ...
Delphi-Quellcode:
SplashForm.cxImageListMainIcon.GetIcon(0, Icon);
Application.Icon := Icon;
oder direkt ohne Zwischenvariable

SplashForm.cxImageListMainIcon.GetIcon(0, Application.Icon);

Geändert von günni0 ( 6. Apr 2018 um 22:38 Uhr)
  Mit Zitat antworten Zitat
freimatz

Registriert seit: 20. Mai 2010
1.380 Beiträge
 
Delphi 11 Alexandria
 
#8

AW: Application.Icon setzen

  Alt 7. Apr 2018, 08:53
Funktioniert leider auch nicht - außer dass es später eine Schutzverletzung gibt (vermutlich weil es dann SplashForm und soit auch das Icon nicht mehr gibt.)

@KodeZwerg: Danke. Das sieht jetzt eher lowlevel aus. Versucht habe ich es so:
Delphi-Quellcode:
  h := LoadIcon(hInstance, 'MAINICON');
  Application.Icon.Handle := h;
  InvalidateRect(Application.Handle, nil, true);
Es funktionert aber auch nicht. Nach dem Debugger hat h einen Wert. Nach der Doku ("If the function succeeds, the return value is a handle to the newly loaded icon. If the function fails, the return value is NULL. To get extended error information, call GetLastError.") müsste das Laden ja dann geklappt haben weil h ist ja nicht NULL.
Application, Application.Icon.Handle und Application.Handle habe nach Debugger auch was drin.
Das Icon erscheint aber nicht bei mir.

Ich habe den Verdacht dass mir DevExpress da noch irgendwie reinspuckt.

Aufgrund von https://stackoverflow.com/questions/...plication-icon mein neuster letzter erfolgloser Versuch:
Delphi-Quellcode:
var
  hApp: HWND;
  hSmall : hIcon;
  hLarge : hIcon;
begin
  hApp := Application.Handle;

  hSmall := LoadImage(HInstance, 'MAINICON', IMAGE_ICON,16, 16, 0);
  hLarge := LoadImage(HInstance, 'MAINICON', IMAGE_ICON,256, 256, 0);

  SendMessage(hApp, WM_SETICON, ICON_SMALL, hSmall) ;
  SendMessage(hApp, WM_SETICON, ICON_BIG, hLarge) ;

  InvalidateRect(hApp, nil, true);
  UpdateWindow(hApp);
end;
Ich gebs mal vorläufig auf.
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Application.Icon setzen

  Alt 7. Apr 2018, 09:25
Delphi-Quellcode:
{$R MYICONS.RES}

procedure TForm1.Button1Click(Sender: TObject);
var
  h : hIcon; // wir brauchen das Handle, nicht das Image, deswegen HICON
begin
  h := LoadIcon(hInstance, 'ICON_1'); // in Resource-Datei MyIcons.res ist ein Eintrag Namens ICON_1, Handle dahin erzeugen
  Application.Icon.Handle := h; // Handle an das Programm übergeben
  InvalidateRect(Application.Handle, nil, true); // Programm update
end;
Also in MyIcons.res existiert ein Icon was den Namen "ICON_1" bekommen hat, dem System ist in der Regel die Größe egal da es von selbst runter/hoch skaliert. Ich hab keinen Check drinn da die Resource bei mir immer existiert. Ob es LowLevel ist kann ich nicht sagen, nur das es bei mir auf diese Weise klappt kann ich sagen.

Code:
SendMessage(hApp, WM_SETICON, ICON_BIG, h);
sollte das WinApi Äquivalent sein und genügen.
Ich vermute LoadImage() macht nicht das gleiche wie LoadIcon().

Code:
SendMessage(hApp, WM_SETICON, ICON_BIG, LoadIcon(hInstance, 'MAINICON'));
Probier's mal so.
Gruß vom KodeZwerg

Geändert von KodeZwerg ( 7. Apr 2018 um 09:37 Uhr)
  Mit Zitat antworten Zitat
günni0
(Gast)

n/a Beiträge
 
#10

AW: Application.Icon setzen

  Alt 7. Apr 2018, 11:06
Zitat:
Funktioniert leider auch nicht - außer dass es später eine Schutzverletzung gibt (vermutlich weil es dann SplashForm und soit auch das Icon nicht mehr gibt.)
Wenn das hier nicht funktioniert stimmt irgendwas in deinem Projekt aber nicht. Einfacher gehts nicht.

SplashForm.cxImageListMainIcon.GetIcon(0, Application.Icon);
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    


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 23:03 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