unit MainFrm;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, ExtCtrls;<br><br>type<br> TMainForm = class(TForm)<br> HandleEdit: TEdit;<br> TextEdit: TEdit;<br> OnTopCheckBox: TCheckBox;<br> Timer: TTimer;<br> procedure FormCreate(Sender: TObject);<br> procedure TimerTimer(Sender: TObject);<br> procedure OnTopCheckBoxClick(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> MainForm: TMainForm;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure SetStayOnTop(Form: TForm; Value: Boolean);<br>begin<br> if Value Then<br> SetWindowPos(Form.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE<br>)<br> else<br> SetWindowPos(Form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSI<br>ZE);<br>end;<br><br>procedure TMainForm.FormCreate(Sender: TObject);<br>begin<br> SetStayOnTop(Self, True);<br>end;<br><br>procedure TMainForm.TimerTimer(Sender: TObject);<br>var<br> Pos: TPoint;<br> Handle: HWND;<br> Buf: array[0..1024] of Char;<br>begin<br> GetCursorPos(Pos);<br> Handle := WindowFromPoint(Pos);<br> HandleEdit.Text := IntToStr(Handle);<br> SendMessage(Handle, WM_GETTEXT, 1024, Integer(@Buf));<br> TextEdit.Text := Buf;<br>end;<br><br>procedure TMainForm.OnTopCheckBoxClick(Sender: TObject);<br>begin<br> SetStayOnTop(Self, OnTopCheckBox.Checked);<br>end;<br><br>end.<br>