如何在鼠标所指的一个窗体边框上绘制一个矩形?用API--Rectangle吗?我应该如何用?(delphi)谢谢!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        procedure Timer1Timer(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        FOldHandle: THandle;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
    const
      cWidth = 3;
    var
      vRect: TRect;
      vHandle: THandle;
      vBoxHandle: THandle;
    begin
      if Color = clWindow then
        Color := clBlue
      else Color := clWindow;  vHandle := WindowFromPoint(Mouse.CursorPos);
      if vHandle = FOldHandle then Exit;
      FOldHandle := vHandle;  if vHandle = Handle then begin
        Hide;
        Exit;
      end;
      Show;
      GetWindowRect(vHandle, vRect);
      Left := vRect.Left;
      Top := vRect.Top;
      Width := vRect.Right - vRect.Left;
      Height := vRect.Bottom - vRect.Top;  vRect := BoundsRect;
      vHandle := CreateRectRgn(0, 0, Width, Height);
      vBoxHandle := CreateRectRgn(cWidth, cWidth, Width - cWidth, Height - cWidth);
      try
        CombineRgn(vHandle, vHandle, vBoxHandle, RGN_XOR);
        SetWindowRgn(Handle, vHandle, True);
      finally
        DeleteObject(vHandle);
        DeleteObject(vBoxHandle);
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Timer1.Interval := 500;
      Color := clBlue;
      BorderStyle := bsNone;
      FormStyle := fsStayOnTop;
      Application.ShowMainForm := False;
    end;end.
      

  2.   

    好像没有用啊,我的意思是说,像spy++那样鼠标指到哪,那就有一个绘制的矩形