Registry.cpp
资源名称:连连看源程序.rar [点击查看]
上传用户:z3308516
上传日期:2013-01-23
资源大小:703k
文件大小:7k
源码类别:
2D图形编程
开发平台:
Visual C++
- #include "StdAfx.h"
- #include "Registry.h"
- #include "Resource.h"
- CRegistry::CRegistry(void)
- {
- ret=RegCreateKey(HKEY_LOCAL_MACHINE,"Software\beautifulGame",&hkey);
- // assert(ret==ERROR_SUCCESS);
- Check();
- }
- void CRegistry::Check(){
- int ifor;
- sz=sizeof(dvalue);
- ret=RegQueryValueEx(hkey,"low1",NULL,NULL,(LPBYTE)&dvalue,&sz);
- strcpy((char*)szuser,"unknown");
- if(ret!=ERROR_SUCCESS){
- dvalue=1000;
- for(ifor=1;ifor<9;ifor++){
- wsprintf((LPTSTR)szkey,"low%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"ulow%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- wsprintf((LPTSTR)szkey,"normal%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"unormal%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- wsprintf((LPTSTR)szkey,"high%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"uhigh%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- wsprintf((LPTSTR)szkey,"special%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"uspecial%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- }
- }
- }
- void CRegistry::ShowAll(HWND hParent,LEVEL_STRUCT lv){ //排行傍
- int ifor;
- char szAll[1024];
- sz=sizeof(DWORD);
- memset((void*)szAll,0,sizeof(szAll));
- switch(lv){
- case enumLow:
- wsprintf((LPTSTR)szAll,"低手排行榜nn");
- break;
- case enumNormal:
- wsprintf((LPTSTR)szAll,"中手排行榜nn");
- break;
- case enumHigh:
- wsprintf((LPTSTR)szAll,"高手排行榜nn");
- break;
- case enumSpecial:
- wsprintf((LPTSTR)szAll,"特别排行榜nn");
- break;
- }
- for(ifor=1;ifor<9;ifor++){
- switch(lv){
- case enumLow:
- wsprintf((LPTSTR)szkey,"ulow%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
- wsprintf((LPTSTR)szkey,"low%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
- break;
- case enumNormal:
- wsprintf((LPTSTR)szkey,"unormal%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
- wsprintf((LPTSTR)szkey,"normal%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
- break;
- case enumHigh:
- wsprintf((LPTSTR)szkey,"uhigh%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
- wsprintf((LPTSTR)szkey,"high%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
- break;
- case enumSpecial:
- wsprintf((LPTSTR)szkey,"uspecial%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_SZ,(BYTE*)szuser,sizeof(szuser));
- wsprintf((LPTSTR)szkey,"special%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sizeof(DWORD));
- wsprintf((LPTSTR)szAll,"%s%sttttt%dnn",szAll,szuser,dvalue);
- break;
- }
- }
- MessageBox(hParent,(LPCTSTR)szAll,"英雄排行榜...",MB_OK);
- }
- int CRegistry::CompareAndSetValue(HWND hParent,LEVEL_STRUCT lv,DWORD ifen){
- int ifor;
- sz=sizeof(dvalue);
- switch(lv){
- case enumSpecial:
- for(ifor=1;ifor<9;ifor++){
- wsprintf((LPTSTR)szkey,"special%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
- if(ifen>dvalue){
- /////////
- if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
- (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
- //record
- wsprintf((LPTSTR)szkey,"special%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"uspecial%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- }
- ShowAll(hParent,lv);
- return ifor;
- }
- }
- break;
- case enumLow:
- for(ifor=1;ifor<9;ifor++){
- wsprintf((LPTSTR)szkey,"low%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
- if(ifen>dvalue){
- /////////
- if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
- (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
- //record
- wsprintf((LPTSTR)szkey,"low%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"ulow%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- }
- ShowAll(hParent,lv);
- return ifor;
- }
- }
- break;
- case enumNormal:
- for(ifor=1;ifor<9;ifor++){
- wsprintf((LPTSTR)szkey,"normal%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
- if(ifen>dvalue){
- /////////
- if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
- (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
- //record
- wsprintf((LPTSTR)szkey,"normal%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"unormal%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- }
- ShowAll(hParent,lv);
- return ifor;
- }
- }
- break;
- case enumHigh:
- for(ifor=1;ifor<9;ifor++){
- wsprintf((LPTSTR)szkey,"high%d",ifor);
- ReadValue((LPCTSTR)szkey,REG_DWORD,(BYTE*)&dvalue,sz);
- if(ifen>dvalue){
- /////////
- if(DialogBox((HINSTANCE)GetModuleHandle(NULL),
- (LPCTSTR)IDD_USERNAME,hParent,(DLGPROC)DlgProc)==IDOK){
- //record
- wsprintf((LPTSTR)szkey,"high%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_DWORD,(CONST BYTE*)&ifen,sizeof(DWORD));
- wsprintf((LPTSTR)szkey,"uhigh%d",ifor);
- WriteValue((LPCTSTR)szkey,REG_SZ,(CONST BYTE*)szuser,strlen(szuser));
- }
- ShowAll(hParent,lv);
- return ifor;
- }
- }
- break;
- }
- return -1;
- }
- INT CRegistry::ReadValue(LPCTSTR key,const DWORD type,BYTE *lpData,DWORD sz){ //always suc
- ret=RegQueryValueEx(hkey,key,NULL,NULL,lpData,&sz);
- if(ret==ERROR_SUCCESS)
- return 1;
- return 0;
- }
- INT CRegistry::WriteValue(LPCTSTR key,const DWORD type,CONST BYTE *lpData,DWORD sz){ //always suc
- ret=RegSetValueEx(hkey,key,0,type,lpData,sz);
- if(ret==ERROR_SUCCESS)
- return 1;
- else
- return 0;
- }
- CRegistry::~CRegistry(void)
- {
- RegCloseKey(hkey);
- }
- LRESULT CALLBACK CRegistry::DlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam){
- switch(msg){
- case WM_INITDIALOG:
- SetDlgItemText(hDlg,IDC_USERNAME,(LPCTSTR)"unknown");
- return true;
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam)){
- case IDOK:
- GetDlgItemText(hDlg,IDC_USERNAME,(LPTSTR)szuser,sizeof(szuser));
- EndDialog(hDlg,IDOK);
- break;
- case IDCANCEL:
- EndDialog(hDlg,IDCANCEL);
- break;
- }
- break;
- }
- return false;
- }
- char CRegistry::szuser[20]={0};