怎样设置墙纸(50分)

刘邦

Unregistered / Unconfirmed
GUEST, unregistred user!
各位请看我的代码,为什么设置墙纸后不能马上显示,必须注销后才能显示,我用的系统是win2000。
procedure TFormReader1.N30Click(Sender: TObject);
var Registry: TRegistry;
begin
// 设置墙纸的属性
Registry := TRegistry.Create;
try
if Registry.OpenKey('Control Panel/DeskTop', false) then
begin
Registry.WriteString('TileWallPaper', '2'); // 平铺方式,TileWallPaper为1
Registry.WriteString('WallPaperStyle', '0'); // 非拉伸方式,WallPaperStyle为0
Registry.WriteString('WallPaper', fileListBox1.FileName); // 墙纸文件的路径″C:/A.BMP″
end;
Registry.CloseKey;
finally
Registry.Free;
end;
//广播注册表改动的消息
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pChar(fileListBox1.FileName), SPIF_SENDCHANGE);
end;
 
Uses ShlObj, ComObj;

Procedure TForm1.SetWallPaper(StrFile: String; Style: Integer);
Var DT: IActiveDesktop;
WPO: TWallpaperOpt;
WS: WideString;
Begin
DT := CreateComObject(CLSID_ActiveDesktop) As IActiveDesktop;
WS := StrFile;
Case Style Of
0: WPO.dwStyle := WPSTYLE_CENTER; {居中}
1: WPO.dwStyle := WPSTYLE_TILE; {平铺}
2: WPO.dwStyle := WPSTYLE_STRETCH; {拉伸}
Else WPO.dwStyle := WPSTYLE_CENTER;
End;
WPO.dwSize := SizeOf(WPO);
DT.SetWallpaperOptions(WPO, 0);
DT.SetWallPaper(PwideChar(WS), 0);
DT.ApplyChanges(AD_APPLY_ALL);
End;
 
感谢指点,接受了!
 

Similar threads

I
回复
0
查看
479
import
I
I
回复
0
查看
540
import
I
I
回复
0
查看
403
import
I
顶部