begin
ListBox1.clear;
enumChildwindows(Panel2.handle,
TFNWndEnumProc(@enumproc), 0);
end;
---- 增 加 一 个 弹 出 菜 单Popupmenu1, 3 个 菜 单 项, 'Show, Hide, Close', 将ListBox1.popupmemu 指 向Popupmenu1.
---- Hide 的 处 理 函 数 是:
procedure TForm1.Hide1Click(Sender: TObject);
var
h : integer;
s : string;
begin
if ListBox1.itemindex = -1 then exit;
s := Listbox1.items[ListBox1.itemindex];
h := strtoint(copy(s, pos(':', s) + 1, length(s)));
ShowWindow(h, SW_HIDE);
Fresh1;
end;
Show 的 处 理 函 数 是:
procedure TForm1.Show1Click(Sender: TObject);
var
h : integer;
s : string;
begin
if ListBox1.itemindex = -1 then exit;
s := Listbox1.items[ListBox1.itemindex];
h := strtoint(copy(s, pos(':', s) + 1, length(s)));
ShowWindow(h, SW_SHOW);
Fresh1;
end;
Close 的 处 理 函 数 是:
procedure TForm1.Close1Click(Sender: TObject);
var
h : integer;
s : string;
begin
if ListBox1.itemindex = -1 then exit;
s := Listbox1.items[ListBox1.itemindex];
h := strtoint(copy(s, pos(':', s) + 1, length(s)));
PostMessage(h, WM_QUIT, 0, 0);
Fresh1;
end;
---- 本 程 序 在Delphi 3.0 下 调 试 通 过, 应 该 能 用Delphi 1.0 / 2.0 编 译.
---- 完 整 程 序 如 下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl, ExtCtrls, Menus;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
FileListBox1: TFileListBox;
ListBox1: TListBox;
PopupMenu1: TPopupMenu;
Hide1: TMenuItem;
Show1: TMenuItem;
Close1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FileListBox1DblClick(Sender: TObject);
procedure Hide1Click(Sender: TObject);
procedure Show1Click(Sender: TObject);
procedure Close1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Fresh1;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function EnumProc(
h : HWND ;// handle of child window
l : integer// application-defined value
): boolean;stdcall;
var buf : array[0..255] of char;
begin
GetWindowText(h, buf, sizeof(buf)- 1);
if iswindowvisible(h) then
Form1.ListBox1.items.add(' ' +strpas(buf) + ' : ' + inttostr(h))
else
Form1.ListBox1.items.add('-' +strpas(buf) + ' : ' + inttostr(h));
Result := true;
end;
procedure TForm1.Fresh1;
begin
ListBox1.clear;
enumChildwindows(Panel2.handle, TFNWndEnumProc(@enumproc), 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
var buf : array[0..256] of char;
begin
GetSystemDirectory(buf, sizeof(buf) - 1);
FileListBox1.directory := strpas(buf);
ListBox1.popupmenu := Popupmenu1;