使用全局热键显示隐藏窗体

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 
= class(TForm)
    
procedure FormCreate(Sender: TObject);
    
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  private
    
{ Private declarations }
  public
    
{ Public declarations }
  
end;

var
  Form1: TForm1;
  HotKeyId: Cardinal;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const
  MOD_ALT 
= 1;
  MOD_CONTROL 
= 2;
  VK_R 
= 82;
begin
  
//Ctrl + Alt + S
  try
    HotKeyId :
= GlobalAddAtom('MyHotKey'- $C000;
    RegisterHotKey(handle, HotKeyId, MOD_CONTROL 
+ MOD_ALT, VK_R);
  except

  
end;
end;

procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  
if Msg.HotKey = HotKeyId then
  
begin
    
if Application.ShowMainForm then
    
begin
      Application.ShowMainForm :
= False;
    
end else
    
begin
      Application.ShowMainForm :
= True;
    
end;
  
end;
  
if Self.Visible then Self.Visible := False
  
else Self.Visible := True;
end;

end.
原文地址:https://www.cnblogs.com/jxgxy/p/2121086.html