更换墙纸

/// <summary>
/// 通知Windows改变墙纸
/// </summary>
/// <param name="strFile">墙纸图片路径</param>

procedure TfrmPara.SetRegWallPaper(strFile: string);

var
  reg : TRegistry;
begin
  reg := TRegistry.Create;
  reg.RootKey := HKEY_CURRENT_USER;
  try
    if reg.OpenKey('Control Panel\Desktop', False) then
    begin
      reg.WriteString('TileWallpaper', '0');
      reg.WriteString('WallpaperStyle', '2');
      reg.WriteString('Wallpaper', strFile);
      reg.WriteString('ConvertedWallpaper', strFile);
      reg.WriteString('OriginalWallpaper', strFile);
      reg.CloseKey;
      // 向Windows发送消息, 通知Windows更换墙纸
      SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(strFile), SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);
    end;
  finally
    reg.Free;
  end;
end;

/// <summary>
/// 用指定的方式改变墙纸
/// </summary>
/// <param name="strFile">墙纸图片文件</param>
/// <param name="style">样式</param>

procedure TfrmPara.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; //拉伸
    3 : wpo.dwStyle := WPSTYLE_KEEPASPECT; //Win7
    4 : wpo.dwStyle := WPSTYLE_CROPTOFIT; //Win7
  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;

转载于:https://www.cnblogs.com/hp243/archive/2012/04/15/2450564.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值