我想将C:\picture001.bmp作桌面, 如下是程序段,在win98中可以实现﹐但在win2k中不能,不知如何改善….thks!desk:='c:\picture001.bmp';
Reg.Rootkey:= Hkey_Current_User;
Reg.OpenKey('Control Panel\Desktop',False); Reg.WriteString ('TileWallPaper','0');
Reg.WriteString('Wallpaper',desk);
reg.WriteString('wallpaperstyle','0');
Systemparametersinfo(SPI_SETDESKWallpaper,0,Nil,SPIF_SendChange); Reg.CloseKey;
Reg.Free
Reg.Rootkey:= Hkey_Current_User;
Reg.OpenKey('Control Panel\Desktop',False); Reg.WriteString ('TileWallPaper','0');
Reg.WriteString('Wallpaper',desk);
reg.WriteString('wallpaperstyle','0');
Systemparametersinfo(SPI_SETDESKWallpaper,0,Nil,SPIF_SendChange); Reg.CloseKey;
Reg.Free
解决方案 »
- KsDhtmlEdit控件的使用问题,在线等。顶帖者都有分…………………………………………!!!
- 将数据流中保存的图片载入image控件时遇到的问题,请各位指点,谢谢!!
- 急,高手赐教-在网页中打开PDF文档,能不能写个ActiveX控件屏蔽掉Acrobat的快捷键
- 一个得到整数的功能代码,急,大家帮帮忙,应该很简单的,希望高手给出代码,1:00就要用了,大家救我啊
- 开除我女秘书的真正原因
- 请教各位,如何控制局域网内的一台客户端关机????
- 请问为什么有的表项在DBGrid上面不能显示,即使明确给出表项也不行?
- 如何获得机器的硬盘序列号?
- PaintBox的错误!(100分)
- 网络销售主管是做什么工作的
- ToolBar怎样设置Width,就像Delphi主界面的主菜单行
- 有关DCOMConnection设置的问题,在线等待
Function SetWallPaper(sWallPaperBMPPath:string):Boolean;
begin
Result :=SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(sWallPaperBMPPath),SPIF_UPDATEINIFILE);
end;
//----------------------------------------------------------[ SetWallpaper ]---
{ 换壁纸核心代码 }
procedure TMainForm.SetWallpaper(FileIndex: Integer);
var
ADeskTop: IActiveDesktop;
tempWideStr: WideString;
wallpaper: PwideChar;
tempImage: TImage;
Error: Boolean;
begin
Error := False;
tempWideStr := FileMemo.Lines.Strings[FileINdex];
tempImage := TImage.Create(nil);
try
tempImage.Picture.LoadFromFile(FileMemo.Lines.Strings[FileINdex]);
except
Error := True;
end;
tempImage.Free;
if Not Error then
begin
ADeskTop := CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
wallpaper := PwideChar(tempWideStr);
ADeskTop.SetWallpaper(wallpaper,0);
ADeskTop.ApplyChanges(AD_APPLY_ALL);
end;
end; {SetWallpaper}
var THEPCHAR:pchar;
begin
THEPCHAR:='e:\a.bmp';
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, THEPCHAR, SPIF_SENDWININICHANGE)
end;用Delphi实现壁纸更换
在Windows95/98中,都是使用注册表对系统数据进行管理,有关壁纸的设置数据保存在Hkey_Current_User\Control Panel\Desktop的Wallpaper和TileWallpaper 等键值中,只要成功修改了这两个键值,然后发消息给Windows即可更换壁纸。在本例的程序中,使用了一个Tform;两个Tspeedbutton(Speedbutton1用于接受用户的浏览命令,Speedbutton2用于接受用户的更换壁纸命令);一个Timage(用于显示图片)。另外,还用到一组文件控件:Tfilelistbox,Tdrivecombobox,Tdirectorylistbox,用于选择图片文件,可以设置FileListBox的mask属性,筛选显示在FileListBox 中的文件类型(如只显示.bmp文件)。下面的两个程序段是实现浏览图片和更换壁纸的关键代码。
Procedure Tform1.SpeedButton1Click(Sender:Tobject);
Begin
If (filelistbox1.FileName=
′′) Then {判断Filelistbox1中文件有没有被选中}
Messagedlg(′请先选择一幅位图′,mtInformation,[mbOK],0)
Else
Image1.Picture.LoadFormFile(Filelistbox1.FileName);{加载图片文件并显示}
End;
ProcedureTform1.SpeedButton2Click(Sender:TObject);
Var
Reg:Tregistry;{Tregistry 对象在Registry 单元中声明,需用Uses令引用Registry单元}
}
Begin
If (Filelistbox1.FileName=′′) Then
Messagedlg(′请先选择一幅位图′,mtinformation,[mbOK],0)
Else
Begin
Reg:=Tregistry.Create;{创建Tregistry对象的实例}
Reg.Rootkey:= Hkey_Current_User;{设置根键名称}
Reg.OpenKey′Control Panel\Desktop′,False); {打开Control Panel\Desktop 路径对应的主键}
Reg.WriteString (′TileWallPaper′,
′0′);
Reg.WriteString
′Wallpaper′,fileli
stbox1.FileName);{向TileWallpaper 和Wallpaper串覆盖写入新值}
Systemparametersinfo(SPI_SETDESKWallpaper,0,Nil,SPIF_SendChange);{向Windows发送消息,通知Windows更换壁纸}
Reg.CloseKey;{将更改内容写入注册表并关闭}
Reg.Free;{释放对象}
End;
End;
代码中用到的一些函数可以察看Delphi的联机帮助。需要注意的是:调用打开子键的函数OpenKey时,第二个参数一定要设为False。
(请作者速与本报联系) 本文出自:《电脑报》1999年03月22日第11期
//////////////////////////////////////
增强的版本
uses
Registry, WinProcs, SysUtils;const
// WallPaperStyles
WPS_Tile = 0;
WPS_Center = 1;
WPS_SizeToFit = 2;
WPS_XY = 3;//
// sWallpaperBMPPath
// - path to a BMP file
//
// nStyle
// - any of the above WallPaperStyles
//
// nX, nY
// - if the nStyle is set to WPS_XY,
// nX and nY can be used to set the
// exact position of the wall paper
//
procedure SetWallpaperExt(
sWallpaperBMPPath : string;
nStyle,
nX, nY : integer );
var
reg : TRegIniFile;
s1 : string;
X, Y : integer;
begin
//
// change registry
//
// HKEY_CURRENT_USER\
// Control Panel\Desktop
// TileWallpaper (REG_SZ)
// Wallpaper (REG_SZ)
// WallpaperStyle (REG_SZ)
// WallpaperOriginX (REG_SZ)
// WallpaperOriginY (REG_SZ)
//
reg := TRegIniFile.Create(
'Control Panel\Desktop' ); with reg do
begin
s1 := '0';
X := 0;
Y := 0; case nStyle of
WPS_Tile : s1 := '1';
WPS_Center: nStyle := WPS_Tile;
WPS_XY :
begin
nStyle := WPS_Tile;
X := nX;
Y := nY;
end;
end; WriteString( '',
'Wallpaper',
sWallpaperBMPPath ); WriteString( '',
'TileWallpaper',
s1 ); WriteString( '',
'WallpaperStyle',
IntToStr( nStyle ) ); WriteString( '',
'WallpaperOriginX',
IntToStr( X ) ); WriteString( '',
'WallpaperOriginY',
IntToStr( Y ) );
end;
reg.Free; //
// let everyone know that we
// changed a system parameter
//
SystemParametersInfo(
SPI_SETDESKWALLPAPER,
0,
Nil,
SPIF_SENDWININICHANGE );
end;
Here are two examples on how to call the above SetWallpaperExt() function. // set wallpaper to winnt.bmp and
// stretch it to fit the screen
SetWallpaperExt(
'c:\winnt\winnt.bmp',
WPS_SizeToFit, 0, 0 ); // set the wallpaper origin
// to (10, 200)
SetWallpaperExt(
'c:\winnt\winnt.bmp',
WPS_XY, 10, 200 );
/////////////////////////////////////
永久改变
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, 'Sample.bmp', SPIF_UPDATEINIFILE); 临时改变:
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, 'Sample.bmp',0);
var THEPCHAR:pchar;
begin
THEPCHAR:='e:\a.bmp';
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, THEPCHAR, SPIF_SENDWININICHANGE)
end;用Delphi实现壁纸更换
在Windows95/98中,都是使用注册表对系统数据进行管理,有关壁纸的设置数据保存在Hkey_Current_User\Control Panel\Desktop的Wallpaper和TileWallpaper 等键值中,只要成功修改了这两个键值,然后发消息给Windows即可更换壁纸。在本例的程序中,使用了一个Tform;两个Tspeedbutton(Speedbutton1用于接受用户的浏览命令,Speedbutton2用于接受用户的更换壁纸命令);一个Timage(用于显示图片)。另外,还用到一组文件控件:Tfilelistbox,Tdrivecombobox,Tdirectorylistbox,用于选择图片文件,可以设置FileListBox的mask属性,筛选显示在FileListBox 中的文件类型(如只显示.bmp文件)。下面的两个程序段是实现浏览图片和更换壁纸的关键代码。
Procedure Tform1.SpeedButton1Click(Sender:Tobject);
Begin
If (filelistbox1.FileName=
′′) Then {判断Filelistbox1中文件有没有被选中}
Messagedlg(′请先选择一幅位图′,mtInformation,[mbOK],0)
Else
Image1.Picture.LoadFormFile(Filelistbox1.FileName);{加载图片文件并显示}
End;
ProcedureTform1.SpeedButton2Click(Sender:TObject);
Var
Reg:Tregistry;{Tregistry 对象在Registry 单元中声明,需用Uses令引用Registry单元}
}
Begin
If (Filelistbox1.FileName=′′) Then
Messagedlg(′请先选择一幅位图′,mtinformation,[mbOK],0)
Else
Begin
Reg:=Tregistry.Create;{创建Tregistry对象的实例}
Reg.Rootkey:= Hkey_Current_User;{设置根键名称}
Reg.OpenKey′Control Panel\Desktop′,False); {打开Control Panel\Desktop 路径对应的主键}
Reg.WriteString (′TileWallPaper′,
′0′);
Reg.WriteString
′Wallpaper′,fileli
stbox1.FileName);{向TileWallpaper 和Wallpaper串覆盖写入新值}
Systemparametersinfo(SPI_SETDESKWallpaper,0,Nil,SPIF_SendChange);{向Windows发送消息,通知Windows更换壁纸}
Reg.CloseKey;{将更改内容写入注册表并关闭}
Reg.Free;{释放对象}
End;
End;
代码中用到的一些函数可以察看Delphi的联机帮助。需要注意的是:调用打开子键的函数OpenKey时,第二个参数一定要设为False。
(请作者速与本报联系) 本文出自:《电脑报》1999年03月22日第11期
//////////////////////////////////////
增强的版本
uses
Registry, WinProcs, SysUtils;const
// WallPaperStyles
WPS_Tile = 0;
WPS_Center = 1;
WPS_SizeToFit = 2;
WPS_XY = 3;//
// sWallpaperBMPPath
// - path to a BMP file
//
// nStyle
// - any of the above WallPaperStyles
//
// nX, nY
// - if the nStyle is set to WPS_XY,
// nX and nY can be used to set the
// exact position of the wall paper
//
procedure SetWallpaperExt(
sWallpaperBMPPath : string;
nStyle,
nX, nY : integer );
var
reg : TRegIniFile;
s1 : string;
X, Y : integer;
begin
//
// change registry
//
// HKEY_CURRENT_USER\
// Control Panel\Desktop
// TileWallpaper (REG_SZ)
// Wallpaper (REG_SZ)
// WallpaperStyle (REG_SZ)
// WallpaperOriginX (REG_SZ)
// WallpaperOriginY (REG_SZ)
//
reg := TRegIniFile.Create(
'Control Panel\Desktop' ); with reg do
begin
s1 := '0';
X := 0;
Y := 0; case nStyle of
WPS_Tile : s1 := '1';
WPS_Center: nStyle := WPS_Tile;
WPS_XY :
begin
nStyle := WPS_Tile;
X := nX;
Y := nY;
end;
end; WriteString( '',
'Wallpaper',
sWallpaperBMPPath ); WriteString( '',
'TileWallpaper',
s1 ); WriteString( '',
'WallpaperStyle',
IntToStr( nStyle ) ); WriteString( '',
'WallpaperOriginX',
IntToStr( X ) ); WriteString( '',
'WallpaperOriginY',
IntToStr( Y ) );
end;
reg.Free; //
// let everyone know that we
// changed a system parameter
//
SystemParametersInfo(
SPI_SETDESKWALLPAPER,
0,
Nil,
SPIF_SENDWININICHANGE );
end;
Here are two examples on how to call the above SetWallpaperExt() function. // set wallpaper to winnt.bmp and
// stretch it to fit the screen
SetWallpaperExt(
'c:\winnt\winnt.bmp',
WPS_SizeToFit, 0, 0 ); // set the wallpaper origin
// to (10, 200)
SetWallpaperExt(
'c:\winnt\winnt.bmp',
WPS_XY, 10, 200 );
/////////////////////////////////////
永久改变
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, 'Sample.bmp', SPIF_UPDATEINIFILE); 临时改变:
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, 'Sample.bmp',0);