首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么将所有正在运行的窗口显示在一个ListView中

2012-03-20 
如何将所有正在运行的窗口显示在一个ListView中!如题,高手帮一下忙呀[解决办法]unit Unit1interfaceusesW

如何将所有正在运行的窗口显示在一个ListView中!
如题,高手帮一下忙呀

[解决办法]
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function GetText(Wnd: HWND): string;
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0 then Result := ' '
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;

function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
begin
Result := True;
if (IsWindowVisible(Wnd)) and (Trim(GetText(Wnd))<> ' ')then
Form1.Listbox1.Items.Add( 'Handle: ' + IntToStr(Wnd) + ',Text: ' + GetText(Wnd));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Param: Longint;
begin
EnumWindows(@EnumWindowsProc, Param);
end;

end.

[解决办法]
function EnumWindowProc(AHandle: THandle; List:TListItems): Boolean;stdcall;
var
ACaption: array[0..256] of Char;
begin
if GetWindowText(AHandle,ACaption,SizeOf(ACaption)-1) <> 0 then
begin
List.Add.Caption := ACaption;
// SetWindowText(Handle, PChar( 'About - ' + ACaption));
end;
Result :=True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ListView1.Items.Clear;
EnumWindows(@EnumWindowProc,LParam(ListView1.Items));
end;
[解决办法]
改一下
if (IsWindowVisible(Wnd)) and (Trim(GetText(Wnd)) <> ' ')then

热点排行