获取已打开的所有记事本的标题


unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;



type

  TForm1 = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    procedure Button1Click(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



{获取已打开的所有记事本的标题}

procedure TForm1.Button1Click(Sender: TObject);

var

  h: HWnd;

  p: array[0..254] of char;

begin

  Memo1.Clear;

  h := GetWindow(Handle, GW_HWNDFIRST);

  while h <> 0 do

  begin

    GetClassName(h, p, Length(p));

    if p = 'Notepad' then

    begin

      GetWindowText(h, p, Length(p));

      Memo1.Lines.Add(p);

    end;

    h := GetWindow(h, GW_HWNDNEXT);

  end;

end;



end.


 
   
参考笔记:
http://www.cnblogs.com/del/archive/2008/02/25/1081295.html
http://www.cnblogs.com/del/archive/2008/02/28/1085404.html
http://www.cnblogs.com/del/archive/2008/02/28/1085432.html

你可能感兴趣的:(记事本)