zoukankan      html  css  js  c++  java
  • Register HotKey

    Register HotKey

    代码
    {*******************************************************}
    { }
    { Module Name: unitHotKey.pas }
    { Creation Date 2010-12-30 }
    { }
    {*******************************************************}
    unit unitHotKey;

    interface

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

    type
    TForm1
    = class(TForm)
    btnAtom: TButton;
    btnGAtom: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnAtomClick(Sender: TObject);
    procedure btnGAtomClick(Sender: TObject);
    private
    { Private declarations }
    FKeyHandle:
    array [1..4] of ATOM;
    public
    { Public declarations }
    procedure WMHotKeyHandle(var msg: Tmessage); message WM_HOTKEY;
    //procedure WMHotKeyHandle(var msg: TWMHotKey); message WM_HOTKEY;
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.FormCreate(Sender: TObject);
    var
    i: Integer;
    begin
    for i := 1 to 4 do
    FKeyHandle[i] :
    = GlobalAddAtom(PChar('MyTestHotKey' + IntToStr(i)));
    RegisterHotKey(Handle, FKeyHandle[
    1], 0, VK_F4);
    RegisterHotKey(Handle, FKeyHandle[
    2], MOD_ALT, VK_F4);
    RegisterHotKey(Handle, FKeyHandle[
    3], MOD_ALT + MOD_CONTROL, VK_F4);
    RegisterHotKey(Handle, FKeyHandle[
    4], MOD_WIN, VK_F4);
    end;

    procedure TForm1.FormDestroy(Sender: TObject);
    var
    i: Integer;
    begin
    for i := 1 to 4 do
    begin
    UnregisterHotKey(Handle,FKeyHandle[i]);
    GlobalDeleteAtom(FKeyHandle[i]);
    end;
    end;

    procedure TForm1.btnAtomClick(Sender: TObject);
    var
    id1: ATOM;
    pc: Array [
    0..255] of Char;
    begin
    id1 :
    = AddAtom('测试文本');
    GetAtomName(id1,pc,
    256);
    ShowMessage(pc);
    DeleteAtom(id1);
    end;

    procedure TForm1.btnGAtomClick(Sender: TObject);
    var
    id1: ATOM;
    pc: Array [
    0..255] of Char;
    begin
    id1 :
    = GlobalAddAtom('测试GlobalAddATom');
    GlobalGetAtomName(id1,pc,
    256);
    ShowMessage(pc);
    GlobalDeleteAtom(id1);
    end;

    procedure TForm1.WMHotKeyHandle(var msg: Tmessage);
    begin
    if msg.WParam = FKeyHandle[1] then ShowMessage('F4');
    if msg.WParam = FKeyHandle[2] then ShowMessage('Alt+F4');
    if msg.WParam = FKeyHandle[3] then ShowMessage('Alt+Ctrl+F4');
    if msg.WParam = FKeyHandle[4] then ShowMessage('Win+F4');
    end;

    end.
    VC:

    代码

    afx_msg LRESULT OnHotKey(WPARAM wParam, LPARAM lParam);
    ON_MESSAGE(WM_HOTKEY, OnHotKey)


    RegisterHotKey(GetSafeHwnd(),m_HKID1,MOD_ALT
    | MOD_CONTROL,VK_F3);
    RegisterHotKey(GetSafeHwnd(),m_HKID2,MOD_ALT ,VK_F4);


    UnregisterHotKey(GetSafeHwnd(),m_HKID1);

    UnregisterHotKey(GetSafeHwnd(),m_HKID2);

    LRESULT CSignleDoc_View::OnHotKey(WPARAM wParam, LPARAM lParam)
    {
    SetForegroundWindow();
    if (wParam==m_HKID1)
    {
    MessageBox(
    "Hello ALT+CTRL+F3 !");
    }
    else if (wParam==m_HKID2)
    {
    MessageBox(
    "Hello ALT+CTRL+F4 !");
    }
    return 1;
    }

  • 相关阅读:
    pxc5.7配置安装
    在SQL中 给字符串补0方法
    python中字符串连接的四种方式
    python中math模块常用的方法整理
    python 字符串比较
    sql去重;同一条数据出现多条取一条的sql语句
    给一行添加数据库不存在的自然数顺序编号
    jvisualvm下载
    sql截取字符串后面四位
    idea破解更新
  • 原文地址:https://www.cnblogs.com/Jekhn/p/1921348.html
Copyright © 2011-2022 走看看