用SystemParametersInfo好像只能设置BMP格式的壁纸,于是我尝试使用IActiveDesktop接口,代码片段如下:var
  Dk : IActiveDesktop;
begin
  Dk:= CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
  if SUCCEEDED(Dk.SetWallpaper(FileName), 0)) then
    ShowMessage('OK!');
  Dk.ApplyChanges(AD_APPLY_SAVE or AD_APPLY_REFRESH);
  Dk:= nil;
end;可是运行过后系统壁纸没有变化,但是的确是返回了S_OK,而且壁纸列表中的壁纸也没有变,请问是怎么回事呢

解决方案 »

  1.   

    你得在“显示属性”中的“WEB”页中的
    按WEB页方式查看活动桌面
    打上勾就OK了
      

  2.   

    呵呵,你说的好像还是98吧?我只是想知道Windows系统自己的更改壁纸的代码是怎么实现的。我发现设置了JPG的壁纸,其实系统还是把它解码成BMP放在一个临时目录里面的
      

  3.   

    uses ShlObj, ComObj;procedure SetWallpaper(WallpaperPath: String);
    const
      CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
    var
      ActiveDesktop: IActiveDesktop;
      ComponentsOpt: TComponentsOpt;
      WStr : PWideChar;
    begin
      WStr := AllocMem(MAX_PATH);
      try
        StringToWideChar(WallpaperPath, WStr, MAX_PATH);
        ActiveDesktop := CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
        ComponentsOpt.dwSize := sizeOf(ComponentsOpt);
        ActiveDesktop.GetDesktopItemOptions(ComponentsOpt,0);
        ComponentsOpt.fActiveDesktop := true;      //啟動ActiveDesktop
        ActiveDesktop.SetDesktopItemOptions(ComponentsOpt,0);
        ActiveDesktop.SetWallpaper(WStr, 0);
        ActiveDesktop.ApplyChanges(AD_APPLY_ALL);   //儲存設定
      finally
        FreeMem(wstr);
      end;
    end;