zoukankan      html  css  js  c++  java
  • Delphi 托盘/热键《LceMeaning》

    以下代码本人在Delphi XE2下编译通过

    ==================================================================

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Menus;
    
    type
      TForm1 = class(TForm)
        TrayIcon1: TTrayIcon;     //托盘控件
        pm1: TPopupMenu;          //托盘菜单
        N1: TMenuItem;
        N2: TMenuItem;
        procedure N2Click(Sender: TObject);
        procedure N1Click(Sender: TObject);
        procedure TrayIcon1DblClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        aatom : ATOM;
        procedure hotkey(var msg:TMessage);message WM_HOTKEY;
        //定义全局热键消息事件
    
        procedure WMsyscommand(var msg : Twmsyscommand);message wm_syscommand;
        //托盘消息定义
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    //全局执键执行过程
    procedure TForm1.hotkey(var msg: TMessage);
    begin
      if TWMHotKey(msg).HotKey=aatom then
      begin
        TrayIcon1DblClick(Self);
      end;
    end;
    
    //删除全局热键
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      UnregisterHotKey(Handle,aatom);
      GlobalDeleteAtom(aatom);
    end;
    
    //创建全局执键
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      if FindAtom('hotKey')=0 then
       begin
         aatom:=GlobalAddAtom('hotKey');
       end;
      RegisterHotKey(Handle,aatom,MOD_ALT,$43);   //ALT + C
    end;
    
    
    procedure TForm1.N1Click(Sender: TObject);
    begin
      Form1.Show;
      OpenIcon(Form1.Handle);    //激活窗口
    end;
    
    procedure TForm1.N2Click(Sender: TObject);
    begin
      TrayIcon1.Visible := False;     //删除托盘图标
      Application.Terminate;
    end;
    
    procedure TForm1.TrayIcon1DblClick(Sender: TObject);
    begin
      //双击托盘图标显示/隐藏窗口
      if WindowState = wsMinimized then
        begin
          Form1.Show;
          OpenIcon(Form1.Handle);
        end
      else
        begin
          Form1.Hide;
          WindowState := wsMinimized;
        end;
    end;
    
    //窗口缩小到托盘执行代码
    procedure Tform1.WMsyscommand(var msg : Twmsyscommand);
    begin
      if msg.CmdType = SC_MINIMIZE then
        Form1.Hide;
      inherited;
    end;
    
    end.

    ==================================================================

    代码结束.

  • 相关阅读:
    ASIHttpRequest框架使用说明-----post请求 以及监听网络
    tableView中当我们向右滑动不出现删除按钮(实现了代理方法)的原因
    自定义view 添加动画的时候一定要注意
    判断一个点是否在view上
    Razor视图引擎 语法学习(二)
    Razor视图引擎 语法学习(一)
    Razor语法大全
    文件
    win10下的使用
    gdb调试器的使用
  • 原文地址:https://www.cnblogs.com/LceMeaning/p/4285368.html
Copyright © 2011-2022 走看看