Einzelnen Beitrag anzeigen

Benutzerbild von Evian
Evian

Registriert seit: 10. Apr 2003
Ort: Berlin
485 Beiträge
 
Delphi 6 Professional
 
#4

Re: Systray Icon verschwindet

  Alt 15. Apr 2006, 12:55
also ich nutze eigendlich standartcode um das Icon zu erzäugen.:


Delphi-Quellcode:
 program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas{Form1},
  Unit2 in 'Unit2.pas{Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.Title := 'ADAM';
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Unit1.Form1.Starter;
  Application.ShowMainForm := false;
  Application.Run;
end.
Delphi-Quellcode:
unit Unit1;

interface

uses
  ...

const WM_TASKBAREVENT = WM_USER + 1;

type
  TForm1 = class(TForm)
    ...
    procedure TaskBarAddIcon(add:boolean);
    procedure TaskBarRemoveIcon;
    procedure FormShow(Sender: TObject);
    ...
  private
    procedure WMTASKBAREVENT(var message: TMessage);
    message WM_TASKBAREVENT;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;


implementation

uses Unit2;

{$R *.dfm}

procedure Tform1.Starter;
BEGIN
  ...
  TaskBarAddIcon(true);
  ...
END;

//-------- Button im Contextmenü des Formulars um
// die Form entweder fsNormal, oder fsStayOnTop festzulegen -----------------

procedure TForm1.On1Click(Sender: TObject);
begin
  if form1.On1.Checked then
  BEGIN
    form1.FormStyle := fsNormal;
    form1.On1.Checked := false;
  END else
  BEGIN
    form1.FormStyle := fsStayOnTop;
    form1.On1.Checked := true;
  END;
end;

procedure TForm1.Beenden1Click(Sender: TObject);
begin
  TaskBarRemoveIcon;
  Application.Terminate;
end;


//----------Für Taskicon----------

procedure TForm1.WMTASKBAREVENT(var message: TMessage);
VAR
MousePos: TPOINT;
begin
  case message.LParamLo of
  WM_LBUTTONDOWN : BEGIN
  end;
  WM_RBUTTONDOWN : begin
  IconPop.Popup(MousePos.x, MousePos.y);
  end;
  WM_LBUTTONDBLCLK : begin
  
  end;
  end;
end;

procedure Tform1.TaskBarAddIcon(add:boolean);
var
tnid: TNOTIFYICONDATA;
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,'ADAM');
  if add then
  Shell_NotifyIcon(NIM_ADD, @tnid) else
  Shell_NotifyIcon(NIM_MODIFY, @tnid)
end;

procedure TForm1.TaskBarRemoveIcon;
var
tnid: TNOTIFYICONDATA ;
begin
  tnid.cbSize := sizeof(TNOTIFYICONDATA);
  tnid.Wnd := Form1.handle;
  tnid.uID := 1;
  Shell_NotifyIcon(NIM_DELETE, @tnid);
end;

procedure TForm1.FormShow(Sender: TObject);
var
  Owner: HWnd;
begin
  Owner := GetWindow(Form1.Handle,GW_OWNER);
  If Owner<>0 Then
  ShowWindow(Owner,SW_HIDE);
end;

//-------- Button im Contextmenü des TrayIcons -----------------
procedure TForm1.OnlineCheck1Click(Sender: TObject);
begin
  Application.ShowMainForm := true;
  Form1.Show;
end;

...
Wenn man das Programm startet ist die Mainform noch nicht sichtbar, weil "Application.ShowMainForm := false".
Wärend der Laufzeit wechselt öfter das Tray-Icon.. indem ich pplication.Icon ein neues Icon zuweise und dann TaskBarAddIcon(false); aufrufe. Keine Ahung, aber vielleicht liegt es daran?
-> www.Phillsoft.de

Ich bin nun Mathematiker, aber meine Freundin bleibt trotzdem unberechenbar!
  Mit Zitat antworten Zitat