考慮窗口句柄的例子中不提供VCL的消息,爲此,我們使用WM_HOTKEY。此消息是由註冊窗口在Windows熱鍵,允許在程序響應它,即使沒有輸入焦點發送:
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
// Declare a event handler
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
// Registering a hotkey Ctrl+Alt+F5
RegisterHotKey(Handle, 0, MOD_CONTROL or MOD_ALT, VK_F5);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// Unregisters a hotkey
UnRegisterHotKey(Handle, 0);
end;
procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
// This procedure is called when a window message WM_HOTKEY
inherited; // We give the form to process the message,
// if she already has its handler
Beep; // We perform additional actions
end;
通常情況下,是在做你希望的東西沒有問題。它只是自動工作。由於您正在使用動作管理器,因此您應該使用'TAction'的'ShortCut'屬性,而不是'TMenuItem'。 – 2012-07-24 06:06:56
是的,只需分配ShortCut屬性即可。 – 2012-07-24 07:42:34
將菜單項視爲「呈現靜態定義的動作的一種動態構建方式」,因此,我設置了我的操作,而不是我的菜單項屬性。菜單項屬性來自動作列表或動作管理器,並向外傳播。 – 2012-07-24 13:32:04