不如通过鼠标来选取窗体的HANDLE:
如下,通过在PANEL1点击,拖动到你要得到HANDLE的窗体标题或者输入框上,松手
就得到HANDLE了。
procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var p:tpoint;
    text:array[1..255] of char;
begin
  if button=mbleft then
  begin
     screen.Cursor:=oldcursor;
     getcursorpos(p);
     ahandle:=windowfrompoint(p);//得到句柄
     sendmessage(ahandle,wm_gettext,100,LongInt(@text));
     if text[1]='' then
     windows.getwindowtext(ahandle,@text,255);
     edit1.Text:=text;
     if edit1.text='' then edit1.Text:='对不起,失败了';
  end;   end;