S
sunzhanwei
Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
<br>s:=isjpg(suilistbox1.Items.Strings[t]);<br>case s of<br>true:<br> Begin //是JPG图像格式,先转换为BMP文件格式,在设为墙纸<br> jpg2bmp(suilistbox1.Items.Strings[t],GetWinTempDir+'/TWPaper.DAP');<br> systemparametersinfo(SPI_SETDESKWALLPAPER,0,PChar(GetWinTempDir+'/TWPaper.DAP'),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);<br> k:=0;<br> t:=t+1;<br> End;<br>false:<br> Begin//是BMP文件,直接设置为墙纸<br> systemparametersinfo(SPI_SETDESKWALLPAPER,0,PChar(suilistbox1.Items.Strings[0]),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);<br> k:=0;<br> t:=t+1;<br> End;<br>//----------------------------------------------------------<br>function TForm1.IsJpg(const filename: string): boolean;<br>Var<br>b : Array[0..1] Of Byte;<br>fs : TFileStream;<br>s:string;<br>begin<br>//result:=false;<br> fs := TFileStream.Create(filename, fmOpenRead);<br> Try<br> fs.Read(b, 3);<br> s := IntToHex(b[0], 2) + IntToHex(b[1], 2);<br> Finally<br> FreeAndNil(fs);<br> End;<br>if s='FFD8' then<br>result:=true<br>else<br>result:=false;<br>end;<br>procedure TForm1.Jpg2Bmp(const source, dest: string);<br>var<br> MyJpeg: TJpegImage;<br> bmp: Tbitmap;<br>begin<br>bmp:=tbitmap.Create;<br>MyJpeg:= TJpegImage.Create;<br>try<br> myjpeg.LoadFromFile(source);<br> bmp.Assign(myjpeg);<br> bmp.SaveToFile(dest);<br>finally<br> bmp.free;<br> myjpeg.Free;<br>end;<br>end;<br>function TForm1.GetWinTempDir: String;<br>var<br> Path:array[0..Max_Path] of Char;<br>begin<br> Result:='';<br> try<br> GetTempPath(SizeOf(Path),Path);<br> Result:=StrPas(Path);<br> except<br> end;<br>end;<br>