Chinaunix首页 | 论坛 | 博客
  • 博客访问: 841828
  • 博文数量: 372
  • 博客积分: 10063
  • 博客等级: 中将
  • 技术积分: 4220
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 11:36
文章分类

全部博文(372)

文章存档

2012年(372)

分类: 虚拟化

2012-04-15 21:32:57

///


/// 通知Windows改变墙纸
///

/// 墙纸图片路径

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;

///


/// 用指定的方式改变墙纸
///

/// 墙纸图片文件
/// 样式

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;

阅读(713) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~