给我设计一套服装,我就给你写代码。以前回复过的。。如下
(或链接: http://www.delphibbs.com/delphibbs/dispq.asp?lid=3373886)
方法一: 添加一Timer ,定义一个Tpoint变量pt,在onTimer中 getCursorPos(pt);label1.caption:=inttostr(pt.x)+' '+inttostr(pt.y);即可。
方法二:点右键显示坐标,主程序代码:
unit mainWnd;
interface
uses
{ Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
}
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
public
{ Public declarations }
procedure wndProc(var mess:TMessage);override;
private
{ Private declara }
end;
var
Form1: TForm1;
myMessage:UINT;
implementation
{$R *.dfm}
procedure installMouseHook;external './hookdll.dll';
procedure unHookMouseHook;external './hookdll.dll';
procedure byMain( wnd:Hwnd);external './hookdll.dll';
procedure TForm1.wndProc(var mess:TMessage);
begin
if mess.Msg=myMessage then
begin
label1.Caption:='X'+inttostr(mess.wparam)+' Y'+inttostr(mess.lparam);
end else
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
byMain(form1.handle);
installMouseHook;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
unHookMouseHook;
end;
begin
myMessage:=registerWindowMessage(pchar('sxw'));
end.
//dll中代码为
library hookdll;
uses
ShareMem,
Windows,
Classes,
Controls,
Dialogs,
SysUtils,
shellapi,
Qt;
{$R *.res}
var mousehook:HHook;
callMessage:UINT;
mainwindow:Hwnd;
procedure byMain(wnd:Hwnd);
begin
mainWindow:=wnd;
end;
function MouseProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
var p:^MOUSEHOOKSTRUCT;
begin
p:=ptr(lParam);
if (wParam=516) and (ncode>=0) then
sendMessage(hwnd_broadCast,callMessage,p^.pt.x,p^.pt.y);
result:=callNextHookEx(mouseHook,nCode,wParam,lParam);
end;
procedure installMouseHook;stdcall;
begin
mousehook:=setWindowsHookEx(WH_MOUSE,@MouseProc,Hinstance,0);
end;
procedure unHookMouseHook;stdcall;
begin
if mousehook<>0 then
begin
unHookWindowsHookEx(mousehook);
end;
end;
exports
unHookMouseHook,
installMouseHook,
byMain;
begin
callMessage:=registerWindowMessage('sxw');
end.
结帐吧!