我这里有一个简单但是完整的例子,看看(1个Button, 1个Edit, 1个Timer):
unit ShowPasswd_pas;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    Txt: TEdit;
    Tim: TTimer;
    btCmd: TButton;
    procedure btCmdClick(Sender: TObject);
    procedure TimTimer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  X,Y:Integer;
  Pos:TPoint;
  hResult,hLength:LongInt;
  hNow: THandle;implementation{$R *.DFM}
function GetText(hWndNow:Integer):String;
var
  buf:Array of Char;
  t:String;
  i:Integer;
begin
  hLength:=SendMessage(hWndNow,WM_GETTEXTLENGTH,0,0);
  if hLength>0 then
  begin
    SetLength(buf,hLength+1);
    SendMessage(hWndNow,WM_GETTEXT,hLength+1,LPARAM(buf));
    for i:=0 to Length(buf) do
      t:=t+buf[i];    GetText:=t;
  end
  else
    GetText:='';
end;
procedure TForm1.btCmdClick(Sender: TObject);
begin
  if btCMD.Caption='Start' then
  begin
    btCMD.Caption:='Stop';
    Tim.Enabled:=true;
  end
  else
  begin
    btCMD.Caption:='Start';
    Tim.Enabled:=false;
  end
end;procedure TForm1.TimTimer(Sender: TObject);
var
  t:array [0..254] of char;
begin
  GetCursorPos(Pos);
  hNow:=WindowFromPoint(Pos);
  GetClassName(hNow,@t,255);
  if (t[0] = 'E') and (t[1] = 'd') and (t[2] = 'i') and (t[3] = 't') and (t[4] = #0) then
  begin
    if hNow<>Form1.Handle then
      Txt.Text:=GetText(hNow);
  end
  else
    Txt.Text:= 'not a EDIT!';
//  GetClass(t);
//  Txt.Text:=t;
//  Tim.Enabled:=false;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Tim.Enabled:=false;
end;end.

解决方案 »

  1.   

    我做过这样的一个程序(东日-看星星),和你的需要一模一样。不过是C++Builder做的(和delphi差不多),我已经公布源代码,你可以看看。http://www.sunistudio.com/download/pswdcode.zip欢迎访问“东日制作室”—— http://www.sunistudio.com
      

  2.   

    我也做了个这样的东西
    功能还比较强大
    去 csdn 共享软件 网络辅助 中去下载 i-Fresher吧
    我也提供原代码。
    相信你需要的就是这个了。
      

  3.   

    To gameboy999:
       你好,能给我源代码吗?谢谢!  Email:[email protected]
      

  4.   

    To Java_SCU(Java)
    感谢你为我提供源代码,我就此有一点问题想请教:为什么只能显示出一小部分窗口的控件(Edit编辑框)的星号密码呢?任意编一个程序,其Edit编辑框的PasswordChar属性定义为'*',通过你提供的源代码所编译的程序,就不能显示出相应的Edit编辑框中的字符串……
      

  5.   

    var
    p:tpoint
    memo1.clear;
    getcursorpos(p);
    hd1:=windowfrompoint(p);while not (hd1=0)  do
    begin
       getclassname(hd1,buf,50);
        memo1.lines.add(buf);
       hd1:=getparent(hd1);
    end;
      

  6.   

    to tombyron:
      Sorry,这是由于我的判断条件过于严格造成的,改写为:
    procedure TForm1.TimTimer(Sender: TObject);
    var
      t:array [0..254] of char;
      tt: String;
    begin
      GetCursorPos(Pos);
      hNow:=WindowFromPoint(Pos);
      GetClassName(hNow,@t,255);
      tt:= StrPas(t);
      if (tt = 'Edit') or (tt = 'TEdit') then    <-关键在这里
      begin
        if hNow<>Form1.Handle then
          Txt.Text:=GetText(hNow);
      end
      else
        Txt.Text:= 'not a EDIT!';
    end;
      

  7.   

    我原来是用VC编写的程序来测试的,因此类名为Edit,而Delphi编写的类名确是TEdit,所以闲是不出来。如果遇到其它新的类名的话,你可以自己单步跟踪添加。
      

  8.   

    To gameboy999:
      你好,能给我i-Fresher的源代码吗?谢谢!  Email:[email protected] 
      

  9.   

    To gameboy999:
      你好,能给我i-Fresher的源代码吗?谢谢!  Email:[email protected] 
      

  10.   

    to tombyron:
    我看见了:)
    看你的邮箱吧。
      

  11.   

    To gameboy999:
       请问:你不是发的附件吗?
       我收到的是这些东东,有很多乱码,看不懂:   Date: Sun, 21 Jan 2001 07:58:08 GMT
    Mime-version: 1.0
    Content-type: multipart/mixed; boundary="=_0_26175_980063888"; charset="us-ascii
    "This is a MIME-formatted message.  If you see this text it means that your
    mail software cannot handle MIME-formatted messages.--=_0_26175_980063888
    Content-Type: text/plain; charset=us-ascii
    --=_0_26175_980063888
    Content-Type: application/zip; name="source.zip"
    Content-Disposition: inline; filename="source.zip"
    Content-Transfer-Encoding: base64UEsDBBQAAAAIAIerkinDmrKxjwcAADkPAAAJAAAAYWJvdXQuZGN17Vb/bxvlGX+fa2w/TTLXS92Q
    hTRNohAlXWLRpKrarWL54rjNlobUdr/AtmqXu9fOtec7c3duk2paA1TQUjFKG9gQaFu1qatEQYA0
    SC2EAtkyVqEIoSx0sB+gIDbo1h8mTWza1ux972zn3Cv7C3ayXz/v+/nc877PV7+nwhv+tm0NIQ8/
    e6aD8OdJsj27WhzTc1YkK5r3PSp3EKMwj8Z2Xc2c6RBkTFjygGWoZtfPzw+l/MlhcYyqZzc/3ZIK
     
      这是怎么回事哟? 能不能再用附件的形式发给我? 谢谢你了!
      

  12.   

    to gameboy999:
       OK,已经收到你的源代码,谢谢你!
      

  13.   

    你们还能不能帮我解决几个问题?
    (我已在“专家门诊”中提出来了)
    1. 如何实现象Oicq那样用户之间文件的相互传输?[Delphi]
    2. 如何发大和缩小图标(*.ico)?格式为*.bmp等等的图可以放大或缩小,但是*.ico却不知道怎么实现,请问各位大侠怎样才能实现?[Delphi]