⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainunit.pas

📁 Delphi7经典问题解析源代码Delphi7经典问解析源代码
💻 PAS
字号:
unit mainunit;

interface

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

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    HookHandle: THandle;
    { Private declarations }
  public
    procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
    procedure GetRectArea;
    { Public declarations }
  end;

var
  Form1: TForm1;
  FormHandle:Hwnd;
  FrmLeft,FrmTop,FrmRight,FrmBottom:Integer;
implementation

{$R *.dfm}
procedure JudgePointPosition(CurPoint:TPoint);
begin
 if ((CurPoint.X >= FrmLeft) and (CurPoint.X <= Frmright) and
     (CurPoint.Y >= FrmTop) and (CurPoint.Y <= FrmBottom)) then
    begin
     Form1.Show;
    end
    else
    begin
     Form1.hide;
    end;
end;

function MouseProc(Code: Integer; W: WPARAM; L: LPARAM): LRESULT; stdcall;
var
 CurPoint:TPoint;
begin
 if Code < 0 then
  Result := CallNextHookEx(Form1.HookHandle, Code, W, L)
 else
 begin
  if Code=HC_ACTION then
   begin
    if W = WM_MOUSEMOVE then
     begin
      Form1.label6.caption:='横坐标:'+InttoStr(PMouseHookStruct(L).pt.x);
      Form1.label7.caption:='纵坐标:'+InttoStr(PMouseHookStruct(L).pt.y);
      CurPoint:=PMouseHookStruct(L).pt;
      JudgePointPosition(CurPoint);
     end;
    Result := 0;
   end;
 end;
end;



procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
 GetRectArea;
 DefaultHandler(Msg);
end;

procedure TForm1.GetRectArea;
var
 rect:TRect;
begin
 GetWindowRect(FormHandle,rect);
 label1.Caption:='窗体左上角坐标:'+'('+Inttostr(rect.left)+','+Inttostr(rect.top)+')';
 label2.Caption:='窗体右上角坐标:'+'('+Inttostr(rect.right)+','+Inttostr(rect.top)+')';
 label3.Caption:='窗体左下角坐标:'+'('+Inttostr(rect.left)+','+Inttostr(rect.bottom)+')';
 label4.Caption:='窗体右下角坐标:'+'('+Inttostr(rect.right)+','+Inttostr(rect.bottom)+')';
 FrmLeft:=rect.left;
 FrmTop:=rect.top;
 FrmRight:=rect.right;
 FrmBottom:=rect.bottom;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
 FormHandle:=Form1.Handle;
 HookHandle := 0;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
 GetRectArea;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 if HookHandle <> 0 then
 begin
  UnhookWindowsHookEx(HookHandle);
  HookHandle := 0;
  Form1.Caption:='鼠标钩子成功卸载!';
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if HookHandle = 0 then
 begin
  HookHandle := SetWindowsHookEx(WH_MOUSE, @MouseProc, hInstance, 0);
  if HookHandle<>0 then
   Form1.Caption:='成功加载了鼠标钩子函数!';
 end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -