请大家看看这个程序? (20分)

  • 主题发起人 topsuper
  • 开始时间
T

topsuper

Unregistered / Unconfirmed
GUEST, unregistred user!
一个老问题了,希望大家不要烦!!!
这是一个根据命令行参数换壁纸的程序,可是运行后却不能立即更新必须‘注销’以后在可以
请问:有什么办法使的设置的壁纸立即生效,请!!

program PR_param;
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs, StdCtrls,Registry,ComObj, ShlObj,ActiveX;
var
ADeskTop:IActiveDesktop;
wallpaper:pwideChar;
lph: HKEY;
X: DWORD;
r:string;
Reg:Tregistry;{Tregistry 对象在Registry 单元中声明,需用Uses令引用Registry单元}
begin
CoInitialize(nil);
X:=1;

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',paramstr(1));{向TileWallpaper 和Wallpaper串覆盖写入新值}
//Systemparametersinfo(SPI_SETDESKWallpaper,0,pchar(paramstr(1)),SPIF_UPDATEINIFILE);{向Windows发送消息,通知Windows更换壁纸}
//SystemParametersInfo(SPI_SETDESKWALLPAPER,0,paramstr(1),SPIF_UPDATEINIFILE);

Reg.CloseKey;{将更改内容写入注册表并关闭}
Reg.Free;{释放对象}

RegOpenKey(HKEY_CURRENT_USER, 'Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', lph);
RegSetValueEx(lph, 'ForceActiveDesktopOn', 0, REG_DWORD, @X, SizeOf(DWORD));
ADeskTop:=CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
wallpaper:=pwidechar(paramstr(1));
ADeskTop.SetWallpaper(wallpaper,1);
ADeskTop.ApplyChanges(AD_APPLY_ALL);
closefile(file1);
systemparametersinfo(SPI_SETDESKWALLPAPER ,0,pchar(paramstr(1)),SPIF_UPDATEINIFILE );
end.
 
SystemParametersInfo(SPI_SETDESKWALLPAPER,0,nil,SPIF_SENDWININICHANGE);
用上这句。
 
按照你的方法做了,还是不行呀!
为什么呀?还有其他方法吗?
上诉方法在win98,win2000好象都不行。
 
我为这里完全可以,也没有你那复杂。
var
PicStation:string;

procedure TForm1.setDesktopPic(PicName:string);
var
a,b:string;
Ini: TregIniFile;
begin
if PicStation=1 then begin a:='0';b:='0';end; //居中
if PicStation=2 then begin a:='1';b:='0';end; //平铺
if PicStation=3 then begin a:='0';b:='2';end; //拉伸
Ini := TRegIniFile.Create('Control Panel');
Ini.WriteString('desktop', 'TileWallpaper', a);
Ini.WriteString('desktop', 'WallpaperStyle', b);
Ini.WriteString('desktop', 'Wallpaper', PicName);
if PicStation=0 then begin //无壁纸
Ini.WriteString('desktop', 'TileWallpaper', '0');
Ini.WriteString('desktop', 'WallpaperStyle', '0');
Ini.WriteString('desktop', 'Wallpaper', '');
end;
Ini.Free;
SystemParametersInfo(SPI_SETDESKWALLPAPER,0,nil,SPIF_SENDWININICHANGE);
end;
 
这些你都试过吗?
不行的!!!!!!!
你自己试一试把?
 
上述方法对BMP文件是可以的,对其他类型的图片不能立即改变。
 

Similar threads

顶部