You learned VB, you know how to replace Windows wallpaper through the program in VB, how is it easy to replace the wallpaper as VB in Delphi? In fact, it is also very convenient, do not believe? Please refer to the following programs.
ProcedureChangeit; Var REG: Treginifile; Begin Reg: p TregInifile. CREATE ('ControlPanel'); REG. WriteString ('Desktop', 'Wallpaper', 'C: | PWIN95 | forwall.bmp'); REG. WriteString ('Desktop', 'TileWallpaper', '1'); REG. Free; SystemParasetersInfo (Spi-setDeskwallpaper, 0, nil, spif-sendwinichange);
--------------------------------------------------
In Windows 95/98, the system data is managed using the registry, and the setting data for wallpapers is saved in the Wallpaper and TileWallPaper equivalence of the wallpaper. As long as the two key values are successfully modified, then Send a message to Windows to replace wallpaper. In the program of this example, a TFORM is used; two TSPEEDButton (SpeedButton1 is used to accept the user's browsing command, and SpeedButton2 is used to accept the user's replacement wallpaper command); a TIMAGE (for display pictures). In addition, it is also available in a set of file controls: TFileListBox, TDRIVAMBOX, TDIRECTORYLISTBOX, is used to select a picture file, which can set the filelistbox's Mask property, filter the file type displayed in FileListBox (such as only .bmp file). The following two blocks are critical code that implements browsing pictures and replacing wallpapers.
Procedure TFORM1.SPEEDBUTTON1CLICK (Sender: TOBJECT);
Begin
IF (fileListbox1.filename =
'') THEN {Judging the file in FileListBox1 is selected}
Messagedlg ('Please 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; {Tregistry Declare in the Registry unit, need to reference the registry unit}
}
Begin
IF (filelistbox1.filename = ') THEN
Messagedlg ('Please select a bitmap ", Mtinformation, [Mbok], 0)
Else
Begin
REG: = Tregistry.create; {Creating an instance of Tregistry object}
Reg.rootkey: = HKEY_CURRENT_USER; {Set Root Key Name}
Reg.openkey'Control Panel / Desktop ', false; {Open the primary key corresponding to the Control Panel / Desktop path} Reg.writeString (' TileWallpaper ',
'0');
Reg.writeString
'Wallpaper', Fileli
STBOX1.FILENAME); {Write a new value to TileWallpaper and WallPaper skewers}
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, NIL, SPIF_SENDCHANGE); {Send a message to Windows, inform Windows Replace Wallpaper}
Reg.closekey; {Write change content into the registry and close}
Reg.Free; {release object}
END;
END;
Some functions used in the code can check the online help of Delphi. It should be noted that the second parameter must be set to false when calling the function OpenKey that opens the subkey.