M
michael_zhu77
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;<br> <br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> id : integer;<br> procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br><br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br> const RSP_SIMPLE_SERVICE = 1;<br> function RegisterServiceProcess(dwProcessID,dwType : DWord) : DWord; stdcall; external 'KERNEL32.DLL';<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>procedure TForm1.WMHotKey(var Msg: TWMHotKey);<br>begin<br> if msg.HotKey = id then<br> ShowMessage('Ctrl+Alt+R键被按下!');<br> form1.Visible :=true;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Const<br>{ALT、CTRL和R键的虚拟键值}<br> MOD_ALT = 1;<br> MOD_CONTROL = 2;<br> VK_R = 82;<br>begin<br> {首先判断程序是否已经运行}<br> if GlobalFindAtom('MyHotkey') = 0 then<br> begin<br> {注册全局热键Ctrl + Alt + R}<br> id := GlobalAddAtom('MyHotkey');<br> RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R);<br> end<br> else<br> halt;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE);<br> form1.Hide;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> close;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> {退出时释放全局热键}<br> UnRegisterHotKey(handle,id);<br> GlobalDeleteAtom(id);<br>end;<br><br>end.<br><br>该代码是网上调试通过的,为啥在我的机器上走不通。<br>出现的错误提示:无法定位程序输入点RegisterServiceProcess于动态链接库KERNEL32.DLL上。<br>是不是有关系统问题?