Uses ShlObj, ComObj;
Procedure 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;
SetWallPaper('c:/xxx.jpg', 1);