nit MainFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, CommCtrl;
type
TMainForm = class(TForm)
tmScratch: TTimer;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
tmWait: TTimer;
Label4: TLabel;
Label5: TLabel;
procedure tmScratchTimer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
{详细资料见 HOWTO: Get a Window's Class Name and Other Window Attributes}
private
{ Private declarations }
procedure WMNLButtonDown(var Message: TMessage);message WM_LBUTTONDOWN;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
var
PreClassLength, PreTextLength: Integer;
{$R *.DFM}
procedure TMainForm.tmScratchTimer(Sender: TObject);
var
ClassName: PChar;
ptCursor: TPoint;
hWndOver: HWND;
Text: PChar;
begin
GetCursorPos(ptCursor);
hWndOver := WindowFromPoint(ptCursor);
GetMem(ClassName, 100);
GetMem(Text, 255);
try
GetClassName(hWndOver, ClassName, 100);
SendMessage(hWndOver, WM_GETTEXT, 255, LongInt(Text));
Canvas.FillRect(Rect(5, 20 , PreClassLength + 20, 40));
Canvas.FillRect(Rect(5, 40 , PreTextLength + 20, 60));
PreClassLength := Canvas.TextWidth(ClassName);
PreTextLength := Canvas.TextWidth(Text);
if PreClassLength > PreTextLength then
Width := Canvas.TextWidth(ClassName) + 20
else
Width := Canvas.TextWidth(Text) + 20;
Canvas.TextOut(5, 20, string(ClassName));
Canvas.TextOut(5, 35, string(Text));
finally
FreeMem(ClassName);
FreeMem(Text);
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
PreClassLength := 0;
PreTextLength := 0;
Width := 80;
Height := 55;
end;
procedure TMainForm.SpeedButton2Click(Sender: TObject);
begin
Close;
end;