HKEY key;
CString sKeyPath;
SKeyPath = "Software // SoftTryTimeTest ";
If (RegOpenKey (HKEY_CURRENT_USER, sKeyPath, & key )! = 0
& RegOpenKey (HKEY_CURRENT_USER, sKeyPath, & key )! = ERROR_SUCCESS
) // Used for the first time
{
// Record the number of times used in the Registry
: RegCreateKey (HKEY_CURRENT_USER, sKeyPath, & key );
: RegSetValueEx (key, "Try time", 0, REG_SZ, (unsigned char *) "5", 2 );
: RegCloseKey (key );
MessageBox ("You can only use five times", "system prompt", MB_ OK | MB_ICONEXCLAMATION );
}
Else // registry information already exists
{
CString sTryTime;
Int nTryTime;
LPBYTE Data = new BYTE [80];
Dword type = REG_SZ;
DWORD cbData = 80;
// Retrieve the number of times used
: RegQueryValueEx (key, "Try time", 0, & TYPE, Data, & cbData );
STryTime. Format ("% s", Data );
NTryTime = atoi (sTryTime );
If (nTryTime <1)
{
MessageBox ("the maximum number of trials has passed", "system prompt", MB_ OK | MB_ICONSTOP );
Return false;
}
NTryTime --;
STryTime. Format ("% d", nTryTime );
: RegSetValueEx (key, "Try time"
, 0, REG_SZ
, (Unsigned char *) sTryTime. GetBuffer (sTryTime. GetLength ())
, 2 );
: RegCloseKey (key );
MessageBox ("You can try again" + sTryTime + "times! "," System prompt ", MB_ OK | MB_ICONEXCLAMATION );
}