新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > 开发语言 > Delphi教程 > 正文:用Delphi开发屏幕保护预览程序

用Delphi开发屏幕保护预览程序

新客网 XKER.COM 2006-07-13 来源: 收藏本文

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;

共3页: 上一页 [1] [2] [3] 下一页
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐