Entwickler-Ecke

Windows API - Tray Icon - Text dynamisch


fuba - Do 15.02.07 12:10
Titel: Tray Icon - Text dynamisch
Hi leute,

Ich habe nen kleines prog gemacht, das alle paar Minuten was bestimmtes machen soll, wenn es aktiv ist.

Dieses prog ist immer minimiert im Tray und würde gerne den Tray text @ laufzeit ändern.

Sollte ca. so sein (im Tray Text):
blabla programm - Status: Aktiv
blabla programm - Status: Inaktiv

Habe für tray icon einen fertigen code genommen:


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:
Procedure TForm1.ApplicationMinimize(Sender: TObject);
var
  NotifyIconData: TNotifyIconData;
  Owner : HWnd;
begin
  Fillchar(NotifyIconData,Sizeof(NotifyIconData),0);
  NotifyIconData.cbSize := Sizeof(NotifyIconData);
  NotifyIconData.Wnd    := Handle;
  NotifyIconData.uFlags := NIF_MESSAGE
    or NIF_ICON
    or NIF_TIP;
  NotifyIconData.uCallbackMessage := WM_TASKABAREVENT;
  NotifyIconData.hIcon := Application.Icon.Handle;
  NotifyIconData.szTip := 'blabla programm - Status:';
  Shell_NotifyIcon(NIM_ADD, @NotifyIconData);


  Owner:=GetWindow(Handle,GW_OWNER);
  ShowWindow(Owner,SW_HIDE);
end;

Procedure TForm1.ApplicationMaximize(Sender: TObject);
var
  NotifyIconData: TNotifyIconData;
begin
  FillChar(NotifyIconData,Sizeof(NotifyIconData),0);
  NotifyIconData.cbSize := Sizeof(NotifyIconData);
  NotifyIconData.Wnd    := Self.Handle;
  NotifyIconData.uFlags := NIF_MESSAGE
    or NIF_ICON
    or NIF_TIP;
  NotifyIconData.uCallbackMessage := WM_TASKABAREVENT;
  NotifyIconData.hIcon := Application.Icon.Handle;
  NotifyIconData.szTip := 'Punkt';
  Shell_NotifyIcon(NIM_DELETE, @NotifyIconData);
end;


das ist der code indem der Tray Text steht:

Delphi-Quelltext
1:
NotifyIconData.szTip := 'blabla programm - Status:';                    


wie kann ich das per laufzeit ändern?

danke für hilfe!


Moderiert von user profile iconTino: Topic aus VCL (Visual Component Library) verschoben am Mo 30.04.2007 um 20:30


jaenicke - Do 15.02.07 12:41

Es gibt nicht nur NIM_ADD und NIM_DELETE... ;-)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shell_notifyicon.asp


Delete - Mo 30.04.07 19:43

Wie siehts denn aber aus, wenn ich Zahlen dort einfügen möchte?

Also in meinem Fall ist es eine Zeitanzeige...

danke


Tino - Mo 30.04.07 20:28
Titel: Re: Tray Icon - Text dynamisch
user profile iconfuba hat folgendes geschrieben:
das ist der code indem der Tray Text steht:

Delphi-Quelltext
1:
NotifyIconData.szTip := 'blabla programm - Status:';                    


wie kann ich das per laufzeit ändern?


...Icons in die TNA hinzufügen, ändern und löschen? [http://www.delphi-library.de/topic_Icons+in+die+TNA+hinzufuegen+aendern+und+loeschen_8294.html]


Delete - Di 01.05.07 14:31

ja, ... ne.

das mein ich nich.
das weiss ich ja bereits.

Das Problem liegt darin, dass ich eine unbestimmte Zahlenfolge eingeben lassen möchte.
also eher etwas im Sinne von:


[highlight]IconData.szTip := 'verbleibende Restzeit: ' + TimeToStr(remTime);
Shell_NotifyIcon(NIM_Modify, @IconData);[/highlight]
(Auszug)



dann kommt eine Fehlermeldung von wegen inkompatible Typen

??

danke



EDIT//
ach mensch, mädels, ihr macht mich fertig...
habs jetze selber raus bekommen.

StrCopy(IconData.szTip, pchar(TimeToStr(remTime)))

trotzdem danke

tschausen


jaenicke - Mi 02.05.07 12:44

Oder:

Delphi-Quelltext
1:
IconData.szTip := PChar('verbleibende Restzeit: ' + #13#10 + TimeToStr(remTime));                    

Letztendlich kommt es auf das gleiche raus.