Autor Beitrag
reg107
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 36



BeitragVerfasst: Do 24.02.05 20:40 
Hallo,
ich habe im Programm einen systemweiten Hotkey. Der Funktioniert, wenn das Fenster nicht in den SystemTray minimiert wurde. In den Systemtray minimieren funktioniert ohne Probleme. Beides zusammen aber nicht. Sobald ich das Fenster in den SystemTray minimiere ist der Hotkey wie weg. Er funktioniert auch nicht mehr, wenn ich das Fenster wieder herstelle.
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:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,
  ShellApi, // systray
  AppEvnts; // systray

// hotkey
type
 TWMHotkey = RECORD
  Msg: Cardinal;
  idHotKey: Word;
  Modifiers: Integer;
  VirtKey: Integer;
 end;

const
  IC_CLICK = WM_APP + 201// systray
  ID = $FF// hotkey

type
  TForm1 = class(TForm)
    ButtonSystray: TButton;
    ButtonHotkeysSetzen: TButton;
    procedure ButtonSystrayClick(Sender: TObject);
    procedure ButtonHotkeysSetzenClick(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure Systray(var sMsg: TMessage); message IC_CLICK; // systray
    procedure WMHotKey(var Msg: TWMHotKey); Message WM_HOTKEY; // hotkey
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  NIM : TNotifyIconData; // systray

implementation

{$R *.dfm}

// - Systray Kontrolle 1 -
procedure TForm1.Systray(var sMsg: TMessage);
begin
  // Vorgang: Klick auf das Icon neben der Uhr und Anzeige der Anwendung
  inherited;
  if (sMsg.LParam = WM_LBUTTONDOWN) then begin
    Show;
    Shell_NotifyIcon(NIM_DELETE, @NIM);
    Application.Restore; //zeigt die Anwendung wieder an
    Form1.FormStyle:=fsNormal;
  end;
end;

// - Systray aktivieren 2 -
procedure TForm1.ButtonSystrayClick(Sender: TObject);
begin
  //Vorgang: Minimieren der Anwendung, Entfernung des Taskleisteneintrags
  //und Hinzufügen des Programmicons neben der Uhr
  Form1.FormStyle:=fsStayOnTop;
  Hide;
  with NIM do begin
    cbSize := SizeOf (nIM);
    Wnd := Handle;
    uID := 0;
    uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
    uCallbackMessage := IC_CLICK;
    hIcon := Application.Icon.Handle;
    szTip := 'flx tools';
  end;
  Shell_NotifyIcon(NIM_ADD, @NIM);
end;

procedure TForm1.WMHotKey(Var Msg: TWMHotkey);
begin
 case Msg.IdHotKey of
  ID: Caption := 'alles klar';
  { Hier könnten noch weiter Hotkeys abgefragt werden z.B. mit
    ID+1: Caption := ... ; }

 end;
 inherited;
end;

procedure TForm1.ButtonHotkeysSetzenClick(Sender: TObject);
begin
  if NOT RegisterHotKey(Form1.Handle, ID, MOD_CONTROL + MOD_Alt, Ord('F')) then
    ShowMessage('Hotkey konnte nicht registriert werden');
end;

end.


Funktioniert sowas überhaupt? Wenn ja, wie?

Gruß,
reg107
Ronny
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 06.03.06 22:45 
Hallo zusammen,

ich habe genau das gleiche Probelm wie schon von "reg107" oben geschieldert
wurde.
Gibt es da mitlerweile eine Lösung dazu?


Vielen Dank schon mal
Gruß Ronny