在windows95/98中,都是使用注册表对系统数据进行管理,有关壁纸的设置数据保存在hkey_current_user\control panel\desktop的wallpaper和tilewallpaper 等键值中,只要成功修改了这两个键值,然后发消息给windows即可更换壁纸。 在本例的程序中,使用了一个tform;两个tspeedbutton(speedbutton1用于接受用户的浏览命令,speedbutton2用于接受用户的更换壁纸命令);一个timage(用于显示图片)。另外,还用到一组文件控件:tfilelistbox,tdrivecombobox,tdirectorylistbox,用于选择图片文件,可以设置filelistbox的mask属性,筛选显示在filelistbox 中的文件类型(如只显示.bmp文件)。下面的两个程序段是实现浏览图片和更换壁纸的关键代码。
procedure tform1.speedbutton1click(sender:tobject);
begin
if (filelistbox1.filename=
′′) then {判断filelistbox1中文件有没有被选中}
messagedlg(′请先选择一幅位图′,mtinformation,[mbok],0)
else
image1.picture.loadformfile(filelistbox1.filename);{加载图片文件并显示}
end;
proceduretform1.speedbutton2click(sender:tobject);
var
reg:tregistry;{tregistry 对象在registry 单元中声明,需用uses令引用registry单元}
}
begin
if (filelistbox1.filename=′′) then
messagedlg(′请先选择一幅位图′,mtinformation,[mbok],0)
else
begin
reg:=tregistry.create;{创建tregistry对象的实例}
reg.rootkey:= hkey_current_user;{设置根键名称}
reg.openkey′control panel\desktop′,false); {打开control panel\desktop 路径对应的主键}
reg.writestring (′tilewallpaper′,
′0′);
reg.writestring
′wallpaper′,fileli
stbox1.filename);{向tilewallpaper 和wallpaper串覆盖写入新值}
systemparametersinfo(spi_setdeskwallpaper,0,nil,spif_sendchange);{向windows发送消息,通知windows更换壁纸}
reg.closekey;{将更改内容写入注册表并关闭}
reg.free;{释放对象}
end;
end;
代码中用到的一些函数可以察看delphi的联机帮助。需要注意的是:调用打开子键的函数openkey时,第二个参数一定要设为false。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器