Autor Beitrag
holgerbremen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 120



BeitragVerfasst: Mo 02.01.06 08:58 
Hallo,

ich möchte ein Anwendung schreiben, die nur als Symbol unten rechts in der Taskbar zu sehen ist. Was ist zu machen? Unter welchen Stichwort muss man hier suchen?

Gruß, Holger


Moderiert von user profile iconTino: Topic aus Sonstiges verschoben am Mo 02.01.2006 um 11:49
breakdancer1111
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 148

Windows 7 Home Premium 64Bit
Delphi XE2 Starter
BeitragVerfasst: Mo 02.01.06 09:07 
Such ab besten mal nach System Suche in der Entwickler-Ecke TRAY.
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Mo 02.01.06 09:50 
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:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
{Anwendung im SysTray anzeigen
Shell_NotifyIcon, TNotifyIconData
--------------------------------------------------------------------------------

Systray oder auch TNA (Taskbar Notification Area) nennt man den Bereich neben der Windows-Uhr in der Taskleiste. Besonders bei Programmen, die lange aktiv sind, kann es sinnvoll sein, diese in den platzsparenden Systray zu verschieben.

Zunächst muss eine sog. benutzerspezifische Botschaft in Form einer globalen Konstante erstellt werden. Als Basis wird dazu die Botschaft WM_USER verwendet:}


const
 WM_TASKBAREVENT = WM_USER + 1;
Es folgt die Deklaration des Prozedurkopfes dieser Botschaft.

Private
procedure WMTaskbarEvent(var Message: TMessage); message WM_TASKBAREVENT;
Über die folgenden Prozeduren wird das Icon im Systray angezeigt (TaskbarAddIcon) und wieder entfernt (TaskBarRemoveIcon):

procedure TaskBarAddIcon;
var
  tnid: TNotifyIconData;
  Owner: HWnd;
begin
  with tnid do
  begin
    cbSize := SizeOf(TNotifyIconData);
    Wnd := Form1.Handle;
    uID := 1;
    uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
    uCallbackMessage := WM_TASKBAREVENT;
    hIcon := Application.Icon.Handle;
  end;
  StrCopy(tnid.szTip, 'Tooltipp');
  Shell_NotifyIcon(NIM_ADD, @tnid);

  Owner:=GetWindow(Form1.Handle,GW_OWNER);
  If Owner<>0 Then
    ShowWindow(Owner,SW_HIDE);
end;

procedure TaskBarRemoveIcon;
var
  tnid: TNotifyIconData;
  Owner: HWnd;
begin
  tnid.cbSize := SizeOf(TNotifyIconData);
  tnid.Wnd := Form1.Handle;
  tnid.uID := 1;
  Shell_NotifyIcon(NIM_DELETE, @tnid);
  Owner:=GetWindow(Form1.Handle,GW_OWNER);
  If Owner<>0 Then Begin
    ShowWindow(Owner,SW_Show);
    ShowWindow(Owner,SW_Normal);
  End;
end;

//Nun folgt noch die Implementation unserer oben deklarierten Botschaft:

procedure TForm1.WMTaskbarEvent(var Message: TMessage);
var 
  Point: TPoint;
begin
  case Message.LParamLo of
     WM_LBUTTONDOWN: TaskBarRemoveIcon;
     WM_RBUTTONDOWN: begin
                          SetForegroundWindow(Handle);
                          GetCursorPos(point);
                          popupmenu1.popup(point.x,point.y);
                     end;
  end;
end;
{Klickt man mit der linken Maustaste auf das Icon (WM_LBUTTONDOWN), wird dieses entfernt. Mit einem Rechtsklick wird an der Stelle ein Kontextmenu (Popupmenu1) geöffnet.

Da die Anwendung in diesem Beispiel nur im minimierten Zustand in SysTray erscheinen soll, muss zusätzlich noch folgende Zeile in das Application-Ereignis OnMinimize:}


procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
 TaskBarAddIcon;
end;
{Seit Delphi 5 ist dieses Ereignis in der Komponente TApplicationEvents gekapselt. Arbeitest du mit einer kleineren Version, musst du das Ereignis manuell zuweisen. Im Private-Abschnitt muss dazu zusätzlich noch folgende Procedure deklariert werden:}

 procedure ApplicationEvents1Minimize(Sender: TObject);
chrisdrury
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

WinXP
D5 Prof
BeitragVerfasst: Mo 02.01.06 11:34 
Such mal hier im Forum nach Suche in der Entwickler-Ecke COOLTRAYICON.