借用资源做屏保

来源:转载

因需要做个屏保,让其每天运行不同的内容。。

两个方案:1. 自己动手写一个,优点:方便  缺点:图片变幻单调。

              2. 利用专业屏保软件生成的 .scr文件(附:梦想之巅屏保制作V3.1破解版主程序(下载后覆盖原主程序文件即可)http://files.cnblogs.com/boltwolf/%E6%A2%A6%E6%83%B3%E4%B9%8B%E5%B7%85%E5%B1%8F%E4%BF%9D%E5%88%B6%E4%BD%9CV3.1%E7%A0%B4%E8%A7%A3%E7%89%88%E4%B8%BB%E7%A8%8B%E5%BA%8F.rar),我们只要在自己的程序里调用它就OK!

结果:方案1很快完成了。可参见:http://www.cnblogs.com/boltwolf/archive/2011/06/07/2074443.html

        做方案2时,却总失败(如果屏保退出时窗体不自动关闭会影响到视觉美观,经历了多次试验后,总算完成了一个,初步解决思路:通过一个计时器,不断查找屏保窗口(经测试,我所生成的屏保程序窗口标题有“屏幕保护”几个字),如果找不到,则退出)

代码如下:

//工程文件program ScrSaveHDDS;uses SysUtils, Windows, Forms, ShellApi, Unit1 in 'Unit1.pas' {Form1};{$R *.res}var i : integer; buf : array[0..MAX_PATH] of char; filepath: string;begin Application.Initialize; //取得系统目录路径 GetSystemDirectory(buf,Length(buf)); //要调用屏保文件的路径 i := DayofWeek(Date()); Case i of 1,2: filepath := buf + '/Hdds/monday.scr'; 3: filepath := buf + '/Hdds/tuesday.scr'; 4: filepath := buf +'/Hdds/wednesday.scr'; 5: filepath := buf + '/Hdds/thursday.scr'; 6,7: filepath := buf+'/Hdds/friday.scr'; end; Application.Title := '横店屏保二'; ShellExecute(Application.handle, 'open', Pchar(filepath), nil, nil, SW_SHOWMAXIMIZED); Application.CreateForm(TForm1, Form1); Application.Run;end.//单元文件unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;type TForm1 = class(TForm) Timer1: TTimer; Label1: TLabel; Edit1: TEdit; ListBox1: TListBox; procedure FormCreate(Sender: TObject); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}var bExit: Boolean = True;procedure TForm1.FormCreate(Sender: TObject);begin WindowState := wsMiniMized;end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin close;end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin close;end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin close;end;procedure TForm1.Timer1Timer(Sender: TObject);var h1 : HWND; stitle: array[Byte] of Char;begin //查找屏保窗口 h1 := GetWindow(handle, GW_HWNDFIRST); while h1 <> 0 do begin GetWindowText(h1, stitle, Length(stitle)); if Pos('屏幕保护', stitle) > 0 then begin
 //测试用 // ListBox1.Items.Add(InttoStr(h1) + stitle); bExit := False; break; end; h1 := GetWindow(h1, GW_HWNDNEXT); end; //如果发现真正的屏保程序已退出,则退出本调用程序 if bExit then close; //重置判断标志 bExit := True;end;end.//窗体代码object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 243 ClientWidth = 383 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate OnKeyDown = FormKeyDown OnMouseDown = FormMouseDown OnMouseMove = FormMouseMove PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 24 Top = 16 Width = 169 Height = 17 AutoSize = False Caption = 'Label1' end object Edit1: TEdit Left = 8 Top = 39 Width = 121 Height = 21 ImeName = #20013#25991' ('#31616#20307') - '#19975#33021#20116#31508#20869#32622#36755#20837#27861 TabOrder = 0 Text = 'Edit1' end object ListBox1: TListBox Left = 8 Top = 72 Width = 209 Height = 163 ImeName = #20013#25991' ('#31616#20307') - '#19975#33021#20116#31508#20869#32622#36755#20837#27861 ItemHeight = 13 TabOrder = 1 end object Timer1: TTimer OnTimer = Timer1Timer Left = 304 Top = 160 endend


分享给朋友:
您可能感兴趣的文章:
随机阅读: