type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function EnumWindowsProc(AHWnd: HWnd;
LPARAM: lParam): boolean; stdcall;
var
WndCaption: array[0..254] of char;
WndClassName: array[0..254] of char;
begin
GetWindowText(AHWnd, @WndCaption, 254);
GetClassName(AHWnd, @WndClassName, 254);
with Form1.Memo1.Lines do
begin
Add(StrPas(WndCaption));
Add(StrPas(WndClassName));
Add('-------');
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Clear;
EnumWindows(@EnumWindowsProc, 0);
end;
HWND hWnd, // handle of window or control with text
LPTSTR lpString, // address of buffer for text
int nMaxCount // maximum number of characters to copy
);
HWND GetActiveWindow(VOID)
int GetWindowTextLength(
HWND hWnd // handle of window or control with text
);
不知你所说当前窗口是DELPHI程序运行后的窗口,还是WINDOWS的活动窗口,可用GetActiveWindow获得活动窗口,可用GetWindowTextLength获得标题长度,可用
GetWindowText得到标题。
比如:
var
str:string;
myhand:THandle;
mylen:integer;
begin
myhand:=GetActiveWindow;
mylen:=GetWindowTextLength(myhand);
setlength(str,mylen+1);
GetWindowText(myhand,Pchar(str),mylen);
end;