Thema: Delphi Tray-Icon

Einzelnen Beitrag anzeigen

Xenonz

Registriert seit: 21. Sep 2005
64 Beiträge
 
#9

Re: Tray-Icon

  Alt 25. Sep 2005, 18:49
Also:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ShellAPI, Menus;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Item11: TMenuItem; //in welchem Reiter sind diese Menüs?
    Item21: TMenuItem;
    Item31: TMenuItem;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    IconData: TNotifyIconData;
  public
    { Public-Deklarationen }
    procedure WndProc(var Msg: TMessage); override;
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND; //was ist der Unterschied
                                                                                    //zw. Public und Private?
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

////////////////////////////////////////////////////////////////////////////////
// auf Mausklicks reagieren, Fensterprozedur erweitern

procedure TForm1.WndProc(var Msg: TMessage);
var
  Point: TPoint; //was ist ein TPoint?
begin
  if Msg.Msg = WM_USER + 20 then // <hä?>
  begin
    case Msg.lParam of
      WM_RBUTTONDOWN:
        begin
          SetForegroundWindow(Handle);
          GetCursorPos(Point);
          PopUpMenu1.PopUp(Point.X, Point.Y);
        end;
      WM_LBUTTONDOWN:
        begin
          //ShowMessage('links runter');
        end;
      WM_LBUTTONDBLCLK:
        begin
          Form1.Show;
          // Icon nur anzeigen wenn Fenster minimiert
          Shell_NotifyIcon(NIM_DELETE, @IconData);
        end;
    end;
  end;
  inherited;
end;

////////////////////////////////////////////////////////////////////////////////
// beim Minimieren Fomr verstecken und Icon in die TNA

procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
begin
  if Message.CmdType and $FFF0 = SC_MINIMIZE then
  begin
    Hide;
    // Icon nur anzeigen wenn Fenster minimiert
    Shell_NotifyIcon(NIM_ADD, @IconData);
  end
  else
    inherited;
end;

////////////////////////////////////////////////////////////////////////////////
// Beim beenden Icon entfernen

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

////////////////////////////////////////////////////////////////////////////////
// Beim Erstellen des Formulares TNotifyIconData-Struktur initialisieren

procedure TForm1.FormCreate(Sender: TObject);
begin
  //Application.ShowMainForm := False; //Programm gar nicht erst anzeigen
  IconData.cbSize := SizeOf(IconData);
  IconData.Wnd := Handle;
  IconData.uID := 100;
  IconData.uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
  IconData.uCallBackMessage := WM_USER + 20;
  IconData.hIcon := Application.Icon.Handle;
  IconData.szTip := 'Dies ist ein TNA-Icon';
  //Shell_NotifyIcon(NIM_ADD, @IconData); // fügt das Icon ein end; //</hä?>
end;

end.
Das sind meine Probleme.
  Mit Zitat antworten Zitat