Autor Beitrag
MarkusBauer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

Win XP Pro
Delphi 7 PE+Indy
BeitragVerfasst: Mo 29.05.06 17:10 
Ich habe mir ein einfaches Programm zum Testen der Trayicon-Funktionen erstellt.
Leider kann ich nur die Symbole IDI_Information, IDI_Warning und IDI_Error benutzen.
Ich würde jedoch gerne ein Symbol aus einer .ico-Datei verwenden.
Kann mir jemand helfen?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
unit T1;

interface

uses
  Windows, Classes, Graphics, Forms, Controls, Menus,
  Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls,
  ToolWin, ShellAPI, Messages;

const
  WM_TRAYICON = WM_USER + 1000;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
  IconData: TNotifyIconData;
  procedure TrayIconEvent(var Msg: TMessage); message WM_TRAYICON;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Hide;
Shell_Notifyicon(NIM_ADD, @IconData);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
with IconData do
  begin
    cbSize := SizeOf(TNOTIFYICONDATA);
    Wnd := Handle;
    uID := 1;
    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
    hIcon := LoadIcon(0, IDI_Warning);  //Hier sollte ein anderes Symbol entstehen
    szTip := 'Timer';
    uCallBackMessage := WM_TRAYICON;
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @IconData);
end;

procedure TForm1.TrayIconEvent(var Msg: TMessage);
begin
if Msg.LParam = WM_LBUTTONDOWN then
  { Show the window and hide the trayicon }
  begin
    Form1.Show;
    Shell_NotifyIcon(NIM_DELETE, @IconData);
  end;
end;

end.


Zuletzt bearbeitet von MarkusBauer am Mo 29.05.06 17:37, insgesamt 1-mal bearbeitet
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Mo 29.05.06 17:28 
Hi,
hast du schonmal folgendes probiert (nicht getestet) ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.FormCreate(Sender: TObject);   
var TestIcon : TIcon;
begin   
TestIcon := TIcon.create;
TestIcon.loadfromfile(...); //dein neues Icon;
with IconData do   
  begin   
    cbSize := SizeOf(TNOTIFYICONDATA);   
    Wnd := Handle;   
    uID := 1;   
    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;   
    //hIcon := LoadIcon(0, IDI_Warning);  //Hier sollte ein anderes Symbol entstehen   
    hIcon := temp.Handle; // TempIcon übernehmen
    szTip := 'Timer';   
    uCallBackMessage := WM_TRAYICON;   
  end;   
end;

//und am ende wieder TestIcon.free beim Form.close oder so


MFG, Arno Nym

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
MarkusBauer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

Win XP Pro
Delphi 7 PE+Indy
BeitragVerfasst: Mo 29.05.06 17:55 
Titel: Danke
Der Quelltext funktionert sehr gut,
sobald man temp.Handle durch TestIcon.Handle ersetzt hat.
Außerdem sollte man TestIcon allgemein definieren, um aus einer
anderen Prozedur heraus Testicon.Free ausführen kann.
Danke :D