Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How MFC enables configuration files (*. Ini) to save information?
How MFC enables configuration files (*. Ini) to save information?
In the program we write, there is always some configuration information that needs to be saved to complete the function of the program. The easiest way is to write this information into the INI file and read it in when the program is initialized. The specific application is as follows:

BOOL WritePrivateProfileString(

LPCTSTR lpAppName,

LPCTSTR lpKeyName,

LPCTSTR lpString,

LPCTSTR lpFileName

);

The meaning of each parameter.

LPCTSTR lpAppName is a field name in the INI file.

LPCTSTR lpKeyName is a key name under lpAppName, commonly known as variable name.

LPCTSTR lpString is a key value, that is, the value of a variable, but it must be of type lpctstr or CString.

LPCTSTR lpFileName is the complete INI file name. If the full pathname is not specified, the file will be found in the windows directory (default). If the file cannot be found, the function will create it in the windows directory.

CString strName,strTemp

int nAge

StrName= "Zhang San";

nAge = 12;

* WritePrivateProfileString(" StudentInfo "," Name ",strName," c:\ \ stud \ \ student . ini ");

At this point, the contents in the c: \ study \ student.ini file are as follows:

[Student Information]

Name = Zhang San

To save a student's age, simply change the integer value to the character type:

strTemp。 Format ("%d", nage);

* WritePrivateProfileString(" StudentInfo "," Age ",strTemp," c:\ \ stud \ \ student . ini ");