关于桌面图片(50分)

  • 主题发起人 主题发起人 lovemimi
  • 开始时间 开始时间
L

lovemimi

Unregistered / Unconfirmed
GUEST, unregistred user!
如何点一下按钮就可以把桌面的图片换成程序中指定的一幅图片?<br>我想应该很简单的把。如果只是几个函数,希望大家直接给出。<br>如果比较复杂,希望大家提示一下我应该看看关于那方面的资料,<br>我对此一无所知,全靠大家领进门
 
I am waiting for answer!<br>It's not difficult!
 
procedure ChangeWallPaper(BmpFile: String);<br>//更改墙纸<br>var<br>&nbsp; Reg: TRegistry;<br>begin<br>&nbsp; &nbsp;Reg:=TRegistry.Create;<br>&nbsp; &nbsp;Reg.RootKey:=Hkey_Current_User;<br>&nbsp; &nbsp;Reg.OpenKey('Control Panel/Desktop', False);<br>&nbsp; &nbsp;Reg.WriteString('Wallpaper', BmpFile);<br>&nbsp; &nbsp;Reg.WriteString('TileWallpaper', '1'); //( 1-平铺 0-居中 2-拉伸)<br>&nbsp; &nbsp;SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, nil, SPIF_UPDATEINIFILE);<br>&nbsp; &nbsp;SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETDESKWALLPAPER, 0);<br>&nbsp; &nbsp;Reg.CloseKey;<br>&nbsp; &nbsp;Reg.Free;<br>end;
 
如果打开了ACTIVE DESKTOP,以上方法无效<br>应该用:(别忘了引用ComObj, ShlObj俩单元)<br>procedure SetActiveWallpaper(Filename: String; Display:TDisplay);<br>var<br>&nbsp; ADesk: IActiveDesktop;<br>&nbsp; Pwpo: TWallpaperOpt;<br>&nbsp; Wallpaper: WideString;<br>begin<br>&nbsp; ADesk := CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;<br>&nbsp; try<br>&nbsp; &nbsp; Pwpo.dwStyle := WPSTYLE_CENTER; //居中<br>&nbsp; &nbsp; //Pwpo.dwStyle := WPSTYLE_TILE; {平铺}<br>&nbsp; &nbsp; //Pwpo.dwStyle := WPSTYLE_STRETCH; {拉伸}<br>&nbsp; &nbsp; Pwpo.dwSize := sizeOf(Pwpo);<br>&nbsp; &nbsp; ADesk.SetWallpaperOptions(Pwpo,0);<br>&nbsp; &nbsp; Wallpaper := WideString(Filename);<br>&nbsp; &nbsp; ADesk.SetWallpaper(PWideChar(Wallpaper), 0);<br>&nbsp; &nbsp; ADesk.ApplyChanges(AD_APPLY_ALL);<br>&nbsp; finally<br>&nbsp; &nbsp; ADesk := nil<br>&nbsp; end;<br>end;
 
不好意思,打错了,上面那个函数头应该是<br>procedure SetActiveWallpaper(Filename: String);<br>多打了个参数。
 
谢谢,问题已经基本解决了
 
后退
顶部