Registry.cpp
上传用户:z3308516
上传日期:2013-01-23
资源大小:703k
文件大小:7k
源码类别:

2D图形编程

开发平台:

Visual C++

  1. #include "StdAfx.h"
  2. #include "Registry.h"
  3. #include "Resource.h"
  4. CRegistry::CRegistry(void)
  5. {
  6. ret=RegCreateKey(HKEY_LOCAL_MACHINE,"Software\beautifulGame",&hkey);
  7. // assert(ret==ERROR_SUCCESS);
  8. Check();
  9. }
  10. void CRegistry::Check(){
  11. int ifor;
  12. sz=sizeof(dvalue);
  13. ret=RegQueryValueEx(hkey,"low1",NULL,NULL,(LPBYTE)&dvalue,&sz);
  14. strcpy((char*)szuser,"unknown");
  15. if(ret!=ERROR_SUCCESS){
  16. dvalue=1000;
  17. for(ifor=1;ifor<9;ifor++){
  18. wsprintf((LPTSTR)szkey,"low%d",ifor);
  19. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
  20. wsprintf((LPTSTR)szkey,"ulow%d",ifor);
  21. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  22. wsprintf((LPTSTR)szkey,"normal%d",ifor);
  23. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
  24. wsprintf((LPTSTR)szkey,"unormal%d",ifor);
  25. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  26. wsprintf((LPTSTR)szkey,"high%d",ifor);
  27. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
  28. wsprintf((LPTSTR)szkey,"uhigh%d",ifor);
  29. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  30. wsprintf((LPTSTR)szkey,"special%d",ifor);
  31. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
  32. wsprintf((LPTSTR)szkey,"uspecial%d",ifor);
  33. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  34. }
  35. }
  36. }
  37. void CRegistry::ShowAll(HWND hParent,LEVEL_STRUCT lv){ //排行傍
  38. int ifor;
  39. char szAll[1024];
  40. sz=sizeof(DWORD);
  41. memset((void*)szAll,0,sizeof(szAll));
  42. switch(lv){
  43. case enumLow:
  44. wsprintf((LPTSTR)szAll,"低手排行榜nn");
  45. break;
  46. case enumNormal:
  47. wsprintf((LPTSTR)szAll,"中手排行榜nn");
  48. break;
  49. case enumHigh:
  50. wsprintf((LPTSTR)szAll,"高手排行榜nn");
  51. break;
  52. case enumSpecial:
  53. wsprintf((LPTSTR)szAll,"特别排行榜nn");
  54. break;
  55. }
  56. for(ifor=1;ifor<9;ifor++){
  57. switch(lv){
  58. case enumLow:
  59. wsprintf((LPTSTR)szkey,"ulow%d",ifor);
  60. ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
  61. wsprintf((LPTSTR)szkey,"low%d",ifor);
  62. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
  63. wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
  64. break;
  65. case enumNormal:
  66. wsprintf((LPTSTR)szkey,"unormal%d",ifor);
  67. ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
  68. wsprintf((LPTSTR)szkey,"normal%d",ifor);
  69. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
  70. wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
  71. break;
  72. case enumHigh:
  73. wsprintf((LPTSTR)szkey,"uhigh%d",ifor);
  74. ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
  75. wsprintf((LPTSTR)szkey,"high%d",ifor);
  76. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
  77. wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
  78. break;
  79. case enumSpecial:
  80. wsprintf((LPTSTR)szkey,"uspecial%d",ifor);
  81. ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
  82. wsprintf((LPTSTR)szkey,"special%d",ifor);
  83. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
  84. wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
  85. break;
  86. }
  87. }
  88. MessageBox(hParent,(LPCTSTR)szAll,"英雄排行榜...",MB_OK);
  89. }
  90. int CRegistry::CompareAndSetValue(HWND hParent,LEVEL_STRUCT lv,DWORD ifen){
  91. int ifor;
  92. sz=sizeof(dvalue);
  93. switch(lv){
  94. case enumSpecial:
  95. for(ifor=1;ifor<9;ifor++){
  96. wsprintf((LPTSTR)szkey,"special%d",ifor);
  97. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
  98. if(ifen>dvalue){
  99. /////////
  100. if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
  101. (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
  102. //record
  103. wsprintf((LPTSTR)szkey,"special%d",ifor);
  104. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
  105. wsprintf((LPTSTR)szkey,"uspecial%d",ifor);
  106. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  107. }
  108. ShowAll(hParent,lv);
  109. return ifor;
  110. }
  111. }
  112. break;
  113. case enumLow:
  114. for(ifor=1;ifor<9;ifor++){
  115. wsprintf((LPTSTR)szkey,"low%d",ifor);
  116. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
  117. if(ifen>dvalue){
  118. /////////
  119. if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
  120. (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
  121. //record
  122. wsprintf((LPTSTR)szkey,"low%d",ifor);
  123. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
  124. wsprintf((LPTSTR)szkey,"ulow%d",ifor);
  125. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  126. }
  127. ShowAll(hParent,lv);
  128. return ifor;
  129. }
  130. }
  131. break;
  132. case enumNormal:
  133. for(ifor=1;ifor<9;ifor++){
  134. wsprintf((LPTSTR)szkey,"normal%d",ifor);
  135. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
  136. if(ifen>dvalue){
  137. /////////
  138. if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
  139. (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
  140. //record
  141. wsprintf((LPTSTR)szkey,"normal%d",ifor);
  142. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
  143. wsprintf((LPTSTR)szkey,"unormal%d",ifor);
  144. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  145. }
  146. ShowAll(hParent,lv);
  147. return ifor;
  148. }
  149. }
  150. break;
  151. case enumHigh:
  152. for(ifor=1;ifor<9;ifor++){
  153. wsprintf((LPTSTR)szkey,"high%d",ifor);
  154. ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
  155. if(ifen>dvalue){
  156. /////////
  157. if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
  158. (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
  159. //record
  160. wsprintf((LPTSTR)szkey,"high%d",ifor);
  161. WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
  162. wsprintf((LPTSTR)szkey,"uhigh%d",ifor);
  163. WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
  164. }
  165. ShowAll(hParent,lv);
  166. return ifor;
  167. }
  168. }
  169. break;
  170. }
  171. return -1;
  172. }
  173. INT CRegistry::ReadValue(LPCTSTR key,const DWORD type,BYTE *lpData,DWORD sz){ //always suc
  174. ret=RegQueryValueEx(hkey,key,NULL,NULL,lpData,&sz);
  175. if(ret==ERROR_SUCCESS)
  176. return 1;
  177. return 0;
  178. }
  179. INT CRegistry::WriteValue(LPCTSTR key,const DWORD type,CONST BYTE *lpData,DWORD sz){ //always suc
  180. ret=RegSetValueEx(hkey,key,0,type,lpData,sz);
  181. if(ret==ERROR_SUCCESS)
  182. return 1;
  183. else
  184. return 0;
  185. }
  186. CRegistry::~CRegistry(void)
  187. {
  188. RegCloseKey(hkey);
  189. }
  190. LRESULT CALLBACK CRegistry::DlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam){
  191. switch(msg){
  192. case WM_INITDIALOG:
  193. SetDlgItemText(hDlg,IDC_USERNAME,(LPCTSTR)"unknown");
  194. return true;
  195. break;
  196. case WM_COMMAND:
  197. switch(LOWORD(wParam)){
  198. case IDOK:
  199. GetDlgItemText(hDlg,IDC_USERNAME,(LPTSTR)szuser,sizeof(szuser));
  200. EndDialog(hDlg,IDOK);
  201. break;
  202. case IDCANCEL:
  203. EndDialog(hDlg,IDCANCEL);
  204. break;
  205. }
  206. break;
  207. }
  208. return false;
  209. }
  210. char CRegistry::szuser[20]={0};