file.cpp
上传用户:mushi823
上传日期:2013-03-02
资源大小:21k
文件大小:3k
源码类别:

屏幕保护

开发平台:

Visual C++

  1. #include<windows.h>
  2. #include<stdio.h>
  3. char FileName[1000];
  4. DWORD FullScreen=0;
  5. int ReadReg(char *filename,DWORD *regnum,DWORD *fullscreen)
  6. {
  7. HKEY hkey;
  8. int i,ret;
  9. DWORD ii;
  10. DWORD size;
  11. ret=0;
  12. if(filename==NULL||regnum==NULL||fullscreen==NULL)return -1;
  13. // i=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",0,KEY_ALL_ACCESS,&hkey);
  14. // i=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\youshi\ScrSaver\multimedia",0,KEY_ALL_ACCESS,&hkey);
  15. i=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\youshi\ScrSaver\multimedia",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hkey,&ii);
  16. if(i!=ERROR_SUCCESS)return 1;
  17. size=1000;
  18. i=RegQueryValueEx(hkey,"FileName",NULL,NULL,(unsigned char *)filename,&size);
  19. if(i!=ERROR_SUCCESS)
  20. {
  21. strcpy(filename,"");
  22. i=RegSetValueEx(hkey,"FileName",0,REG_SZ,(unsigned char *)filename,0);
  23. if(i!=ERROR_SUCCESS)ret|=2;
  24. }
  25. size=sizeof(DWORD);
  26. i=RegQueryValueEx(hkey,"RegisterNumber",NULL,NULL,(unsigned char *)regnum,&size);
  27. if(i!=ERROR_SUCCESS)
  28. {
  29. *regnum=0;
  30. i=RegSetValueEx(hkey,"RegisterNumber",0,REG_DWORD,(unsigned char *)regnum,sizeof(DWORD));
  31. if(i!=ERROR_SUCCESS)ret|=4;
  32. }
  33. size=sizeof(DWORD);
  34. i=RegQueryValueEx(hkey,"FullScreen",NULL,NULL,(unsigned char *)fullscreen,&size);
  35. if(i!=ERROR_SUCCESS)
  36. {
  37. *fullscreen=0;
  38. i=RegSetValueEx(hkey,"FullScreen",0,REG_DWORD,(unsigned char *)fullscreen,sizeof(DWORD));
  39. if(i!=ERROR_SUCCESS)ret|=8;
  40. }
  41. i=RegCloseKey(hkey);
  42. return ret;
  43. }
  44. int WriteReg(char *filename,DWORD *regnum,DWORD *fullscreen)
  45. {
  46. HKEY hkey;
  47. int i,ret;
  48. DWORD ii;
  49. ret=0;
  50. i=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\youshi\ScrSaver\multimedia",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hkey,&ii);
  51. if(i!=ERROR_SUCCESS)return 1;
  52. if(filename!=NULL)
  53. {
  54. i=RegSetValueEx(hkey,"FileName",0,REG_SZ,(unsigned char *)filename,strlen(filename));
  55. if(i!=ERROR_SUCCESS)
  56. {
  57. strcpy(filename,"");
  58. ret|=2;
  59. }
  60. }
  61. if(regnum!=NULL)
  62. {
  63. i=RegSetValueEx(hkey,"RegisterNumber",0,REG_DWORD,(unsigned char *)regnum,sizeof(DWORD));
  64. if(i!=ERROR_SUCCESS)
  65. {
  66. *regnum=0;
  67. ret|=4;
  68. }
  69. }
  70. if(fullscreen!=NULL)
  71. {
  72. i=RegSetValueEx(hkey,"FullScreen",0,REG_DWORD,(unsigned char *)fullscreen,sizeof(DWORD));
  73. if(i!=ERROR_SUCCESS)
  74. {
  75. *fullscreen=0;
  76. ret|=8;
  77. }
  78. }
  79. i=RegCloseKey(hkey);
  80. return ret;
  81. }
  82. int TestReg()
  83. {
  84. DWORD savenum,regnum;
  85. DWORD snum;
  86. GetVolumeInformation("C:\",NULL,0,&snum,NULL,NULL,NULL,0);
  87. ReadReg(FileName,&regnum,&FullScreen);
  88. FILE *fp;
  89. char dir[100];
  90. GetWindowsDirectory(dir,sizeof(dir));
  91. strcat(dir,"\saverreg.dat");
  92. if((fp=fopen(dir,"rb"))==NULL)
  93. {
  94. savenum=0;
  95. }
  96. else
  97. {
  98. fread(&savenum,sizeof(DWORD),1,fp);
  99. fclose(fp);
  100. }
  101. if(savenum!=snum)
  102. {
  103. fp=fopen(dir,"wb");
  104. fwrite(&snum,sizeof(DWORD),1,fp);
  105. fclose(fp);
  106. }
  107. if(regnum==7265)return 1;
  108. snum*='C';
  109. snum/='L';
  110. snum-='Z';
  111. snum*='S';
  112. snum/='L';
  113. if(snum==regnum)return 1;
  114. else return 0;
  115. }