第一次用 API。求教! ( 积分: 100 )

  • 主题发起人 主题发起人 michael_zhu77
  • 开始时间 开始时间
M

michael_zhu77

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;<br> &nbsp;<br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;id : integer;<br> &nbsp; &nbsp;procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br><br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br> &nbsp;const RSP_SIMPLE_SERVICE = 1;<br> &nbsp;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> &nbsp;if msg.HotKey = id then<br> &nbsp; &nbsp;ShowMessage('Ctrl+Alt+R键被按下!');<br> &nbsp;form1.Visible :=true;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Const<br>{ALT、CTRL和R键的虚拟键值}<br> &nbsp;MOD_ALT = 1;<br> &nbsp;MOD_CONTROL = 2;<br> &nbsp;VK_R = 82;<br>begin<br> &nbsp;{首先判断程序是否已经运行}<br> &nbsp;if GlobalFindAtom('MyHotkey') = 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;{注册全局热键Ctrl + Alt + R}<br> &nbsp; &nbsp; &nbsp;id := GlobalAddAtom('MyHotkey');<br> &nbsp; &nbsp; &nbsp;RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R);<br> &nbsp; &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;halt;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> &nbsp;RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE);<br> &nbsp;form1.Hide;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> &nbsp;close;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp;{退出时释放全局热键}<br> &nbsp;UnRegisterHotKey(handle,id);<br> &nbsp;GlobalDeleteAtom(id);<br>end;<br><br>end.<br><br>该代码是网上调试通过的,为啥在我的机器上走不通。<br>出现的错误提示:无法定位程序输入点RegisterServiceProcess于动态链接库KERNEL32.DLL上。<br>是不是有关系统问题?
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;<br> &nbsp;<br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;id : integer;<br> &nbsp; &nbsp;procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br><br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br> &nbsp;const RSP_SIMPLE_SERVICE = 1;<br> &nbsp;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> &nbsp;if msg.HotKey = id then<br> &nbsp; &nbsp;ShowMessage('Ctrl+Alt+R键被按下!');<br> &nbsp;form1.Visible :=true;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Const<br>{ALT、CTRL和R键的虚拟键值}<br> &nbsp;MOD_ALT = 1;<br> &nbsp;MOD_CONTROL = 2;<br> &nbsp;VK_R = 82;<br>begin<br> &nbsp;{首先判断程序是否已经运行}<br> &nbsp;if GlobalFindAtom('MyHotkey') = 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;{注册全局热键Ctrl + Alt + R}<br> &nbsp; &nbsp; &nbsp;id := GlobalAddAtom('MyHotkey');<br> &nbsp; &nbsp; &nbsp;RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R);<br> &nbsp; &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;halt;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> &nbsp;RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE);<br> &nbsp;form1.Hide;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> &nbsp;close;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp;{退出时释放全局热键}<br> &nbsp;UnRegisterHotKey(handle,id);<br> &nbsp;GlobalDeleteAtom(id);<br>end;<br><br>end.<br><br>该代码是网上调试通过的,为啥在我的机器上走不通。<br>出现的错误提示:无法定位程序输入点RegisterServiceProcess于动态链接库KERNEL32.DLL上。<br>是不是有关系统问题?
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=102116<br>标题是: how to use RegisterServiceProcess ,get me a sample, (50分)<br>分类:GIS <br><br>const<br> &nbsp;RSP_SIMPLE_SERVICE &nbsp; &nbsp; = $00000001;<br> &nbsp;RSP_UNREGISTER_SERVICE = $00000000;<br>// Parameter dwProcessId can be 0, same effect as GetCurrentProcessId<br>// Return Values: True(1) means success<br>function RegisterServiceProcess(dwProcessId, dwServiceType: DWord): Bool; stdcall;<br>// Place in &quot;implementation&quot; session<br>function RegisterServiceProcess; external 'Kernel32.dll' Name 'RegisterServiceProcess';<br>// Example: <br>// &nbsp; RegisterServiceProcess(0, RSP_SIMPLE_SERVICE);<br>// &nbsp; RegisterServiceProcess(0, RSP_UNREGISTER_SERVICE
 
没懂。<br>能不能讲的清楚些,谢谢!
 
看看行不行<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;<br> &nbsp;<br>const<br> &nbsp;RSP_SIMPLE_SERVICE &nbsp; &nbsp; = $00000001;<br> &nbsp;RSP_UNREGISTER_SERVICE = $00000000;<br>type<br><br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;id : integer;<br> &nbsp; &nbsp;procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br><br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br> &nbsp; &nbsp;function RegisterServiceProcess(dwProcessId, dwServiceType: DWord): Bool; stdcall;<br>implementation<br> &nbsp; &nbsp; &nbsp;function RegisterServiceProcess; external Kernel32 name 'RegisterServiceProcess';<br>{$R *.dfm}<br><br>{ TForm1 }<br><br>procedure TForm1.WMHotKey(var Msg: TWMHotKey);<br>begin<br> &nbsp;if msg.HotKey = id then<br> &nbsp; &nbsp;ShowMessage('Ctrl+Alt+R键被按下!');<br> &nbsp;form1.Visible :=true;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Const<br>{ALT、CTRL和R键的虚拟键值}<br> &nbsp;MOD_ALT = 1;<br> &nbsp;MOD_CONTROL = 2;<br> &nbsp;VK_R = 82;<br>begin<br> &nbsp;{首先判断程序是否已经运行}<br> &nbsp;if GlobalFindAtom('MyHotkey') = 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;{注册全局热键Ctrl + Alt + R}<br> &nbsp; &nbsp; &nbsp;id := GlobalAddAtom('MyHotkey');<br> &nbsp; &nbsp; &nbsp;RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R);<br> &nbsp; &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;halt;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> &nbsp;RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE);<br> &nbsp;form1.Hide;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> &nbsp;close;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp;{退出时释放全局热键}<br> &nbsp;UnRegisterHotKey(handle,id);<br> &nbsp;GlobalDeleteAtom(id);<br>end;<br><br>end.
 
不行,还是提示同样的错误。
 
再USES SysOption;看有没有用???
 
好像没有这个单元,在什么目录的,我用D6
 
这是win9X上的函数,win2K以上就不能用了。。<br><br>[red]http://www.delphibbs.com/delphibbs/dispq.asp?lid=617077[/red]
 
楼上的,2K以上的该用什么文件?
 
看这些吧<br>http://www.aidelphi.com/ShowTopic.asp?TopicID=9227&amp;PageIDX=1&amp;SpaceID=30<br>&lt;精华&gt; 在Windows2000中动态禁用/启用Ctrl-Alt-Delete <br>http://cnzz.cn/soft/html/18466.html<br> 在2000XP2003下屏蔽Ctrl + Alt + Del组合键 <br>http://dev.csdn.net/develop/article/15/15645.shtm<br>如何: 在Windows2000中动态禁用/启用Ctrl-Alt-Delete
 
后退
顶部