上一篇 | 下一篇

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

发布: 2008-6-26 20:29 | 作者: admin | 来源: | 查看: 0次

width="84%">用Delphi开发windows95屏幕保护预览程序

北京上地信息中路3#包伟

----大家都知道windows屏幕保护程序的作用,而且新的屏幕保护程序越来越漂亮.如果在win95的桌面右键菜单选属性,就弹出显示器设置界面,有一个标签是设置屏幕保护程序的.

----在该页的画面上,有一个显示器图案,如果你选择win95所带的屏幕保护程序,这个屏幕保护程序就会在这个小'显示器'上自动运行,你可以直接看到运行效果.这功能大大方便了屏幕保护程序的选择,这就是win95对屏幕保护程序的新增接口:预览功能.

----目前大多数新推出的屏幕保护程序都支持这个接口.

----屏幕保护程序从它的诞生那时起,在同一时刻只能运行一个,不能多个同时运行,然而预览接口的推出,使同时预览多个屏幕保护程序成为可能,本文将向读者介绍如何用Delphi开发这样一个程序.

----1.屏幕保护预览接口

----屏幕保护预览接口的使用很简单,这是通过传给屏幕保护程序的命令行参数来实现的,该命令行参数格式为:

----screensaver.exe/p#####

----其中#####为一个有效的窗口句柄的10进制表示.

----这个窗口我们可以称之为预览窗口.

----实际上,支持预览接口的屏幕保护程序将自己的窗口创建为预览窗口的子窗口来实现预览功能的.

----2.画面布局

----我们这个程序的窗口分为3部分,为倒'品'字形,上左部分列出所有可用的屏幕保护程序,上右部分列出所有预览的屏幕保护程序,下面当然是预览窗口了.

----用Delphi实现时,首先在Form里放2个TPanel组件,Panel1对齐方式为顶部对齐,Panel2为撑满用户区,再在Panel1中放1个TFileListBox组件和一个TListBox组件,FileListBox1左对齐,ListBox1撑满用户区.

----这样,FileListBox1为屏幕保护列表,ListBox1为预览列表,Panel2为预览窗口.

----3.列出屏幕保护程序.

----将FileListBox1的Mask属性设为'*.scr',这是屏幕保护程序的扩展名.

----在FormCreate方法中将FileListBox1.directory设为windows系统目录GetSystemDirectory;

----4.预览屏幕保护程序.

----在FileListBox1DblClick方法中运行该屏幕保护程序,并将Panel2的窗口句柄传给它.

----WinExec(pchar(FileListBox1.FileName+'/p'+inttostr(Panel2.handle)),SW_Show);

----运行程序,怎么样?COOL!

----5.增加一些新特性:隐藏/显示/关闭.

----增加2个函数:用于更新ListBox1.

function EnumProc(

h:HWND;//handleofchildwindow

l:integer//application-definedvalue

):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;

----增加一个弹出菜单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

字号: | 推荐给好友

31/3123>

评分:0

我来说两句