Use Delphi to implement wallpaper replacement

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.