码迷,mamicode.com
首页 > 其他好文 > 详细

Delphi 注册快捷键

时间:2014-05-29 16:52:29      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:des   c   class   blog   code   a   

ShortCutToText , TextToShortCut 需 uses Menus;

type
TForm1 = class(TForm)
HotKey1: THotKey;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure WMHotKey(var Msg:TMessage);message WM_HOTKEY;
public
{ Public declarations }
end;
 
var
Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
var
Key, Shift: Word;
Id: Integer;
 
procedure ShortCutToKey(ShortCut: TShortCut; var Key: Word; var Shift: TShiftState);
begin
Key := ShortCut and not (scShift + scCtrl + scAlt);
Shift := [];
if ShortCut and scShift <> 0 then Include(Shift, ssShift);
if ShortCut and scCtrl <> 0 then Include(Shift, ssCtrl);
if ShortCut and scAlt <> 0 then Include(Shift, ssAlt);
end;
 
function ShiftStateToWord(TShift: TShiftState): Word;
begin
Result := 0;
if ssShift in TShift then Result := MOD_SHIFT;
if ssCtrl in TShift then Result := Result or MOD_CONTROL;
if ssAlt in TShift then Result:= Result or MOD_ALT;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
T: TShiftState;
begin
Id := GlobalAddAtom(‘MyHotKey‘) - $C000;
ShortCutToKey(HotKey1.HotKey, Key, T);
Shift := ShiftStateToWord(T);
RegisterHotKey(Handle, Id, Shift, Key);
end;
 
procedure TForm1.WMHotKey(var Msg: TMessage);
begin
if (Msg.LparamLo = Shift) AND (Msg.LParamHi = Key) then
ShowMessage(‘This is HotKey‘);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(Handle, Id);
GlobalDeleteAtom(Id);
end;
 
end.

 

Delphi 注册快捷键,布布扣,bubuko.com

Delphi 注册快捷键

标签:des   c   class   blog   code   a   

原文地址:http://www.cnblogs.com/lifelog/p/3758581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!