关于网友提出的“ 主程序如何知道系统单击鼠标事件?(下面程序如何修改)”问题疑问,本网通过在网上对“ 主程序如何知道系统单击鼠标事件?(下面程序如何修改)”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 主程序如何知道系统单击鼠标事件?(下面程序如何修改)
描述: library GMousehook;
uses
SysUtils,wintypes,winprocs,messages,windows, Dialogs, mousehookdemou,
Classes;
var
ishooked:boolean;
hookhandle:hhook;
desktopwin:hwnd;
OldProc:FARPROC;
function hookproc(code:integer;wparam:wparam;lparam:lparam):lresult;stdcall;
var
WinStr:HWND;
var form1:tform1;
begin
if wparam=WM_LBUTTONDBLCLK then
begin
{messagebeep(mb_iconasterisk);
WinStr:=FindWindow(nil,'form1');
OldProc:=FARPROC(GetWindowLong(WinStr,GWL_WNDPROC));
//SetWindowLong(WinStr,GWL_WNDPROC,Longint(@WinProc));
mousehookdemou.s:='asdf'; }
form1:=tform1.Create(nil);
form1.Label1.Caption:='123';
showmessage('鼠标事件');
end;
result:=callnexthookex(hookhandle,code,wparam,lparam);
end;
function sethook:boolean;stdcall;
begin
result:=false;
if ishooked then
exit;
//desktopwin:=getdesktopwindow;
hookhandle:=setwindowshookex(wh_mouse,hookproc,hinstance,0);
ishooked:=true;
result:=hookhandle<>0;
end;
Function WinProc(Hwnd,Msg,wParam,lParam:longint):LRESULT; stdcall;
begin
{在这做出对消息的处理
case Msg of
WM_ACTIVATEAPP:exit;
WM_ACTIVATE:exit;
WM_KILLFOCUS:exit;
WM_SETFOCUS:exit;
end;
上面这些消息是窗口失去焦点和获得焦点的屏蔽
}
//将窗口消息传递给Windows处理
Result:=CallWindowProc(OldProc,Hwnd,Msg,wParam,lParam);
end;
function removehook:boolean;stdcall;
begin
result:=false;
if (not ishooked) and (hookhandle<>0) then
result:=unhookwindowshookex(hookhandle);
ishooked:=false;
end;
exports
sethook name 'sethook',
removehook name 'removehook',
hookproc name 'hookproc';
{$R *.res}
begin
ishooked:=false;
end.
主程序:
unit mousehookdemou;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
function sethook:boolean;stdcall;
function removehook:boolean;stdcall;
var
Form1: TForm1;
s:string;
implementation
function sethook;external 'gmousehook.dll' name 'sethook';
function removehook;external 'gmousehook.dll' name 'removehook';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if sethook then
showmessage('global mouse hook set, click on desktop ')
else
showmessage('global mouse hook not set');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if removehook then
showmessage('global mouse hook removed,click on desktop')
else
showmessage('global mouse hook not removed');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
showmessage(s);
end;
end.
程序如何修改,请指教?
以上介绍了“ 主程序如何知道系统单击鼠标事件?(下面程序如何修改)”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3668799.html