全局热键的一些知识

来源:互联网 发布:软件企业质量体系认证 编辑:程序博客网 时间:2024/05/22 03:33

//全局热键的一些知识,程序快捷键也要用到原子。

TmpID:Integer;
begin
TmpID:=GlobalFindAtom(‘MyHotkey’);
if TmpID=0 then //查找全局原子.如果返回值不为0,则说明这个全局原子已经被注册;
id:=GlobalAddAtom(‘MyHotkey’)
else
ID:=TmpID;
TmpID:=GlobalFindAtom(‘MyHotkey2′);
if tmpid=0 then
id2:=globaladdatom(‘MyHotkey2′)
else
id2:=TmpID;

TmpID:=GlobalFindAtom(‘MyHotkey3′);
if tmpid=0 then
id3:=globaladdatom(‘MyHotkey3′)
else
id3:=TmpID;

TmpID:=GlobalFindAtom(‘MyHotkey4′);
if tmpid=0 then
id4:=globaladdatom(‘MyHotkey4′)
else
id4:=TmpID;
RegisterHotKey(Handle, id, 0, $70); //注册热键:
RegisterHotKey(Handle, id2, 0, $71); //注册热键:
RegisterHotKey(Handle, id3, 0, $72); //注册热键:
RegisterHotKey(Handle, id4, 0, $73); //注册热键:
untPublicUnit.h:=untPublicUnit.opencomm(1,2400);
EditRegID.Text:=untPublicUnit.MarkAddDate;

procedure TfrmRegister.WMHotKey(var Msg: TWMHotKey);
begin
if msg.HotKey=ID then //热键esc的消息.
untPublicUnit.voicehanshu(1,”);
if msg.HotKey=id2 then
untPublicUnit.voicehanshu(4,”);
if msg.HotKey=id3 then
untPublicUnit.voicehanshu(10,”);
if msg.HotKey=id4 then
untPublicUnit.voicehanshu(11,”);

end;

procedure TfrmRegister.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Handle,ID);//释放热键
GlobalDeleteAtom(ID); //删除全局原子ID
UnregisterHotKey(Handle,ID2);//释放热键
GlobalDeleteAtom(ID2); //删除全局原子ID
UnregisterHotKey(Handle,ID3);//释放热键
GlobalDeleteAtom(ID3); //删除全局原子ID
UnregisterHotKey(Handle,ID4);//释放热键
GlobalDeleteAtom(ID4); //删除全局原子ID
end;

原创粉丝点击