Einzelnen Beitrag anzeigen

af99

Registriert seit: 22. Apr 2004
84 Beiträge
 
Delphi XE5 Ultimate
 
#1

Programm komplett in den Tray minimieren

  Alt 25. Jan 2013, 10:32
Delphi-Version: 5
Hallo Zusammen,

ich habe ein Programm geschrieben welches ich in den Tray mit einem Hotkey minimieren möchte. Das Programm hat 2 Formulare. Wenn ich nun das Hauptformular und das 2. Formular geöffnet habe und den Hotkey betätige dann minimiert sich lediglich das Hauptformular nicht jedoch das 2. Formular. Dieses bleibt weiterhin sichtbar.
Ich benutze folgende Komponenten auf dem Hauptformular
- Trayicon
- applicationevents

Delphiversion XE

Delphi-Quellcode:
unit Unit11;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, ExtCtrls, AppEvnts, Menus, StdCtrls, Buttons;

type
  TForm11 = class(TForm)
    TrayIcon1: TTrayIcon;
    ApplicationEvents1: TApplicationEvents;
    PopupMenu1: TPopupMenu;
    Anzeigen1: TMenuItem;
    ber1: TMenuItem;
    BitBtn1: TBitBtn;
    beenden1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure TrayIcon1DblClick(Sender: TObject);
    procedure ApplicationEvents1Minimize(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Anzeigen1Click(Sender: TObject);
    procedure beenden1Click(Sender: TObject);
    procedure ber1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    HotKeyID1: Integer;
    HotKeyID2: Integer;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
    procedure anwendung_sichtbar;
  public
    { Public-Deklarationen }
  end;

var
  Form11: TForm11;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm11.anwendung_sichtbar;
begin
  { Hide the tray icon and show the window,
  setting its state property to wsNormal. }

  TrayIcon1.Visible := False;
  Show();
  WindowState := wsNormal;
  Application.BringToFront();
end;

procedure TForm11.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = HotKeyID1 then
    anwendung_sichtbar;
  if Msg.HotKey = HotKeyID2 then
    ApplicationEvents1Minimize(Form11);
end;

procedure TForm11.Anzeigen1Click(Sender: TObject);
begin
  anwendung_sichtbar;
end;

procedure TForm11.ApplicationEvents1Minimize(Sender: TObject);
begin
  { Hide the window and set its state variable to wsMinimized. }
  Hide();
  //WindowState := wsMinimized;
  Application.Minimize;


  { Show the animated tray icon and also a hint balloon. }
  TrayIcon1.Visible := True;
  TrayIcon1.ShowBalloonHint;
end;

procedure TForm11.beenden1Click(Sender: TObject);
begin
  application.Terminate;
end;

procedure TForm11.ber1Click(Sender: TObject);
begin
  MessageDlg('Soennecken Server Dashboard' + CHR(10) + CHR(13) + 'Version 1.0', mtInformation, [mbOK], 0, mbOK);
end;

procedure TForm11.BitBtn1Click(Sender: TObject);
begin
  form1.show;
end;

procedure TForm11.FormCreate(Sender: TObject);
const
  VK_S = $53;
  VK_M = $4D;
begin
  HotKeyID1 := GlobalAddAtom(PChar(Application.Exename + '_Hotkey1'));
  RegisterHotKey(Handle, HotKeyID1, MOD_CONTROL + MOD_ALT, VK_S);

  HotKeyID2 := GlobalAddAtom(PChar(Application.Exename + '_Hotkey2'));
  RegisterHotKey(Handle, HotKeyID2, MOD_CONTROL + MOD_ALT, VK_M);


  TrayIcon1.Hint := 'SDash!';
  { Set up a hint balloon. }
  TrayIcon1.BalloonTitle := 'Bash reaktivieren';
  TrayIcon1.BalloonHint :=
    'Doppel click oder <Strg> + <Alt> + p = Anwendung sichtbar';
  TrayIcon1.BalloonFlags := bfInfo;
end;

procedure TForm11.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, HotKeyID1);
  GlobalDeleteAtom(HotKeyID1);

  UnRegisterHotKey(Handle, HotKeyID2);
  GlobalDeleteAtom(HotKeyID2);
end;

procedure TForm11.TrayIcon1DblClick(Sender: TObject);
begin
  anwendung_sichtbar;
end;

end.
Wie bekomme ich das hin???
Einer eine Idee???

Viele Grüße
Andreas

Geändert von af99 (25. Jan 2013 um 10:37 Uhr)
  Mit Zitat antworten Zitat