如何得到当前windows的标题

wsf 2000-04-21 01:11:00
如何用delphi调用windows api 得到当前窗口的标题
...全文
105 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsf 2000-04-23
  • 打赏
  • 举报
回复
非常感谢rollback and 929
rollback 2000-04-21
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

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;

end.
929 2000-04-21
  • 打赏
  • 举报
回复
int GetWindowText(

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;

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧