unit wallpaper;interfaceuses Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms, Dialogs,Math,StrUtils,ShlObj,ComObj,RegWrap,RTLTide,WinWrap, bit;procedure SetWallpaper(fn:string);//仅bmpprocedure SetActiveWallpaper(fn:string;dwStyle:Integer);implementationprocedure SetWallpaper(fn:string);begin SystemParametersInfo(SPI_SETDESKWALLPAPER,0,PChar(fn),SPIF_UPDATEINIFILE);end;procedure SetActiveWallpaper(fn:string;dwStyle:Integer);//JPG等格式需要启用ActiveDesktop// WPSTYLE_CENTER居中 WPSTYLE_TILE;平铺 WPSTYLE_STRETCH拉伸var t:TShellFlagState; ADesk:IActiveDesktop; Pwpo:TWallpaperOpt; Wallpaper:WideString;begin ADesk:=CreateComObject(CLSID_ActiveDesktop)as IActiveDesktop; try t:=ShellSet(SSF_DESKTOPHTML); if GetBit(t,7)=1 then begin Pwpo.dwStyle:=dwStyle; Pwpo.dwSize:=sizeOf(Pwpo); ADesk.SetWallpaperOptions(Pwpo,0); Wallpaper:=WideString(fn); ADesk.SetWallpaper(PWideChar(Wallpaper),0); ADesk.ApplyChanges(AD_APPLY_ALL); end; finally ADesk:=nil end;end;end.