mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
源码类别:

Delphi/CppBuilder

开发平台:

Delphi

  1. unit mainunit;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, ExtCtrls;
  6. type
  7.   TForm1 = class(TForm)
  8.     GroupBox1: TGroupBox;
  9.     Button1: TButton;
  10.     Button2: TButton;
  11.     Label1: TLabel;
  12.     Label2: TLabel;
  13.     Label3: TLabel;
  14.     Label4: TLabel;
  15.     Label5: TLabel;
  16.     Label6: TLabel;
  17.     Label7: TLabel;
  18.     Timer1: TTimer;
  19.     
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure FormPaint(Sender: TObject);
  22.     procedure Button2Click(Sender: TObject);
  23.     procedure Button1Click(Sender: TObject);
  24.     procedure Timer1Timer(Sender: TObject);
  25.   private
  26.     { Private declarations }
  27.   public
  28.     procedure GetRectArea;
  29.     { Public declarations }
  30.   end;
  31. var
  32.   Form1: TForm1;
  33.   FormHandle:Hwnd;
  34.   FrmLeft,FrmTop,FrmRight,FrmBottom:Integer;
  35. implementation
  36. {$R *.dfm}
  37. procedure JudgePointPosition(CurPoint:TPoint);
  38. begin
  39.  if ((CurPoint.X >= FrmLeft) and (CurPoint.X <= Frmright) and
  40.      (CurPoint.Y >= FrmTop) and (CurPoint.Y <= FrmBottom)) then
  41.     begin
  42.      Form1.Show;
  43.     end
  44.     else
  45.     begin
  46.      Form1.hide;
  47.     end;
  48. end;
  49. procedure TForm1.GetRectArea;
  50. var
  51.  rect:TRect;
  52. begin
  53.  GetWindowRect(FormHandle,rect);
  54.  label1.Caption:='窗体左上角坐标:'+'('+Inttostr(rect.left)+','+Inttostr(rect.top)+')';
  55.  label2.Caption:='窗体右上角坐标:'+'('+Inttostr(rect.right)+','+Inttostr(rect.top)+')';
  56.  label3.Caption:='窗体左下角坐标:'+'('+Inttostr(rect.left)+','+Inttostr(rect.bottom)+')';
  57.  label4.Caption:='窗体右下角坐标:'+'('+Inttostr(rect.right)+','+Inttostr(rect.bottom)+')';
  58.  FrmLeft:=rect.left;
  59.  FrmTop:=rect.top;
  60.  FrmRight:=rect.right;
  61.  FrmBottom:=rect.bottom;
  62. end;
  63. procedure TForm1.FormCreate(Sender: TObject);
  64. begin
  65.  FormHandle:=Form1.Handle;
  66. end;
  67. procedure TForm1.FormPaint(Sender: TObject);
  68. begin
  69.  GetRectArea;
  70. end;
  71. procedure TForm1.Button2Click(Sender: TObject);
  72. begin
  73.  Timer1.Enabled:=False;
  74. end;
  75. procedure TForm1.Button1Click(Sender: TObject);
  76. begin
  77.  Timer1.Enabled:=True;
  78. end;
  79. procedure TForm1.Timer1Timer(Sender: TObject);
  80. var
  81.  P:TPoint;
  82. begin
  83.  GetRectArea;
  84.  GetCursorPos(P);
  85.  Form1.label6.caption:='横坐标:'+InttoStr(P.x);
  86.  Form1.label7.caption:='纵坐标:'+InttoStr(P.y);
  87.  JudgePointPosition(P);
  88. end;
  89. end.