吐血送分行动,非常急!!(300分)(300分)

  • 主题发起人 主题发起人 dxpjj
  • 开始时间 开始时间
D

dxpjj

Unregistered / Unconfirmed
GUEST, unregistred user!
;我正在编写一个程序,目的记录鼠标在屏幕上的点击位置,同时能够记录下鼠标所点击窗口
的标题.最好有代码.
 
SetCursorPos(
X: Integer; {X coordinate of the cursor}
Y: Integer {Y coordinate of the cursor}
): BOOL; {returns TRUE or FALSE}


GetWindow(
hWnd: HWND; {a handle to a window}
uCmd: UINT {relationship flags}
): HWND; {returns a handle to a window}


GetWindowText(
hWnd: HWND; {a handle to a window}
lpString: PChar; {a pointer to a buffer to receive the string}
nMaxCount: Integer {the maximum number of characters to copy}
): Integer; {returns the length of the copied string}

够了?
 
上面已经说得很清楚,不过我建议你,把的X,Y保存在一个INI文件中
下一次可以知道你所要的X,Y
 
一是依靠时钟不停的读鼠标的消息,还有就是使用Hook
下面的例程可以完全满足你的要求,程序执行后,双击得到输入框中的内容,可以得到密码框中的***呦

Hook代码:
library GetCharDLL;

uses
SysUtils,
Classes,
Windows,
MainDLL in 'MainDLL.pas';

{$R *.RES}

exports
InstallMouseHook,
UninstallMouseHook;

begin
DLLProc := @MouseHookDLLProc;
MouseHookDLLProc(DLL_Process_Attach);
end.

//------------------------------------------------------------------

unit MainDLL;

interface

uses
SysUtils,
Classes,
Windows,
Messages,
Dialogs;

var
hMouseHook : HHook;

function MyMouseProc(nCode : integer; wParam : WPARAM; lParam : LPARAM) : LRESULT; stdcall;
function InstallMouseHook : boolean;
function UninstallMouseHook : boolean;
procedure MouseHookDLLProc(Reason : integer);

implementation

function MyMouseProc(nCode : integer; wParam : WPARAM; lParam : LPARAM) : LRESULT; stdcall;
var
MyMouseHookStruct : ^TMouseHookStruct;
x, y : integer;
p : PChar;
begin
if (nCode >= 0) then
begin
if (wParam = WM_LBUTTONDBLCLK) then
begin
MyMouseHookStruct := Pointer(lParam);
x := MyMouseHookStruct^.pt.x;
y := MyMouseHookStruct^.pt.y;

p := StrAlloc(50);
try
if (GetWindowText(MyMouseHookStruct^.hwnd, p, 40) <> 0) then
begin
ShowMessage(IntToStr(x) + ', ' + IntToStr(y) + #13#10 + p);
end;
finally
StrDispose(p);
end;
end;
end;

Result := CallNextHookEx(hMouseHook, nCode, wParam, lParam);
end;

function InstallMouseHook : boolean;
begin
Result := False;
if (hMouseHook <> 0) then Exit;
hMouseHook := SetWindowsHookEx(WH_MOUSE, MyMouseProc, HInstance, 0);
Result := (hMouseHook <> 0);
end;

function UninstallMouseHook : boolean;
begin
if (hMouseHook <> 0) then
begin
UnhookWindowsHookEx(hMouseHook);
hMouseHook := 0;
MessageBeep(0); MessageBeep(0); MessageBeep(0);
end;

Result := (hMouseHook = 0);
end;

procedure MouseHookDLLProc(Reason : integer);
begin
case Reason of
DLL_Process_Attach: //整个DLL的初始化
begin
hMouseHook := 0;
end;

DLL_Process_Detach: //整个DLL的善後
begin
UninstallMouseHook;
end;

DLL_Thread_Attach: //开始一个Thread
begin
//
end;

DLL_Thread_Detach: //终止一个Thread
begin
//
end;
end;
end;

end.


程序代码:
unit Main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function InstallMouseHook : boolean; external 'GetCharDLL.dll' name 'InstallMouseHook';
function UninstallMouseHook : boolean; external 'GetCharDLL.dll' name 'UninstallMouseHook';

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
InstallMouseHook;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
UninstallMouseHook;
end;

end.
 
还不如用WH_JOURNALRECORD Hook呢,
 
感谢大家的回答.我不想用dll文件,用时钟也不可取,因为我要鼠标在屏幕上点击的位置记录
下来,请大家继续关注(要有代码哟,呵呵),我愿意再加100分!
 
我的意思是鼠标点击或双击屏幕时记录下屏幕的位置.
 
记录屏幕的位置?什么意思?
 
用GETCURSORPOS得到鼠标在屏幕上的位置,再用WINDOWFROMPOINT可以得到鼠标所在窗口的
HANDLE,再用GETWINDOWTEXT可以得到窗口标题。
用这两个API函数都要定义一个TPOINT类型的变量,例如:
procedure getwinfrompoint();
var
win_caption:array[0..255] of char;
mypoint:tpoint;
cur_window:hwnd;
begin
if getcursorpos(mypoint) then//得到当前鼠标所在的坐标,mypoint.x和mypoint.y
//分别代表鼠标所在坐标的x,y值
begin
cur_window:=windowfrompoint(mypoint);//得到鼠标所在窗口的句柄
getwindowtext(cur_window,pchar(@win_caption),255);//得到鼠标所在窗口的标题
showmessage(strpas(@win_caption));//@win_caption数组中保存了窗口标题
end;
再做个捕获鼠标单击的HOOK,每次单击左键时调用 这个过程,就可以的了!
 
procedure TForm1.FormDblClick(Sender: TObject);
var
Pos:TPoint;
begin
GetCursorPos(Pos);
showmessage(floattostr(Pos.x)+'---'+ floattostr(Pos.y));
end;
 
吐血?---- 我很感动......不过俺很关注
 
大家好:
感谢你们的回答!!
如何捕获鼠标在屏幕单击,双击,右键?????
 
如果不使用HOOK,或时钟的话,实现的可能性为0
因为在程序中捕获消息,只能捕获本窗口中的消息,是无法捕获其他窗口中的
使用GetCursorPos是可以的,但是你准备时候去调这个函数呢?
如果一直去调用,实时去得到鼠标消息,这又需要时钟。
所以时钟、HOOK两者必须选一。
 
多人接受答案了。
 
后退
顶部