📄 ini2.cpp
字号:
if(bGet)
n = (DWORD)GetInt(strEntry,nDefault/*=NULL*/,strSection/* = NULL*/);
else
WriteInt(strEntry,n, strSection/* = NULL*/);
}
void CIni::SerGetBool( BOOL bGet,BOOL & b, LPCTSTR strEntry,LPCTSTR strSection/* = NULL*/,BOOL bDefault/* = FALSE*/)
{
if(bGet)
b = GetBool(strEntry,bDefault/*=NULL*/,strSection/* = NULL*/);
else
WriteBool(strEntry,b, strSection/* = NULL*/);
}
void CIni::SerGetPoint( BOOL bGet,CPoint & pt, LPCTSTR strEntry, LPCTSTR strSection, CPoint ptDefault)
{
if(bGet)
pt = GetPoint(strEntry,ptDefault,strSection);
else
WritePoint(strEntry,pt, strSection);
}
void CIni::SerGetRect( BOOL bGet,CRect & rect, LPCTSTR strEntry, LPCTSTR strSection, CRect rectDefault)
{
if(bGet)
rect = GetRect(strEntry,rectDefault,strSection);
else
WriteRect(strEntry,rect, strSection);
}
void CIni::SerGetColRef( BOOL bGet,COLORREF & cr, LPCTSTR strEntry, LPCTSTR strSection, COLORREF crDefault)
{
if(bGet)
cr = GetColRef(strEntry,crDefault,strSection);
else
WriteColRef(strEntry,cr, strSection);
}
// 躡erladene Methoden //////////////////////////////////////////////////////////////////////////////////////////////////77
// Einfache Typen /////////////////////////////////////////////////////////////////////////////////////////////////////////
void CIni::SerGet( BOOL bGet,CString & str, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, LPCTSTR strDefault/*= NULL*/)
{
SerGetString(bGet,str,strEntry,strSection,strDefault);
}
void CIni::SerGet( BOOL bGet,double & f, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, double fDefault/* = 0.0*/)
{
SerGetDouble(bGet,f,strEntry,strSection,fDefault);
}
void CIni::SerGet( BOOL bGet,float & f, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, float fDefault/* = 0.0*/)
{
SerGetFloat(bGet,f,strEntry,strSection,fDefault);
}
void CIni::SerGet( BOOL bGet,int & n, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, int nDefault/* = 0*/)
{
SerGetInt(bGet,n,strEntry,strSection,nDefault);
}
void CIni::SerGet( BOOL bGet,short & n, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, int nDefault/* = 0*/)
{
int nTemp = n;
SerGetInt(bGet,nTemp,strEntry,strSection,nDefault);
n = nTemp;
}
void CIni::SerGet( BOOL bGet,DWORD & n, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, DWORD nDefault/* = 0*/)
{
SerGetDWORD(bGet,n,strEntry,strSection,nDefault);
}
void CIni::SerGet( BOOL bGet,WORD & n, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, DWORD nDefault/* = 0*/)
{
DWORD dwTemp = n;
SerGetDWORD(bGet,dwTemp,strEntry,strSection,nDefault);
n = dwTemp;
}
void CIni::SerGet( BOOL bGet,CPoint & pt, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, CPoint ptDefault/* = CPoint(0,0)*/)
{
SerGetPoint(bGet,pt,strEntry,strSection,ptDefault);
}
void CIni::SerGet( BOOL bGet,CRect & rect, LPCTSTR strEntry, LPCTSTR strSection/*= NULL*/, CRect rectDefault/* = CRect(0,0,0,0)*/)
{
SerGetRect(bGet,rect,strEntry,strSection,rectDefault);
}
void CIni::SerGet(BOOL bGet, CString *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, LPCTSTR Default/*=NULL*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, ar[i]);
if(ar[i].GetLength() == 0)
ar[i] = Default;
}
} else {
strBuffer = ar[0];
for(int i = 1; i < nCount; i++) {
strBuffer.AppendChar(_T(','));
strBuffer.Append(ar[i]);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet(BOOL bGet, double *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, double Default/* = 0.0*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
CString strTemp;
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, strTemp);
if(strTemp.GetLength() == 0)
ar[i] = Default;
else
ar[i] = _tstof(strTemp);
}
} else {
CString strTemp;
strBuffer.Format(_T("%g"), ar[0]);
for(int i = 1; i < nCount; i++) {
strTemp.Format(_T("%g"), ar[i]);
strBuffer.AppendChar(_T(','));
strBuffer.Append(strTemp);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet(BOOL bGet, float *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, float Default/* = 0.0*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
CString strTemp;
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, strTemp);
if(strTemp.GetLength() == 0)
ar[i] = Default;
else
ar[i] = (float)_tstof(strTemp);
}
} else {
CString strTemp;
strBuffer.Format(_T("%g"), ar[0]);
for(int i = 1; i < nCount; i++) {
strTemp.Format(_T("%g"), ar[i]);
strBuffer.AppendChar(_T(','));
strBuffer.Append(strTemp);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet(BOOL bGet, int *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, int Default/* = 0*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
CString strTemp;
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, strTemp);
if(strTemp.GetLength() == 0)
ar[i] = Default;
else
ar[i] = _tstoi(strTemp);
}
} else {
CString strTemp;
strBuffer.Format(_T("%d"), ar[0]);
for(int i = 1; i < nCount; i++) {
strTemp.Format(_T("%d"), ar[i]);
strBuffer.AppendChar(_T(','));
strBuffer.Append(strTemp);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet(BOOL bGet, unsigned char *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, unsigned char Default/* = 0*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
CString strTemp;
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, strTemp);
if(strTemp.GetLength() == 0)
ar[i] = Default;
else
ar[i] = (unsigned char)_tstoi(strTemp);
}
} else {
CString strTemp;
strBuffer.Format(_T("%d"), ar[0]);
for(int i = 1; i < nCount; i++) {
strTemp.Format(_T("%d"), ar[i]);
strBuffer.AppendChar(_T(','));
strBuffer.Append(strTemp);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet(BOOL bGet, short *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, int Default/* = 0*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
CString strTemp;
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, strTemp);
if(strTemp.GetLength() == 0)
ar[i] = Default;
else
ar[i] = (short)_tstoi(strTemp);
}
} else {
CString strTemp;
strBuffer.Format(_T("%d"), ar[0]);
for(int i = 1; i < nCount; i++) {
strTemp.Format(_T("%d"), ar[i]);
strBuffer.AppendChar(_T(','));
strBuffer.Append(strTemp);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet(BOOL bGet, DWORD *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, DWORD Default/* = 0*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
CString strTemp;
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, strTemp);
if(strTemp.GetLength() == 0)
ar[i] = Default;
else
ar[i] = (DWORD)_tstoi(strTemp);
}
} else {
CString strTemp;
strBuffer.Format(_T("%d"), ar[0]);
for(int i = 1; i < nCount; i++) {
strTemp.Format(_T("%d"), ar[i]);
strBuffer.AppendChar(_T(','));
strBuffer.Append(strTemp);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet(BOOL bGet, WORD *ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, DWORD Default/* = 0*/)
{
if(nCount > 0) {
CString strBuffer;
if(bGet) {
strBuffer = GetString(strEntry, _T(""), strSection);
CString strTemp;
int nOffset = 0;
for(int i = 0; i < nCount; i++) {
nOffset = Parse(strBuffer, nOffset, strTemp);
if(strTemp.GetLength() == 0)
ar[i] = Default;
else
ar[i] = (WORD)_tstoi(strTemp);
}
} else {
CString strTemp;
strBuffer.Format(_T("%d"), ar[0]);
for(int i = 1; i < nCount; i++) {
strTemp.Format(_T("%d"), ar[i]);
strBuffer.AppendChar(_T(','));
strBuffer.Append(strTemp);
}
WriteString(strEntry, strBuffer, strSection);
}
}
}
void CIni::SerGet( BOOL bGet,CPoint * ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, CPoint Default/* = CPoint(0,0)*/)
{
CString strBuffer;
for( int i=0 ; i<nCount ; i++)
{
strBuffer.Format(_T("_%i"),i);
strBuffer = strEntry + strBuffer;
SerGet(bGet,ar[i],strBuffer,strSection,Default);
}
}
void CIni::SerGet( BOOL bGet,CRect * ar, int nCount, LPCTSTR strEntry, LPCTSTR strSection/*=NULL*/, CRect Default/* = CRect(0,0,0,0)*/)
{
CString strBuffer;
for( int i=0 ; i<nCount ; i++)
{
strBuffer.Format(_T("_%i"),i);
strBuffer = strEntry + strBuffer;
SerGet(bGet,ar[i],strBuffer,strSection,Default);
}
}
int CIni::Parse(const CString& strIn, int nOffset, CString& strOut) {
strOut.Empty();
int nLength = strIn.GetLength();
if(nOffset < nLength) {
if(nOffset != 0 && strIn[nOffset] == _T(','))
nOffset++;
while(nOffset < nLength) {
if(!isspace(strIn[nOffset]))
break;
nOffset++;
}
while(nOffset < nLength) {
strOut += strIn[nOffset];
if(strIn[++nOffset] == _T(','))
break;
}
strOut.Trim();
}
return nOffset;
}
CString CIni::Read(LPCTSTR strFileName, LPCTSTR strSection, LPCTSTR strEntry, LPCTSTR strDefault)
{
CString strReturn;
GetPrivateProfileString(strSection,
strEntry,
strDefault,
strReturn.GetBufferSetLength(MAX_INI_BUFFER),
MAX_INI_BUFFER,
strFileName);
strReturn.ReleaseBuffer();
return strReturn;
}
void CIni::Write(LPCTSTR strFileName, LPCTSTR strSection, LPCTSTR strEntry, LPCTSTR strValue)
{
WritePrivateProfileString(strSection,
strEntry,
strValue,
strFileName);
}
BOOL CIni::GetBinary(LPCTSTR lpszEntry, BYTE** ppData, UINT* pBytes, LPCTSTR pszSection)
{
*ppData = NULL;
*pBytes = 0;
CString str = GetString(lpszEntry, NULL, pszSection);
if (str.IsEmpty())
return FALSE;
ASSERT(str.GetLength()%2 == 0);
INT_PTR nLen = str.GetLength();
*pBytes = UINT(nLen)/2;
*ppData = new BYTE[*pBytes];
for (int i=0;i<nLen;i+=2)
{
(*ppData)[i/2] = (BYTE)(((str[i+1] - 'A') << 4) + (str[i] - 'A'));
}
return TRUE;
}
BOOL CIni::WriteBinary(LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes, LPCTSTR pszSection)
{
// convert to string and write out
LPTSTR lpsz = new TCHAR[nBytes*2+1];
UINT i;
for (i = 0; i < nBytes; i++)
{
lpsz[i*2] = (TCHAR)((pData[i] & 0x0F) + 'A'); //low nibble
lpsz[i*2+1] = (TCHAR)(((pData[i] >> 4) & 0x0F) + 'A'); //high nibble
}
lpsz[i*2] = 0;
WriteString(lpszEntry, lpsz, pszSection);
delete[] lpsz;
return TRUE;
}
void CIni::DeleteKey(LPCTSTR pszKey)
{
WritePrivateProfileString(m_strSection, pszKey, NULL, m_strFileName);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -