实现壁纸更换的示范代码
来源:互联网 发布:出国留学用哪种gpa算法 编辑:程序博客网 时间:2024/04/23 23:18
通过 DELPHi 编程方式实现更换 Windows 桌面背景的方法。陆岛工作室为本示范提供了一个详细完整的函数,可以直接在DELPHI 下调用该函数实现更换 Windows 桌面背景。
函数代码如下:
type
TWallpaperStyle = (wsTitle, wsCenter, wsStretch); //平铺, 居中, 拉伸
function ChangeWindowsDesktopWallPaper(WallFileName: string; WallpaperStyle: TWallpaperStyle; UpdateNow: Boolean=True): Boolean;
function SaveWallpaperFile: String;
var
Dir: PChar;
Pt: TPoint;
AWallpaper, APicture: TPicture;
begin
APicture := TPicture.Create;
Result := '';
try
APicture.LoadFromFile(WallFileName);
except
on E: Exception do
begin
Result := '';
APicture.Free;
//ShowMessage(E.Message);
Exit;
end;
end;
GetMem(Dir, 255);
GetWindowsDirectory(Dir, 255);
Result := Dir+ '/Wallpaper demo.bmp';
FreeMem(Dir);
AWallpaper := TPicture.Create;
try
with AWallpaper.Bitmap do
begin
Width := APicture.Width;
Height := APicture.Height;
Canvas.StretchDraw(Canvas.ClipRect, APicture.Graphic);
end;
AWallpaper.SaveToFile(Result);
finally
APicture.Free;
AWallpaper.Free;
end;
end;
var
AFileName: string;
RegFile: TRegIniFile;
begin
//将文件保存为 BMP 格式,并转移到 Windows 的目录下. 保存成功将返回文件, 否则文件为空.
AFileName := SaveWallpaperFile;
Result := FileExists(WallFileName);
if Result then
begin
RegFile := TRegIniFile.Create;
RegFile.RootKey := HKEY_CURRENT_USER;
RegFile.OpenKey('Control Panel/Desktop', True);
{ 更改主键 DeskTop 下的两个键值, 设置桌面图片显示方式
平铺选项:TileWallpaper=True;WallpaperStyle=0;
居中选项:TileWallpaper=False ;WallpaperStyle=0
拉伸选项:TileWallpaper=False ;WallpaperStyle=2 }
case WallpaperStyle of
wsTitle:
begin
RegFile.WriteBool('', 'TileWallpaper', True);
RegFile.WriteInteger('','WallpaperStyle', 0);
end;
wsCenter:
begin
RegFile.WriteBool('', 'TileWallpaper', False);
RegFile.WriteInteger('','WallpaperStyle', 0);
end;
wsStretch:
begin
RegFile.WriteBool('', 'TileWallpaper', False);
RegFile.WriteInteger('','WallpaperStyle', 2);
end;
end;
RegFile.WriteString('', 'Wallpaper', AFileName);
RegFile.Free;
if UpdateNow then //立即更新桌面显示
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, nil, SPIF_SENDWININICHANGE);
end;
end;
TWallpaperStyle = (wsTitle, wsCenter, wsStretch); //平铺, 居中, 拉伸
function ChangeWindowsDesktopWallPaper(WallFileName: string; WallpaperStyle: TWallpaperStyle; UpdateNow: Boolean=True): Boolean;
function SaveWallpaperFile: String;
var
Dir: PChar;
Pt: TPoint;
AWallpaper, APicture: TPicture;
begin
APicture := TPicture.Create;
Result := '';
try
APicture.LoadFromFile(WallFileName);
except
on E: Exception do
begin
Result := '';
APicture.Free;
//ShowMessage(E.Message);
Exit;
end;
end;
GetMem(Dir, 255);
GetWindowsDirectory(Dir, 255);
Result := Dir+ '/Wallpaper demo.bmp';
FreeMem(Dir);
AWallpaper := TPicture.Create;
try
with AWallpaper.Bitmap do
begin
Width := APicture.Width;
Height := APicture.Height;
Canvas.StretchDraw(Canvas.ClipRect, APicture.Graphic);
end;
AWallpaper.SaveToFile(Result);
finally
APicture.Free;
AWallpaper.Free;
end;
end;
var
AFileName: string;
RegFile: TRegIniFile;
begin
//将文件保存为 BMP 格式,并转移到 Windows 的目录下. 保存成功将返回文件, 否则文件为空.
AFileName := SaveWallpaperFile;
Result := FileExists(WallFileName);
if Result then
begin
RegFile := TRegIniFile.Create;
RegFile.RootKey := HKEY_CURRENT_USER;
RegFile.OpenKey('Control Panel/Desktop', True);
{ 更改主键 DeskTop 下的两个键值, 设置桌面图片显示方式
平铺选项:TileWallpaper=True;WallpaperStyle=0;
居中选项:TileWallpaper=False ;WallpaperStyle=0
拉伸选项:TileWallpaper=False ;WallpaperStyle=2 }
case WallpaperStyle of
wsTitle:
begin
RegFile.WriteBool('', 'TileWallpaper', True);
RegFile.WriteInteger('','WallpaperStyle', 0);
end;
wsCenter:
begin
RegFile.WriteBool('', 'TileWallpaper', False);
RegFile.WriteInteger('','WallpaperStyle', 0);
end;
wsStretch:
begin
RegFile.WriteBool('', 'TileWallpaper', False);
RegFile.WriteInteger('','WallpaperStyle', 2);
end;
end;
RegFile.WriteString('', 'Wallpaper', AFileName);
RegFile.Free;
if UpdateNow then //立即更新桌面显示
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, nil, SPIF_SENDWININICHANGE);
end;
end;
调用方法如下:
var
AWallpaperFile: string;
begin
AWallpaperFile := 'D:/Backup/我的文档/My Pictures/xxxx.bmp'; //文件名自己定义
ChangeWindowsDesktopWallPaper(AWallpaperFile, wsCenter, True); //wsCenter 或以指定为其他方式 wsTitle, wsStretch 等。
end;
AWallpaperFile: string;
begin
AWallpaperFile := 'D:/Backup/我的文档/My Pictures/xxxx.bmp'; //文件名自己定义
ChangeWindowsDesktopWallPaper(AWallpaperFile, wsCenter, True); //wsCenter 或以指定为其他方式 wsTitle, wsStretch 等。
end;
- 实现壁纸更换的示范代码
- Android 更换壁纸 代码
- 简易的壁纸更换
- 自动更换壁纸vb代码
- service实现自动更换壁纸
- 用python实现下载必应壁纸并自动更换壁纸的功能
- lucene的代码示范
- C#制作的更换壁纸程序
- C#编写的壁纸更换程序
- 关于自动更换xp桌面的壁纸。
- 我的Android进阶之旅------>Android使用AlarmManager全局定时器实现定时更换壁纸
- 我的Android进阶之旅------>Android使用AlarmManager全局定时器实现定时更换壁纸,androidalarmmanager
- 简单的数据库连接代码示范!!
- Android使用AlarmManager全局定时器实现定时更换壁纸
- 如何更换wince壁纸?
- 如何更换wince壁纸?
- 项目:自动更换壁纸
- windows更换壁纸脚本
- Window.ShowModalDialog使用详解
- JS获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度
- select 1 from 浅析
- OGREFont的研究与OGRE的中文显示(三)小插曲
- C++好书 推荐 努力在大学里在多看几本书
- 实现壁纸更换的示范代码
- AT91RM9200引导程序的建立(一)--------建立交叉编译工具链
- CreateWindow返回Handle失败
- sp_help
- 主键与外键的问题
- 实现执行外部程序,并等待程序结束的函数。
- 个人真实FireFox体验
- Javascript跨域访问解决方案
- SQL2K5数据库日志