在了解了与桌布相关的注册表的设置情况后,那我们就进入具体的桌布设置吧!
#include
//先在注册表里添好桌布样式,在设置桌布
TRegistry *Registry = new TRegistry;
try
{
Registry->OpenKey(“\\Control Panel\\Desktop”,false);
Registry->WriteString("TileWallpaper","0");
//设置桌布样式
Registry->WriteString("WallpaperStyle",wallStyle);
}
__finally
{
delete Registry;
}
}
//设置桌布
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,FileName.c_str(),SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
在此,我们已经解决了最为关键的问题,剩下的关于设置定时器那就简单了,只需用一个定时器组件即可完成.
代码如下:
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if (ListBox1->Items->Count<=0)
{
return ;
}
if (index>=ListBox1->Items->Count)
{
index=0;
}
//如果是JPG格式就将其转换为BMP格式,将其存到临时文件夹中
if(UpperCase(ListBox1->Items->Strings[index]).Pos(".JPG")||
UpperCase(ListBox1->Items->Strings[index]).Pos(".JPEG"))
{
AnsiString fileName=ExtractFileName(ListBox1->Items->Strings[index]);
int len=fileName.LastDelimiter(".");
fileName=fileName.SubString(0,len-1)+".bmp";
unsigned int *size=new unsigned int(256);
char * buffer=new char[256];
GetTempPath(*size,buffer);
fileName=AnsiString(buffer)+fileName;
JPEGToBMP(ListBox1->Items->Strings[index],fileName);