In windows95/98, the system data is managed using the registry, and the settings for the wallpaper are stored in the wallpaper and tilewallpaper of HKEY_CURRENT_USER\Control Panel\Desktop The same key value, as long as the two key values are successfully modified, and then send a message to Windows to replace the wallpaper. In the program of this example, a Tform two Tspeedbutton (Speedbutton1 is used to accept the user's Browse command, Speedbutton2 to accept the user's replacement wallpaper command), and a timage (for displaying pictures). In addition, a set of file controls is used: Tfilelistbox,tdrivecombobox,tdirectorylistbox, which is used to select picture files, to set FileListBox mask properties, and to filter the display in FileListBox The file type in, such as only. bmp files are displayed. The following two program segments are key codes for implementing browse pictures and replace wallpaper.
Procedure Tform1.speedbutton1click (sender:tobject);
The Begin
If (filelistbox1). Filename=
′′) Then {To determine if Filelistbox1 Chinese pieces are selected}
Messagedlg (select a bitmap ′,mtinformation,[mbok],0)
Else
Image1.Picture.LoadFormFile (Filelistbox1.filename); {Load picture file and display}
End;
Proceduretform1.speedbutton2click (Sender:tobject);
Var
reg:tregistry;{ The Tregistry object is declared in the registry cell and requires the uses to refer to the registry cell}
}
Begin
If (filelistbox1.filename=′′) Then
Messagedlg (Please select a bitmap ′,mtinformation,[mbok],0 first)
Else
Begin
reg:=tregistry.create;{ Create an instance of the Tregistry object}
reg.rootkey:= hkey_current_user;{ Sets the root key name}
Reg.openkey′control panel\desktop′,false); {Open the primary key for the control Panel\Desktop path}
Reg.writestring (′tilewallpaper′,
′0′);
Reg.writestring
′wallpaper′,fileli?
Stbox1. FileName); {Write new value to Tilewallpaper and wallpaper string overrides}
SystemParametersInfo (Spi_setdeskwallpaper,0,nil,spif_sendchange); {Send a message to Windows notifying Windows to replace wallpaper}
Reg.closekey; {Write changes to the registry and close}
Reg.free; {Releasing Object}
End;
End;
Some of the functions used in your code can look at Delphi's online help. It is important to note that the second argument must be set to False when the function Openkey that opens the subkey is invoked.