win2000下定义热键(300分)

小菜

Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码在win98下正常,在win2000下定义F1至F11都正常,但失败.<br>在Delphi里运行,按下F12后弹出CPU窗口,编译成EXE文件运行时,按F12无反应.<br>请大家帮忙看看<br><br>var<br>&nbsp; F11,F12:THandle;<br><br>procedure TForm1.WMHotkeyHandle(var Msg: TMessage);<br>begin<br>showmessage(intostr(msg.LParamhi));<br>Msg.Result := 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; F11:= GlobalAddAtom(Pchar('F11')) - $C000;<br>&nbsp; F12:= GlobalAddAtom(Pchar('F12')) - $C000;<br>&nbsp; RegisterHotkey(Handle, F11, 0, 122);<br>&nbsp; RegisterHotkey(Handle, F12, 0, 123);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; UnRegisterhotkey(Handle, F11);<br>&nbsp; UnRegisterhotkey(Handle, F12);<br>&nbsp; DeleteAtom(F11);<br>&nbsp; DeleteAtom(F12);<br>end;<br><br>
 
打漏了"F12",应该是:在win2000下定义F1至F11都正常,但F12失败。
 
那是因为注册热键失败了:<br>&nbsp; if not RegisterHotkey(Handle, F12, 0, 123) then<br>&nbsp; &nbsp; ShowMessage('Failed');<br><br>在2000下好象F12被占用了吧? 我试了一下,就是F12不能注册成功<br>
 
你要判断每个RegisterHotkey()的返回是否成功
 
那是因为F12已经给人先注册了,比如delphi<br>你可以在不运行delphi的情况下,直接运行你的程序看看
 
{给你实验了一下,没有发现问题呀。环境Delphi5在98下编译,Windows 2000 Adv Server的客户端连接测试}<br>var HotkeyId: THandle;<br><br>procedure TForm1.WMHotkeyHandle(var Msg: TMessage);<br>begin<br>&nbsp; if Msg.LParamHi = VK_F12 then<br>&nbsp; begin<br>&nbsp; &nbsp; Msg.Result := 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//该消息已经处理<br>&nbsp; &nbsp; Caption:='1';<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; HotkeyId := GlobalAddAtom(Pchar('UserDefineHotKey')) - $C000; //减去$C000是为了保证取值范围的限制<br>&nbsp; RegisterHotkey(Handle, Hotkeyid, 0, VK_F12);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; UnRegisterhotkey(Handle, HotkeyId);<br><br>end;<br><br>end.<br>
 
谢谢大家!<br>to xianjun、陈锡震:<br>&nbsp; &nbsp;我试过的,RegisterHotKey()的返回值并无异常,但编译后按下F12毫无反应,<br>to Pipi:<br>&nbsp; &nbsp;编译后运行对F12毫无反应,在Delphi下调试按下F12后弹出CPU窗口,可惜我搞不清那些汇编 :(<br>to yzhshi:<br>&nbsp; &nbsp;win98下编译能成功。请试在Win2000下编译。开始我以为是自己的系统有问题,可换了一台机器还是不行。<br><br>&nbsp; 是不是Win2000下的F12有点小花样啊?请大家继续帮忙看看,小菜多谢了!<br>
 
在Delphi下当然不能用F12了,因为在运行期F12是显示CPU窗口, 设计期F12是切换窗体与代码<br>你那边RegisterHotkey返回了True吗? 我这里都是False,不管是在Delphi下还是什么<br>所以我想F12是被系统占用了<br>因为用其他F1-F11, F13等等都可以。
 
是我错了,win2000下用RegisterHotkey注册VK_F12总是返回False,<br>问题是Win2000对这F12动了什么手脚呢? 怎样才在自己的程序里能定义F12?<br>我想:<br>&nbsp; 1. &nbsp;winn98下能成功,我想这应不是Delphi的问题,而是Win2000的问题<br>&nbsp; 2. &nbsp;Win2000下delphi能用F12,自己的程序里也应能实现。<br>请各位继续帮忙,多提意见。
 
是的,在WIN2000下面对系统进行操作都涉及到权限提升的问题!!<br>你自己看看资料吧,应该不难解决·!
 
Windows NT4 and Windows 2000/XP: <br>The F12 key is reserved for use by the debugger at all times, <br>so it should not be registered as a hot key.<br>&nbsp;Even when you are not debugging an application,<br>&nbsp;F12 is reserved in case a kernel-mode debugger or a just-in-time debugger<br>&nbsp;is resident.<br><br>!!!!<br>给我分吧,谢谢。<br>:)<br><br>
 
发分了,谢谢大家!<br>谢谢gb2312!还有点小问题请帮到底:<br>怎样才能把保留给debugger的F12重新释放;<br>还有你这一段资料是哪来的 :)
 
目前为止,我还没有找出来怎么在2k/xp下,怎么释放F12<br><br>原文在msdn里面。<br><br>欢迎大家进行讨论~~<br><br>我也对这个有一点兴趣。<br><br>:)<br>
 
顶部