THotKey控件和RegisterHotKey控件的配合使用

字体大小: 中小 标准 ->行高大小: 标准
我想注册一系统热键,但不在设计时注册,要在运行时通过按“设置”按钮,将THotKey1

组件中用户选定的组合键(比如:Ctrl+A;或Alt+Ctrl+R)设为系统热键(用RegisterHotKey)。请问该怎么样做?急用。

下面是Kingron的回答:

unit Unit1;

{ Copyright Kingron 2002 }

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Grids, ValEdit, StdCtrls, ExtCtrls, ComCtrls;

type

TForm1 = class(TForm)

LabeledEdit1: TLabeledEdit;

HotKey1: THotKey;

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

Key,Shift:Word;

procedure wmhotkey(var Msg:TMessage);message WM_HOTKEY;

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

uses

Menus;

function ShiftStateToWord(Shift:TShiftState):Word;

begin

if ssShift in Shift then Result :=MOD_SHIFT;

if ssCtrl in Shift then Result :=Result or MOD_CONTROL;

if ssAlt in Shift then Result:=Result or MOD_ALT;

end;

procedure TForm1.Button1Click(Sender: TObject);

var

T:TShiftState;

begin

ShortCutToKey(HotKey1.HotKey,Key,T);

Shift :=ShiftStateToWord(T);

RegisterHotKey(Handle,GlobalAddAtom('MyHotKey') - $C000,Shift,Key);

end;

procedure TForm1.wmhotkey(var Msg: TMessage);

begin

if (Msg.LparamLo = Shift) AND (Msg.LParamHi = Key) then

ShowMessage('OK');

end;

end.

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/68035.html