设置Windows墙纸

需引用ComObj, ShlObj单元

procedure SetActiveWallpaper(Filename: String);
var
  ADesk: IActiveDesktop;
  Pwpo: TWallpaperOpt;
  Wallpaper: WideString;
begin
  ADesk := CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
  try
    //Pwpo.dwStyle := WPSTYLE_CENTER; //居中
    //Pwpo.dwStyle := WPSTYLE_TILE; {平铺}
    Pwpo.dwStyle := WPSTYLE_STRETCH; {拉伸}
    Pwpo.dwSize := sizeOf(Pwpo);
    ADesk.SetWallpaperOptions(Pwpo,0);
    Wallpaper := WideString(Filename);
    ADesk.SetWallpaper(PWideChar(Wallpaper), 0);
    ADesk.ApplyChanges(AD_APPLY_ALL);
  finally
    ADesk := nil
  end;
end; 

你可能感兴趣的:(设置Windows墙纸)