Bool ctest1_dlg: readini () // read ini
{
Char filepath [max_path];
Char databuf [1024];
: Getcurrentdirectory (max_path, filepath );
Strcat (filepath ,"\\");
Strcat (filepath, "config. ini ");
Int COUNT = calccount (); // counts the number of existing segments in the INI file. For details, see the following.
Cstring secname = "section ";
Cstring temp;
Temp. Format ("% d", Count-1 );
Secname + = temp;
: Getprivateprofilestring (secname, "User ID", "", databuf, 1024, filepath );
M_username = databuf;
: Getprivateprofilestring (secname, "password", "", databuf, 1024, filepath );
M_passwd = databuf;
Return false;
}
Bool ctest1_dlg: writeini () // write ini
{
Char filepath [max_path];
: Getcurrentdirectory (max_path, filepath );
Strcat (filepath ,"\\");
Strcat (filepath, "config. ini ");
Int COUNT = calccount (); // same as above
Cstring secname = "section ";
Cstring temp;
Temp. Format ("% d", count );
Secname + = temp;
: Writeprivateprofilestring (secname, "User ID", m_username, filepath );
: Writeprivateprofilestring (secname, "password", m_passwd, filepath );
Return true;
}
Int ctest1_dlg: calccount ()
{
Char chsectionnames [1024] = {0 };
Char * psectionname; // Save the first address of a specified node name string
Int I; // point to a location of the array chsectionnames, starting from 0, with sequential descendant
Int J = 0; // used to save the first address of the string of the next node name
Int COUNT = 0; // count the number of nodes.
: Getprivateprofilesectionnames (chsectionnames, 1024, ". \ config. ini ");
For (I = 0; I <1024; I ++, J ++)
{
If ('\ 0' = chsectionnames [0])
Break;
If ('\ 0' = chsectionnames [I])
{
Psectionname = & chsectionnames [I-j];
J =-1;
// Afxmessagebox (psectionname );
Count ++;
If ('\ 0' = chsectionnames [I + 1])
{
Break;
}
}
}
Return count;
}