📄 nfunction.cpp
字号:
// nFunction.cpp File
#include "stdafx.h"
#include <afxdllx.h>
#include "nFunction.h"
CString GetGameName( CString strGameType, int i)
{
char m_szGame[64], m_GameBuf[64]; int m_ChkCount;
sprintf( m_szGame, "Game%d", i);
// 读取游戏名称
m_ChkCount = GetPrivateProfileString( strGameType, m_szGame, "", m_GameBuf, sizeof(m_GameBuf), "INIS\\GameName.ini");
if( 0 == m_ChkCount)
{
CString m_str = "";
return m_str;
}
else
{
CString m_str = m_GameBuf;
return m_str;
}
}
CString GetGameRoom( CString strGameName, int j)
{
char m_szRoom[64], m_RoomBuf[64]; int m_ChkCount;
sprintf( m_szRoom, "Room%d", j);
// 读取游戏名称
m_ChkCount = GetPrivateProfileString( strGameName, m_szRoom, "", m_RoomBuf, sizeof(m_RoomBuf), "INIS\\GameRoom.ini");
if( 0 == m_ChkCount)
{
CString m_str = "";
return m_str;
}
else
{
CString m_str = m_RoomBuf;
return m_str;
}
}
DWORD RegReadData(HKEY hKey, LPCTSTR lpValueName, DWORD dwDefault = 0)
{
if (hKey)
{
LONG lResult = 0;
DWORD dwValue = 0;
DWORD dwType = REG_DWORD;
DWORD dwSize = sizeof(DWORD);
lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE)&dwValue, &dwSize);
return (lResult == ERROR_SUCCESS) ? dwValue : dwDefault;
}
return 0;
}
BOOL RegReadData(HKEY hKey, LPCTSTR lpValueName, LPTSTR lpString, int nLen)
{
if (hKey)
{
ZeroMemory(lpString, nLen);
LONG lResult = 0;
DWORD dwValue = 0;
DWORD dwType = REG_SZ;
DWORD dwSize = nLen;
lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE)lpString, &dwSize);
return (lResult == ERROR_SUCCESS) ? dwValue : 0;
}
return 0;
}
LPTSTR LoadGamePath( LPCTSTR lpKey, LPCTSTR lpPath)
{
HKEY hKey = NULL;
DWORD dwResult = 0;
LPTSTR m_lpStrGamePath;
if (RegCreateKeyEx(HKEY_CURRENT_USER, lpPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, &hKey, &dwResult) == ERROR_SUCCESS)
{
//TCHAR lpBuf[128] = lpPath;
char lpBuf[128];
strcpy(lpBuf, lpPath);
//_stprintf(lpBuf, _T("lpText_%d"), i + 1);
RegReadData(hKey, lpKey, m_lpStrGamePath, 128);
RegCloseKey( hKey);
}
return m_lpStrGamePath;
}
BOOL RegWriteData(HKEY hKey, LPCTSTR lpValueName, DWORD dwData)
{
if (hKey)
{
return (RegSetValueEx(hKey, lpValueName, 0, REG_DWORD,
(LPBYTE)&dwData, sizeof(DWORD)) == ERROR_SUCCESS);
}
return FALSE;
}
BOOL RegWriteData(HKEY hKey, LPCTSTR lpValueName, LPCTSTR lpString)
{
if (hKey)
{
return (RegSetValueEx(hKey, lpValueName, 0, REG_SZ, (LPBYTE)lpString, _tcslen(lpString) * sizeof(TCHAR)) == ERROR_SUCCESS);
}
return FALSE;
}
void SaveGamePath( LPCTSTR lpKey, LPCTSTR lpPath)
{
HKEY hKey = NULL;
DWORD dwResult = 0;
if (RegCreateKeyEx(HKEY_CURRENT_USER, lpPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &dwResult) == ERROR_SUCCESS)
{
TCHAR lpBuf[128];
strcpy(lpBuf, lpKey);
//_stprintf(lpBuf, _T("lpText_%d"), i + 1);
RegWriteData(hKey, lpBuf, lpPath);
RegCloseKey(hKey);
}
}
void testReg(int x)
{
if(x == 1)
{
TCHAR lpBuf[128];
_stprintf(lpBuf, _T("%sGamePath"), REG_ROOT);
LoadGamePath( "CS1.5", lpBuf);
}
if(x == 0)
{
TCHAR lpBuf[128];
_stprintf(lpBuf, _T("%sGamePath"), REG_ROOT);
SaveGamePath( "CS1.5", lpBuf);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -