郁闷啊!下面这段代码是dll中的键盘钩子的回调函数,想在这个回调函数中打开
dll中的窗体!但是现在连编译都过不了。这是drhook 工程文件:library drHook;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
Forms,
Unit2 in 'Unit2.pas',
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}exports
CreateKeyboardHook,
DestroyKeyboardHook;
begin
hNextHookProc := 0;
procSaveExit := ExitProc;
ExitProc := @KeyboardHookExit;
end.这是dll中的键盘钩子:
unit Unit2;interfaceuses
Windows, SysUtils;
var
hNextHookProc: HHook;
procSaveExit: Pointer;function KeyboardHookProc(code: Integer; wparam: WPARAM;
lparam: LPARAM): LRESULT stdcall; export;
function CreateKeyboardHook: BOOL; stdcall; export;
function DestroyKeyboardHook: BOOL; stdcall; export;
procedure KeyboardHookExit;implementationvar
GameSwitch: Word; //程序热键function KeyboardHookProc(code: Integer; wparam: WPARAM;
lparam: LPARAM): LRESULT;
const
_KeyProcessMask = $80000000;
begin
Result := 0;
if code < 0 then
begin
Result := Windows.CallNextHookEx(hNextHookProc, code, wparam, lparam);
Exit;
end;
if ((lparam and _KeyProcessMask) = 0) and (wparam = GameSwitch) then
begin
Application.Handle := GetForegroundWindow; //返回当前窗口句柄
Result := 1;
end;
end;function CreateKeyboardHook: BOOL;
begin
Result := false;
if hNextHookProc <> 0 then
exit;
hNextHookProc := Windows.SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,
hInstance, 0);
Result := hNextHookProc <> 0;
end;function DestroyKeyboardHook: BOOL;
begin
if hNextHookProc <> 0 then
begin
Windows.UnhookWindowsHookEx(hNextHookProc);
hNextHookProc := 0;
end;
Result := hNextHookProc = 0;
end;procedure KeyboardHookExit;
begin
if hNextHookProc <> 0 then
DestroyKeyboardHook;
ExitProc := procSaveExit;
end;Initialization
GameSwitch := VK_HOME;end.这是那个窗体文件,啥都没有,就一个空窗体,我就想让他显示
困扰好久了。比较菜unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;implementation
{$R *.dfm}
end.
希望那位大哥能指点指点,小弟先谢谢了。
dll中的窗体!但是现在连编译都过不了。这是drhook 工程文件:library drHook;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
Forms,
Unit2 in 'Unit2.pas',
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}exports
CreateKeyboardHook,
DestroyKeyboardHook;
begin
hNextHookProc := 0;
procSaveExit := ExitProc;
ExitProc := @KeyboardHookExit;
end.这是dll中的键盘钩子:
unit Unit2;interfaceuses
Windows, SysUtils;
var
hNextHookProc: HHook;
procSaveExit: Pointer;function KeyboardHookProc(code: Integer; wparam: WPARAM;
lparam: LPARAM): LRESULT stdcall; export;
function CreateKeyboardHook: BOOL; stdcall; export;
function DestroyKeyboardHook: BOOL; stdcall; export;
procedure KeyboardHookExit;implementationvar
GameSwitch: Word; //程序热键function KeyboardHookProc(code: Integer; wparam: WPARAM;
lparam: LPARAM): LRESULT;
const
_KeyProcessMask = $80000000;
begin
Result := 0;
if code < 0 then
begin
Result := Windows.CallNextHookEx(hNextHookProc, code, wparam, lparam);
Exit;
end;
if ((lparam and _KeyProcessMask) = 0) and (wparam = GameSwitch) then
begin
Application.Handle := GetForegroundWindow; //返回当前窗口句柄
Result := 1;
end;
end;function CreateKeyboardHook: BOOL;
begin
Result := false;
if hNextHookProc <> 0 then
exit;
hNextHookProc := Windows.SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,
hInstance, 0);
Result := hNextHookProc <> 0;
end;function DestroyKeyboardHook: BOOL;
begin
if hNextHookProc <> 0 then
begin
Windows.UnhookWindowsHookEx(hNextHookProc);
hNextHookProc := 0;
end;
Result := hNextHookProc = 0;
end;procedure KeyboardHookExit;
begin
if hNextHookProc <> 0 then
DestroyKeyboardHook;
ExitProc := procSaveExit;
end;Initialization
GameSwitch := VK_HOME;end.这是那个窗体文件,啥都没有,就一个空窗体,我就想让他显示
困扰好久了。比较菜unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;implementation
{$R *.dfm}
end.
希望那位大哥能指点指点,小弟先谢谢了。
解决方案 »
- "句柄"在Delphi 中的作用是什么(详细)。急!!!
- TDBChart组件在哪里啊?我没找到
- 想转行搞餐饮业,帮我的饮食店起个名字,要有个凯字!!!各位帮忙想想:)
- 如何弹出已个对话框?
- 为什么我从数据采集仪采集到的数据是乱码?
- PowerBuilder 和 delphi 数据库开发方面的比较
- 如何让我的程序在windows启动后自动运行,并不能让人很容的就去掉该自动运行功能
- 在一个treeview的节点中,怎么设置每个字的颜色,各位大哥,谢谢了
- 能否采用hook实时获得用户在我的电脑或资源管理器中选取的文件及路径?
- delphi7+ado+sqlsever2008数据库软件发布打包些什么东,还有人用delphi 么,求好友
- 做触摸屏程序,界面lable做菜單,更新label時界面閃得厲害,怎麼解決.
- 点树弹出窗体
Windows, SysUtils, Forms; // add Forms
Application声明在Forms单元中,难道你没有看帮助?