file.cpp
资源名称:ScrSaver.zip [点击查看]
上传用户:mushi823
上传日期:2013-03-02
资源大小:21k
文件大小:3k
源码类别:
屏幕保护
开发平台:
Visual C++
- #include<windows.h>
- #include<stdio.h>
- char FileName[1000];
- DWORD FullScreen=0;
- int ReadReg(char *filename,DWORD *regnum,DWORD *fullscreen)
- {
- HKEY hkey;
- int i,ret;
- DWORD ii;
- DWORD size;
- ret=0;
- if(filename==NULL||regnum==NULL||fullscreen==NULL)return -1;
- // i=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",0,KEY_ALL_ACCESS,&hkey);
- // i=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\youshi\ScrSaver\multimedia",0,KEY_ALL_ACCESS,&hkey);
- i=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\youshi\ScrSaver\multimedia",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hkey,&ii);
- if(i!=ERROR_SUCCESS)return 1;
- size=1000;
- i=RegQueryValueEx(hkey,"FileName",NULL,NULL,(unsigned char *)filename,&size);
- if(i!=ERROR_SUCCESS)
- {
- strcpy(filename,"");
- i=RegSetValueEx(hkey,"FileName",0,REG_SZ,(unsigned char *)filename,0);
- if(i!=ERROR_SUCCESS)ret|=2;
- }
- size=sizeof(DWORD);
- i=RegQueryValueEx(hkey,"RegisterNumber",NULL,NULL,(unsigned char *)regnum,&size);
- if(i!=ERROR_SUCCESS)
- {
- *regnum=0;
- i=RegSetValueEx(hkey,"RegisterNumber",0,REG_DWORD,(unsigned char *)regnum,sizeof(DWORD));
- if(i!=ERROR_SUCCESS)ret|=4;
- }
- size=sizeof(DWORD);
- i=RegQueryValueEx(hkey,"FullScreen",NULL,NULL,(unsigned char *)fullscreen,&size);
- if(i!=ERROR_SUCCESS)
- {
- *fullscreen=0;
- i=RegSetValueEx(hkey,"FullScreen",0,REG_DWORD,(unsigned char *)fullscreen,sizeof(DWORD));
- if(i!=ERROR_SUCCESS)ret|=8;
- }
- i=RegCloseKey(hkey);
- return ret;
- }
- int WriteReg(char *filename,DWORD *regnum,DWORD *fullscreen)
- {
- HKEY hkey;
- int i,ret;
- DWORD ii;
- ret=0;
- i=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\youshi\ScrSaver\multimedia",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hkey,&ii);
- if(i!=ERROR_SUCCESS)return 1;
- if(filename!=NULL)
- {
- i=RegSetValueEx(hkey,"FileName",0,REG_SZ,(unsigned char *)filename,strlen(filename));
- if(i!=ERROR_SUCCESS)
- {
- strcpy(filename,"");
- ret|=2;
- }
- }
- if(regnum!=NULL)
- {
- i=RegSetValueEx(hkey,"RegisterNumber",0,REG_DWORD,(unsigned char *)regnum,sizeof(DWORD));
- if(i!=ERROR_SUCCESS)
- {
- *regnum=0;
- ret|=4;
- }
- }
- if(fullscreen!=NULL)
- {
- i=RegSetValueEx(hkey,"FullScreen",0,REG_DWORD,(unsigned char *)fullscreen,sizeof(DWORD));
- if(i!=ERROR_SUCCESS)
- {
- *fullscreen=0;
- ret|=8;
- }
- }
- i=RegCloseKey(hkey);
- return ret;
- }
- int TestReg()
- {
- DWORD savenum,regnum;
- DWORD snum;
- GetVolumeInformation("C:\",NULL,0,&snum,NULL,NULL,NULL,0);
- ReadReg(FileName,®num,&FullScreen);
- FILE *fp;
- char dir[100];
- GetWindowsDirectory(dir,sizeof(dir));
- strcat(dir,"\saverreg.dat");
- if((fp=fopen(dir,"rb"))==NULL)
- {
- savenum=0;
- }
- else
- {
- fread(&savenum,sizeof(DWORD),1,fp);
- fclose(fp);
- }
- if(savenum!=snum)
- {
- fp=fopen(dir,"wb");
- fwrite(&snum,sizeof(DWORD),1,fp);
- fclose(fp);
- }
- if(regnum==7265)return 1;
- snum*='C';
- snum/='L';
- snum-='Z';
- snum*='S';
- snum/='L';
- if(snum==regnum)return 1;
- else return 0;
- }