Develop screen saver preview program with Delphi
Organizing and editing: China asp
---- Everyone knows the role of the windows screen saver, and the new screen saver is getting more and more beautiful. If you select properties from the desktop right-click menu of win95, the monitor settings interface will pop up, and there is a tab for setting the screen saver. .
---- On the screen of this page, there is a monitor pattern. If you choose the screen saver that comes with win95, the screen saver will automatically run on this small 'monitor', and you can directly see the running effect. . This function greatly facilitates the selection of screen savers. This is the new interface of win95 for screen savers: preview function.
---- Most of the newly launched screen savers currently support this interface.
---- Since its birth, only one screen saver can be run at the same time, and multiple screens cannot be run at the same time. However, the introduction of the preview interface has made it possible to preview multiple screen savers at the same time. This article will show readers Introduce how to develop such a program using Delphi.
---- 1. Screen saver preview interface
---- The screen saver preview interface is very simple to use. This is achieved by passing the command line parameters to the screen saver. The command line parameter format is:
---- screensaver.exe /p #####
---- Where ##### is the decimal representation of a valid window handle.
---- We can call this window the preview window.
----In fact, screensavers that support the preview interface create their own windows as sub-windows of the preview window to implement the preview function.
---- 2. Screen layout
---- The window of our program is divided into 3 parts, which are in the shape of an inverted 'pin'. The upper left part lists all available screensavers, the upper right part lists all previewed screensavers, and the bottom part is of course the preview window. .
---- When implemented with Delphi, first put two TPanel components in the Form, Panel1 is aligned to the top, Panel2 is to fill the user area, then put a TFileListBox component and a TListBox component in Panel1, FileListBox1 is left aligned , ListBox1 fills up the user area.
---- In this way, FileListBox1 is the screen saver list, ListBox1 is the preview list, and Panel2 is the preview window.
---- 3. List screen savers.
---- Set the Mask property of FileListBox1 to '*.scr', which is the extension of the screen saver.
---- Set FileListBox1.directory to the windows system directory GetSystemDirectory in the FormCreate method;
---- 4. Preview screen saver.
----Run the screensaver in the FileListBox1DblClick method and pass it the window handle of Panel2.
---- WinExec(pchar(FileListBox1.FileName + ' /p ' + inttostr(Panel2.handle)), SW_Show);
---- How about running the program? COOL!
---- 5. Add some new features: hide/show/close.
----Added 2 functions: used to update ListBox1.
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;
---- Add a pop-up menu Popupmenu1, 3 menu items, 'Show, Hide, Close', and point ListBox1.popupmemu to Popupmenu1.
----The processing function of Hide is:
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;
The handler function for Show is:
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;
The handler function for Close is:
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;
---- This program has been debugged under Delphi 3.0 and should be able to be compiled with Delphi 1.0 / 2.0.
----The complete procedure is as follows:
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;
end;
procedure TForm1.FileListBox1DblClick(Sender: TObject);
begin
WinExec(pchar(FileListBox1.FileName + ' /p ' + inttostr(Panel2.handle)), SW_Show);
Fresh1;
end;
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;
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;
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;
end.
Copyright © Shanghai Jusheng Computer System Engineering Co., Ltd. 1999-2000, All Rights Reserved