是不是所有的api函数都在windows.pas中的呢?
我用了其中想改变壁纸的函数可总是没有成功,而且要手动去刷新桌面后就变成无墙纸桌面。。??源码如下:
 filename:='G:\其他软件\壁纸\flower\hua007.JPG';
 systemparametersinfo(spi_setdeskwallpaper,0,pchar(filename),spif_updateinifile);我是delphi初学者,我需要去买本api大全来看吗?

解决方案 »

  1.   

    到Delphi中自带的Api帮助来看,或者用msdn来看
      

  2.   

    改成:
     systemparametersinfo(spi_setdeskwallpaper,0,pchar(filename),0);
    //spi_setdeskwallpaper-->0
      

  3.   

    试试这个:更改墙纸,请参考以下的程序。
      procedureChangeIt;
      var
      Reg:TregIniFile;
      begin
      Reg:ΚTRegIniFile.Create(′ControlPanel′);
      Reg.WriteString(′desktop′,′Wallpaper′,′c:ιpwin95ιforest.bmp′);
      Reg.WriteString(′desktop′,′TileWallpaper′,′1′);
      Reg.Free;
      SystemParametersInfo(SPI-SETDESKWALLPAPER,0,nil,SPIF-SENDWININICHANGE);
      end;
      

  4.   

    或这个:
    设置墙纸
    procedure TForm1.Button1Click(Sender: TObject);
    var
      ADeskTop:IActiveDesktop;
      wallpaper:PwideChar;
    begin
      ADeskTop:=CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
      wallpaper:='d:\2.bmp';
      ADeskTop.SetWallpaper(wallpaper,0);
      ADeskTop.ApplyChanges(AD_APPLY_ALL);
    end;
      

  5.   

    还是实现不了啊?
    ///改成:
     systemparametersinfo(spi_setdeskwallpaper,0,pchar(filename),0);
    //spi_setdeskwallpaper-->0 改了也一样啊其他又看不懂,后面两个是用什么实现的啊???
      

  6.   

    'Change the desktop's background
        SystemParametersInfo SPI_SETDESKWALLPAPER, 0, CDBox.filename, SPIF_UPDATEINIFILEor  delphiseabird(沙鸥)说的通过修改注册表来实现。
      

  7.   

    能:用于随机的更换壁纸,能适应不同的分辨率。联系方法:[email protected]。附注:Source.RES的建立方法:用任意一个文本编辑器输入“SourceCode RT_RCDATA AltWallPaper.dpr”并保存到源代码目录,然后用Delphi 5自带的Brcc32.exe进行编译即可。*******************************************************************************}program AltWallPaper;useswindows,Sysutils,jpeg,graphics,classes,registry,messages,shlobj,comobj,Activex;constWALLPAPERFILENAME='WallPaperK.BMP';OUTFILENAME='AltWallPaper.dpr';APPNAME='壁纸随机更换器';USFILENAME='+APPNAME+'\u21368卸载'+APPNAME+'.lnk';SETFILENAME='+APPNAME+'\u21442参数设置.lnk';RUNFILENAME='+APPNAME+'\u38543随机更换壁纸.lnk';PROGDIR='+APPNAME;REGKEY='Software';REGKEY1='Software';MSG1=' 提示:本程序不需要注册,你可以自由传播和使用这个程序,唯一的要求是'+'向作者寄一封信,如果你发现Bug也请及时报告作者以便修正。'+',但是作者不对使用本程序造成的任何损失负责!'#13+' 联系方法:E_Mail([email protected]])'#13+' 本程序遵守源码开放原则,如果你修改了程序,请提供本程序源代码和你修改后的代码。'#13#13+' 您需要源代码吗?选择[是]将生成源代码文件:'+OUTFILENAME;MSG2=' 是否为程序建立快捷方式?选择[是]将在开始菜单中建立如下三个快捷方式:'#13+'[程序]'+RUNFILENAME+#13+'[程序]'+SETFILENAME+#13+'[程序]'+USFILENAME+#13+' 注意:如果要恢复本程序到第一次运行时的状态,请删除注册表中如下主键即可[HKEY_CURRENT_USER+REGKEY+']。';typeTFindCallBack=procedure (const filename:string);{$R *.RES}{$R Source.RES}varpath:string;filenames:tstrings;reg:tregistry;windir:pchar;sourcecode:TResourceStream;programfolder:pchar;ppidl:pitemidlist;procedure Jpg2Bmp(const source,dest:string);varMyJpeg: TJpegImage;bmp: Tbitmap;beginbmp:=TBitmap.Create;MyJpeg:= TJpegImage.Create;trymyjpeg.LoadFromFile(source);bmp.Assign(myjpeg);bmp.SaveToFile(dest);finallybmp.free;myjpeg.Free;end;end;procedure FindFile(const path: String;proc:TFindCallBack);varfpath: String;info: TsearchRec;beginif path[length(path)]<>' then fpath:=path+' else fpath:=path;tryif 0=findfirst(fpath+'*',faanyfile,info) thenbeginif (info.Name<>'.') and (info.Name<>'..') thenif (info.Attr and faDirectory)<>faDirectory thenproc(fpath+info.FindData.cFileName)elsefindfile(fpath+info.Name,proc);while 0=findnext(info) doif (info.Name<>'.') and (info.Name<>'..') thenif (info.Attr and faDirectory)<>faDirectory thenproc(fpath+info.FindData.cFileName)elsefindfile(fpath+info.Name,proc);end;finallyfindclose(info);end;end;procedure Callback(const fn:string);varext:string;beginext:=uppercase(extractfileext(fn));if (ext='.JPG') or (ext='.BMP') then filenames.Add(fn);end;function SelectDirectory(const Caption: string; out Directory: string): Boolean;varlpbi:_browseinfo;buf:array [0..MAX_PATH] of char;id:ishellfolder;beginresult:=false;lpbi.hwndOwner:=0;lpbi.lpfn:=nil;lpbi.lpszTitle:=pchar(caption);lpbi.ulFlags:=BIF_RETURNONLYFSDIRS+BIF_STATUSTEXT;SHGetDesktopFolder(id);lpbi.pidlRoot:=nil;getmem(lpbi.pszDisplayName,MAX_PATH);if shgetpathfromidlist(shbrowseforfolder(lpbi),buf) thenbeginresult:=true;directory:=buf;if length(directory)<>3 then directory:=directory+';end;freemem(lpbi.pszDisplayName);end;function DirectoryExists(const Name: string): Boolean;varCode: Integer;beginCode := GetFileAttributes(PChar(Name));Result := (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0);end;procedure DeleteMe;varBatchFile: TextFile;BatchFileName: string;beginif SetFileAttributes(pchar(paramstr(0)),FILE_ATTRIBUTE_NORMAL) thenbeginBatchFileName := changefileext(paramstr(0),'.bat');AssignFile(BatchFile, BatchFileName);Rewrite(BatchFile);Writeln(BatchFile, ':try');Writeln(BatchFile, 'del "' + ParamStr(0) + '"');Writeln(BatchFile, 'if exist "' + ParamStr(0) + '"' + ' goto try');Writeln(BatchFile, 'del %0');CloseFile(BatchFile);winexec(pchar(batchfilename),sw_hide);end;end;function CreateLinkFile(const sourcefilename,Arguments,DestFileName:string):boolean;varanobj:IUnknown;shlink:IShellLink;pFile:IPersistFile;wFileName:widestring;beginwFileName:=destfilename;anobj:=CreateComObject(CLSID_SHELLLINK);shlink:=anobj as IShellLink;pFile:=anobj as IPersistFile;shlink.SetPath(pchar(sourcefilename));shlink.SetArguments(pchar(Arguments));shlink.SetShowCmd(1);if DestFileName='' thenwFileName:=ChangeFileExt(sourcefilename,'lnk');result:=succeeded(pFile.Save(pwchar(wFileName),false));end;procedure fitbitmap;var接下面
      

  8.   

    接上面abmp,bbmp:tbitmap;scale:real;sx,sy:integer;beginabmp:=tbitmap.Create;bbmp:=tbitmap.Create;sx:=GetSystemMetrics(SM_CXSCREEN);sy:=GetSystemMetrics(SM_CYSCREEN);tryabmp.LoadFromFile(windir+WALLPAPERFILENAME);if (abmp.Width>sx) or (abmp.Height>sy) thenbeginif abmp.Width/sx>abmp.Height/sy then scale:=abmp.Width/sx else scale:=abmp.Height/sy;bbmp.Width:=round(abmp.Width/scale);bbmp.Height:=round(abmp.Height/scale);bbmp.PixelFormat:=abmp.PixelFormat;SetStretchBltMode(bbmp.Canvas.Handle,COLORONCOLOR);stretchblt(bbmp.Canvas.Handle,0,0,bbmp.Width,bbmp.Height,abmp.Canvas.Handle,0,0,abmp.Width,abmp.Height,srccopy);bbmp.SaveToFile(windir+WALLPAPERFILENAME);end;finallyabmp.Free;bbmp.Free;end;end;beginGetmem(programfolder,MAX_PATH);getmem(windir,MAX_PATH);getwindowsdirectory(windir,MAX_PATH);if strlen(windir)<>3 then strcat(windir,');filenames:=tstringlist.Create;reg:=tregistry.Create;tryif succeeded(SHGetSpecialFolderLocation(0,CSIDL_PROGRAMS,ppidl)) thenif not shgetpathfromidlist(ppidl,programfolder) thenbeginmessagebox(0,'出现未知错误!程序终止!','错误',MB_OK+MB_ICONERROR);exit;end;if paramstr(1)='/U' thenif MessageBox(0,'你真的要卸载吗?','警告',MB_OKCANCEL+MB_ICONWARNING)=IDOK thenbeginreg:=tregistry.Create;reg.DeleteKey(REGKEY);reg.RootKey:=HKEY_LOCAL_MACHINE;if reg.OpenKey(REGKEY1,false) and reg.ValueExists(APPNAME) thenreg.DeleteValue(APPNAME);reg.CloseKey;deletefile(programfolder+RUNFILENAME);deletefile(programfolder+SETFILENAME);deletefile(programfolder+USFILENAME);removedirectory(pchar(programfolder+PROGDIR));deleteme;MessageBox(0,'成功卸载:'+APPNAME,'信息',MB_OK+MB_ICONINFORMATION);exit;endelse exit;if reg.OpenKey(REGKEY,true) thenbeginif not reg.ValueExists('FirstRun') thenbeginif (MessageBox(0,MSG1,'信息',MB_YESNO+MB_ICONINFORMATION+MB_APPLMODAL)=IDYES) andselectdirectory('请选择保存源代码文件的目录:',path) thenbeginsourcecode:=TResourceStream.Create(hinstance,'SourceCode','RT_RCDATA');sourcecode.SaveToFile(path+OUTFILENAME);sourcecode.Free;end;if MessageBox(0,MSG2,'安装',MB_YESNO+MB_ICONINFORMATION)=IDYES thenif (CoInitialize(nil)=S_OK) and CreateDirectory(pchar(programfolder+PROGDIR),nil) thenbeginCreateLinkFile(paramstr(0),'/AutoRun',programfolder+RUNFILENAME);createlinkfile(paramstr(0),'',programfolder+SETFILENAME);createlinkfile(paramstr(0),'/U',programfolder+USFILENAME);CoUninitialize;end else messagebox(0,'不能建立快捷方式,可能程序已经安装了!','错误',MB_OK+MB_ICONERROR);end;path:='';reg.WriteBool('FirstRun',true);if reg.ValueExists('Path') thenbeginif (paramstr(1)<>'/AutoRun') thenif selectdirectory(' 更改图片文件所在(JPEG格式或者BMP格式)的目录。请更改图片目录:',path) thenreg.WriteString('Path',path) else exit;Path:=reg.ReadString('Path');if not directoryexists(path) thenif selectdirectory(' 指定的图片(JPEG格式或者BMP格式)目录不存在。请另外选择一个目录:',path) thenreg.WriteString('Path',path) else exit;end elseif selectdirectory(' 没有定义图片文件所在(JPEG格式或者BMP格式)的目录。必须指定目录程序才能正常运行,请选择目录:',path) thenreg.WriteString('Path',path) else exit;reg.CloseKey;if directoryexists(path) thenbeginfindfile(path,Callback);if filenames.Count>0 thenbeginrandomize;path:=filenames.Strings[random(filenames.Count)];if Uppercase(extractfileext(path))='.JPG' thentrySetFileAttributes(pchar(windir+WALLPAPERFILENAME),FILE_ATTRIBUTE_NORMAL);jpg2bmp(path,windir+WALLPAPERFILENAME);exceptMessageBox(0,'不能建立输出文件。'#13+'请检查文件格式是否正确或者检查磁盘!','错误',MB_OK+MB_ICONERROR);exit;end else copyfile(pchar(path),pchar(windir+WALLPAPERFILENAME),false);path:=windir+WALLPAPERFILENAME;if fileexists(path) thenbeginFitbitmap;if reg.OpenKey('Control Panel',true) thenbeginreg.WriteString('WallPaper',path);reg.WriteString('TileWallpaper','0');systemparametersinfo(SPI_SETDESKWALLPAPER,0,pchar(path),0);end;end;end;end;reg.RootKey:=HKEY_LOCAL_MACHINE;if reg.OpenKey(REGKEY1,true) then reg.WriteString(APPNAME,paramstr(0)+' /AutoRun');reg.CloseKey;end;finallyfilenames.Free;reg.Free;freemem(programfolder);freemem(windir);end;end. 
      

  9.   

    为什么只有bmp格式的图像才能实现多个图片更换壁纸?用jpg就不行,真奇怪,请高手指点!!
      reg:=tregistry.Create;
       try
       reg.rootkey:=HKEY_CURRENT_USER;
       if reg.openkey('\Control Panel\DeskTop', False) then
       begin
        Reg.WriteString('TileWallPaper', '0'); // 平铺方式,TileWallPaper为1
        Reg.WriteString('WallPaperStyle', '0'); // 非拉伸方式,WallPaperStyle为0
        Reg.WriteString('WallPaper', filename[i]); // 墙纸文件的路径
        Reg.CloseKey;
       end
       finally
         Reg.Free;
       end;
       SystemParametersInfo(SPI_SETDESKWALLPAPER,0,nil,SPIF_SENDWININICHANGE);