我在用
Systemparametersinfo(SPI_SETDESKWallpaper,0,nil,SPIF_SendChange)设置桌面壁纸时,只能在开机后第一次使用后,再右键桌面‘刷新’才会更改壁纸,以后再用该方法改变壁纸后,只能在桌面属性里看到壁纸文件更改了,但桌面并无变化,无论怎样刷新都没有用。请问这是为什么?

解决方案 »

  1.   

    You may have noticed that using SystemParametersInfo to change the wallpaper 
      when ActiveDesktop is turned on doesn't work. The reason is because you need 
      to use the IActiveDesktop COM interface. Using SystemParametersInfo still works, 
      but it doesn't update the wallpaper. 
      Requires Internet Explorer 4.0 or later). 
    } uses 
      ShlObj, ComObj; 
    function ChangeWallpaper(aFile: String): Boolean; 
    const 
      CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}'; 
    var 
      hObj: IUnknown; 
      ADesktop: IActiveDesktop; 
      str: string; 
      wstr: PWideChar; 
    begin 
      hObj     := CreateComObject(CLSID_ActiveDesktop); 
      ADesktop := hObj as IActiveDesktop; 
      wstr := AllocMem(MAX_PATH); 
      try 
        StringToWideChar(aFile, wstr, MAX_PATH); 
        ADesktop.SetWallpaper(wstr, 0); 
        ADesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE); 
      finally 
        FreeMem(wstr); 
      end; 
    end; 
    **************************************
    活动桌面下更换墙纸:
    uses shlobj;
    获得墙纸 
    procedure TForm1.Button1Click(Sender: TObject); 
    var 
    ADeskTop:IActiveDesktop; 
    wallpaper:PwideChar; 
    begin 
    ADeskTop:=CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop; 
    GetMem(wallpaper,128); 
    ADeskTop.GetWallpaper(wallpaper,128,0); 
    ShowMessage(string(wallpaper)); 
    FreeMem(wallpaper); 
    end; 
    设置墙纸 
    procedure TForm1.Button1Click(Sender: TObject); 
    var 
    ADeskTop:IActiveDesktop; 
    wallpaper:PwideChar; 
    begin 
    ADeskTop:=CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop; 
    wallpaper:='d:\2.bmp'; 
    ADeskTop.SetWallpaper(wallpaper,0); 
    ADeskTop.ApplyChanges(AD_APPLY_ALL); 
    end;