在消息处理中处理热键问题?112分(100分)

  • 主题发起人 主题发起人 enteraj
  • 开始时间 开始时间
E

enteraj

Unregistered / Unconfirmed
GUEST, unregistred user!
用函数GlobalAddAtom怎么定义热键问题?<br>如:<br>var ni:integer;<br>ni:=GlobalAddAtom(pchar(F3));<br>RegisterHotkey(Handle,ni,MOD_CONTROL or MOD_Alt, $41);<br>这样我在消息处理时怎么无法得F3热键。
 
等了这么久怎么都没有人知道呢?各位同仁
 
我看你可能是少了消息激发.<br>procedure OnHotKey(var Message:TWMHotKey);Message WM_HotKey;<br><br>procedure TForm2.OnHotKey(var Message: TWMHotKey);<br>begin<br>&nbsp; if Message.HotKey=ni then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('OK');<br>&nbsp; end;<br>end;<br>在Create中注册热键.ni为全局变量<br>&nbsp; ni:=GlobalAddAtom(pchar(F3));<br>&nbsp; RegisterHotKey(Handle,ni,MOD_ALT+MOD_CONTROL+MOD_SHIFT,VK_F9); //定义热键<br>在Close中注销热键.<br>&nbsp; UnregisterHotKey(handle,ni);
 
我看你可能是少了消息激发.<br>procedure OnHotKey(var Message:TWMHotKey);Message WM_HotKey;<br><br>procedure TForm2.OnHotKey(var Message: TWMHotKey);<br>begin<br>&nbsp; if Message.HotKey=ni then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('OK');<br>&nbsp; end;<br>end;<br>在Create中注册热键.ni为全局变量<br>&nbsp; ni:=GlobalAddAtom(pchar(F3));<br>&nbsp; RegisterHotKey(Handle,ni,MOD_ALT+MOD_CONTROL+MOD_SHIFT,VK_F9); //定义热键<br>在Close中注销热键.<br>&nbsp; UnregisterHotKey(handle,ni);
 
id:=GlobalAddAtom('MyHotkey');<br>RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_F3);
 
HotkeyId:=GlobalAddAtom(pchar('F3')); //减去$C000是为了保证取值范围的限制<br>&nbsp; RegisterHotkey(Handle,HotkeyId,MOD_CONTROL or MOD_Alt, $41);//敏感键为ctrl+Alt+A<br>end;<br>procedure TForm1.WMHotkeyHandle(var Msg:TMessage); //响应敏感键按键消息<br>begin<br>&nbsp; &nbsp; if (Msg.LParamHi=$41) and (msg.lparamLo=MOD_CONTROL or mod_Alt) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Msg.Result:=1; //该消息已经处理<br>&nbsp; &nbsp; &nbsp; form2.show;<br>&nbsp; &nbsp; end;<br>上面这样写可以按ctrl+alt+a键可以使form2弹出,但是我的意思是通过按F3键也实现。上面的写法怎么不行?
 
可惜,在WIN2000中不能屏蔽CTRL+ALT+DEL
 
衰,上面居然贴了两次.<br>你看你自己的定义<br>&nbsp; RegisterHotKey(Handle,ni,MOD_ALT or MOD_CONTROL,VK_F3); //这儿你定义成同时按CTRL和ALT,当然效果就是CTRL+ALT+F3,<br>如果你只想要F3,<br>&nbsp; RegisterHotKey(Handle,ni,0,VK_F3); //这样就行了.<br>不知咋搞的,好慢,是我这儿的问题还是大富翁的问题?
 
to zhangkan:<br>&nbsp;在你贴的过程中我已经试成功了哈哈谢谢。回影子:<br>HotkeyId:=GlobalAddAtom(pchar('F3')); RegisterHotkey(Handle,HotkeyId,MOD_CONTROL or MOD_Alt, VK_DEL);//敏感键为ctrl+Alt+del<br>end;<br>procedure TForm1.WMHotkeyHandle(var Msg:TMessage); //响应敏感键按键消息<br>begin<br>&nbsp; &nbsp; if (Msg.LParamHi=VK_DEL) and (msg.lparamLo=MOD_CONTROL or mod_Alt) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Msg.Result:=1; //该消息已经处理<br>&nbsp; &nbsp; &nbsp; //不做事情这样不就屏蔽了alt+ctrl+del键吗?<br>&nbsp; &nbsp; end;<br>
 
在WIN2000中不能屏蔽CTRL+ALT+DEL。<br>VK_DEL应为:VK_DELETE
 
我认为程序更应该这样写:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, Buttons;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; BitBtn1: TBitBtn;<br>&nbsp; &nbsp; procedure BitBtn1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; procedure GetHotkey(var Msg : TWMHOTKEY);message WM_HOTKEY;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.GetHotKey(var Msg : TWMHOTKEY);<br>begin<br>&nbsp; if Msg.HotKey = $DDDDDD then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('press');<br>&nbsp; &nbsp; Msg.Result := 1;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>begin<br>&nbsp; RegisterHotkey(handle,$DDDDDD,MOD_CONTROL or MOD_Alt, VK_F3);<br>end;<br><br>end.
 
回影子:<br>&nbsp; 对了刚才VK_DEL应改为VK_DELETE就可以。<br>你可以试试这种方法:<br>  当你不需要让用户按Alt+Enter、Ctrl+Alt+Del、Ctrl+Esc等功能键的时候加入以下代码:<br>Var<br>temp:integer;<br>begin<br>SystemParametersInfo(Spi_screensaverrunning,1,@temp,0);<br>end;<br>  当你要恢复功能键时用以下代码:<br>Var<br>Temp:integer;<br>begin<br>SystemParametersInfo(spi_screensaverrunning,0,@temp,0);<br>end;
 
不行的。<br>你现在用的系统是WIN98吧。<br>我实在找不到更好的办法了。<br>
 
上面的$DDDDDD是随意的。<br>范围看RegisterHotKey函数。
 
没招了,想出办法大家一起共享
 
后退
顶部