//看一下吧:
{procedure WMHOTKEY(var Message : TMessage); message WM_HOTKEY;
procedure WMDESTROY(var Message : TMessage); message WM_DESTROY;
function GetHotChar : Char;
procedure Loaded;override;}
function TButton1.GetHotChar: Char;
begin
Result := #0;
if (Pos('&', Caption) > 0) and
(Length(Copy(Caption, Pos('&', Caption) + 1, 1))>0) then
Result := Copy(Caption, Pos('&', Caption) + 1, 1)[1];
end;
procedure TButton1.Loaded;
begin
inherited;
if not (csDesigning in ComponentState) and (GetHotChar <> #0) then
RegisterHotKey(Handle, IDHOT_SNAPWINDOW, MOD_CONTROL, Ord(GetHotChar));
end;
procedure TButton1.WMDESTROY(var Message: TMessage);
begin
if not (csDesigning in ComponentState) then
UnregisterHotKey(Handle, IDHOT_SNAPWINDOW);
inherited;
end;
procedure TButton1.WMHOTKEY(var Message: TMessage);
function GetPWnd : THandle;
begin
Result := Handle;
repeat
Result := Windows.GetParent(Result);
until not IsWindow(Windows.GetParent(Result));
end;
begin
if (GetActiveWindow = GetPWnd) and (Message.WParam = IDHOT_SNAPWINDOW) and
(Message.LParamLo = MOD_CONTROL) and (Message.LParamHi = ord(GetHotChar))
then Click;
end;