class LboxInifile

  コンストラクタ



  
// *********************************************************
// コンストラクタ1
// 現在実行しているプログラムのパスとファイル名を用いる
// *********************************************************
LboxInifile::LboxInifile()
{
	LboxInifile::szIniFilePath = NULL;
	char *szBuffer = new char[MAX_PATH];
	LboxGetProgramPath( szBuffer );
	PathRemoveExtension( szBuffer );
	lstrcat( szBuffer, ".ini" );
	LboxReAlloc(
		&(LboxInifile::szIniFilePath),
		lstrlen( szBuffer + 10 )
	);
	if ( LboxInifile::szIniFilePath != NULL ) {
		lstrcpy( LboxInifile::szIniFilePath, szBuffer );
	}
	delete [] szBuffer;
}
// *********************************************************
// コンストラクタ2
// 現在実行しているプログラムのパスと lpName を用いる
// *********************************************************
LboxInifile::LboxInifile( LPTSTR lpName )
{
	LboxInifile::szIniFilePath = NULL;
	char *szBuffer = new char[MAX_PATH];
	LboxGetProgramPath( szBuffer );
	PathRemoveFileSpec( szBuffer );
	PathAddBackslash( szBuffer );
	lstrcat( szBuffer, lpName );
	lstrcat( szBuffer, ".ini" );
	LboxReAlloc(
		&(LboxInifile::szIniFilePath),
		lstrlen( szBuffer + 10 )
	);
	if ( LboxInifile::szIniFilePath != NULL ) {
		lstrcpy( LboxInifile::szIniFilePath, szBuffer );
	}
	delete [] szBuffer;
}
// *********************************************************
// コンストラクタ3
// lpPath が "WINDOWS" の場合はウインドウズディレクトリ
// lpPath が "SYSTEM" の場合はシステムディレクトリ
// それ以外の場合は lpPath をディレクトリに用い、
// ファイル名部分は lpName を用いる
// *********************************************************
LboxInifile::LboxInifile( LPTSTR lpPath, LPTSTR lpName )
{
	LboxInifile::szIniFilePath = NULL;
	char *szBuffer = new char[MAX_PATH];
	if ( lstrcmpi( lpPath, "WINDOWS" ) == 0 ) {
		GetWindowsDirectory( szBuffer, MAX_PATH );
	}
	if ( lstrcmpi( lpPath, "SYSTEM" ) == 0 ) {
		GetSystemDirectory( szBuffer, MAX_PATH );
	}
	if ( lstrcmpi( lpPath, "WINDOWS" ) != 0 && 
		lstrcmpi( lpPath, "SYSTEM" ) != 0 ) {
		lstrcpy( szBuffer, lpPath );
	}
	PathAddBackslash( szBuffer );
	lstrcat( szBuffer, lpName );
	lstrcat( szBuffer, ".ini" );
	LboxReAlloc(
		&(LboxInifile::szIniFilePath),
		lstrlen( szBuffer + 10 )
	);
	if ( LboxInifile::szIniFilePath != NULL ) {
		lstrcpy( LboxInifile::szIniFilePath, szBuffer );
	}
	delete [] szBuffer;
}
  



  WriteString



  
// *********************************************************
// 文字列を書き込み
// 戻り値 : 無し
// *********************************************************
void LboxInifile::WriteString( LPTSTR lpSection, LPTSTR lpEntry, LPTSTR lpValue )
{
	WritePrivateProfileString(
		lpSection,
		lpEntry,
		lpValue,
		LboxInifile::szIniFilePath
	);
}
  



  GetString

  
// *********************************************************
// 文字列を読み込み
// 戻り値 : 無し
// *********************************************************
void LboxInifile::GetString(
LPTSTR lpSection, LPTSTR lpEntry, LPTSTR lpDefault, LPTSTR lpValue, DWORD nSize )
{
	GetPrivateProfileString(
		lpSection,
		lpEntry,
		lpDefault,
		lpValue,
		nSize,
		LboxInifile::szIniFilePath
	);
}
  



  RemoveSection, RemoveEntry

  
// *********************************************************
// セクションを削除
// 戻り値 : 無し
// *********************************************************
void LboxInifile::RemoveSection( LPTSTR lpSection )
{
	if ( lpSection == NULL ) {
		return;
	}
	WritePrivateProfileString(
		lpSection,
		NULL,
		NULL,
		LboxInifile::szIniFilePath
	);
}

// *********************************************************
// エントリ(キー)を削除
// 戻り値 : 無し
// *********************************************************
void LboxInifile::RemoveEntry( LPTSTR lpSection, LPTSTR lpEntry )
{
	if ( lpSection == NULL ) {
		return;
	}
	if ( lpEntry == NULL ) {
		return;
	}
	WritePrivateProfileString(
		lpSection,
		lpEntry,
		NULL,
		LboxInifile::szIniFilePath
	);
}
  



  初期化ファイル内の各種一覧データを取得する

  
// *********************************************************
// 初期化ファイル内の各種一覧データを取得する
// 戻り値 : バッファのポインタ
// nType
// 0 : セクション名一覧
// 1 : エントリ(キー)名一覧
// 2 : エントリ(キー)名と値の一覧
// *********************************************************
LPTSTR LboxInifileGetEnum( int nType, LPTSTR lpTarget, LPTSTR lpFile )
{
	LPTSTR lpBuffer;
	DWORD nSize,dwRet;

	nSize = 1024;
	lpBuffer = NULL;
	while( 1 ) {
		LboxReAlloc( &lpBuffer, nSize + 10 );
		if ( lpBuffer == NULL ) {
			return NULL;
		}
		if ( nType == 0 ) {
			dwRet = GetPrivateProfileSectionNames(
				lpBuffer,
				nSize,
				lpFile
			);
		}
		if ( nType == 1 ) {
			dwRet = GetPrivateProfileString(
				lpTarget,
				NULL,
				"",
				lpBuffer,
				nSize,
				lpFile
			);
		}
		if ( nType == 2 ) {
			dwRet = GetPrivateProfileSection(
				lpTarget,
				lpBuffer,
				nSize,
				lpFile
			);
		}
		if ( dwRet == (nSize - 2) ) {
			nSize += 1024;
		}
		else {
			break;
		}
	}

	return lpBuffer;
}
  



  GetSectionNames

LboxInifileGetEnum

  
// *********************************************************
// セクション名の一覧をリストボックスにセット
// 戻り値 : 無し
// *********************************************************
void LboxInifile::GetSectionNames( HWND hTarget, int nIndex )
{
	LPTSTR lpBuffer;

	lpBuffer = LboxInifileGetEnum(
		0,
		NULL,
		LboxInifile::szIniFilePath
	);
	if ( lpBuffer == NULL ) {
		return;
	}

	int nPos;
	nPos = 0;
	if ( lpBuffer[nPos] != 0x00 ) {
		LboxListInsert( hTarget, nIndex, lpBuffer );
		nPos++;
		while( 1 ) {
			if ( lpBuffer[nPos] == 0x00 ) {
				if ( lpBuffer[nPos+1] == 0x00 ) {
					break;
				}
				else {
					nIndex++;
					LboxListInsert(
						hTarget,
						nIndex,
						lpBuffer + nPos + 1
					);
				}
			}
			nPos++;
		}
	}

	GlobalFree( (HGLOBAL)lpBuffer );
}

// *********************************************************
// セクション名の一覧をトークンオブジェクトにセット
// 戻り値 : 無し
// *********************************************************
void LboxInifile::GetSectionNames( LboxToken *obj )
{
	LPTSTR lpBuffer;

	lpBuffer = LboxInifileGetEnum(
		0,
		NULL,
		LboxInifile::szIniFilePath
	);
	if ( lpBuffer == NULL ) {
		return;
	}

	int nPos;
	nPos = 0;
	while( 1 ) {
		if ( lpBuffer[nPos] == 0x00 ) {
			lpBuffer[nPos] = 0x1a;
			if ( lpBuffer[nPos+1] == 0x00 ) {
				break;
			}
		}
		nPos++;
	}

	char szDelim[4];
	szDelim[0] = 0x1a;
	szDelim[1] = 0x00;
	obj->CreateToken( lpBuffer, szDelim );

	GlobalFree( (HGLOBAL)lpBuffer );
}
  



  GetEntryNames

LboxInifileGetEnum

  
// *********************************************************
// 指定したセクションのエントリ(キー)名の一覧を
// リストボックスにセット
// 戻り値 : 無し
// *********************************************************
void LboxInifile::GetEntryNames( LPTSTR lpSection, HWND hTarget, int nIndex )
{
	LPTSTR lpBuffer;

	lpBuffer = LboxInifileGetEnum(
		1,
		lpSection,
		LboxInifile::szIniFilePath
	);
	if ( lpBuffer == NULL ) {
		return;
	}

	int nPos;
	nPos = 0;
	if ( lpBuffer[nPos] != 0x00 ) {
		LboxListInsert( hTarget, nIndex, lpBuffer );
		nPos++;
		while( 1 ) {
			if ( lpBuffer[nPos] == 0x00 ) {
				if ( lpBuffer[nPos+1] == 0x00 ) {
					break;
				}
				else {
					nIndex++;
					LboxListInsert(
						hTarget,
						nIndex,
						lpBuffer + nPos + 1
					);
				}
			}
			nPos++;
		}
	}

	GlobalFree( (HGLOBAL)lpBuffer );
}

// *********************************************************
// 指定したセクションのエントリ(キー)名の一覧を
// トークンオブジェクトにセット
// 戻り値 : 無し
// *********************************************************
void LboxInifile::GetEntryNames( LPTSTR lpSection, LboxToken *obj )
{
	LPTSTR lpBuffer;

	lpBuffer = LboxInifileGetEnum(
		1,
		lpSection,
		LboxInifile::szIniFilePath
	);
	if ( lpBuffer == NULL ) {
		return;
	}

	int nPos;
	nPos = 0;
	while( 1 ) {
		if ( lpBuffer[nPos] == 0x00 ) {
			lpBuffer[nPos] = 0x1a;
			if ( lpBuffer[nPos+1] == 0x00 ) {
				break;
			}
		}
		nPos++;
	}

	char szDelim[4];
	szDelim[0] = 0x1a;
	szDelim[1] = 0x00;
	obj->CreateToken( lpBuffer, szDelim );

	GlobalFree( (HGLOBAL)lpBuffer );
}
  



  GetEntryNamesX

LboxInifileGetEnum

  
// *********************************************************
// 指定したセクションのエントリ(キー)名と値の一覧を
// リストボックスにセット
// 戻り値 : 無し
// *********************************************************
void LboxInifile::GetEntryNamesX( LPTSTR lpSection, HWND hTarget, int nIndex )
{
	LPTSTR lpBuffer;

	lpBuffer = LboxInifileGetEnum(
		2,
		lpSection,
		LboxInifile::szIniFilePath
	);
	if ( lpBuffer == NULL ) {
		return;
	}

	int nPos;
	nPos = 0;
	if ( lpBuffer[nPos] != 0x00 ) {
		LboxListInsert( hTarget, nIndex, lpBuffer );
		nPos++;
		while( 1 ) {
			if ( lpBuffer[nPos] == 0x00 ) {
				if ( lpBuffer[nPos+1] == 0x00 ) {
					break;
				}
				else {
					nIndex++;
					LboxListInsert(
						hTarget,
						nIndex,
						lpBuffer + nPos + 1
					);
				}
			}
			nPos++;
		}
	}

	GlobalFree( (HGLOBAL)lpBuffer );
}

// *********************************************************
// セクション内のエントリ(キー)と値の一覧を
// トークンオブジェクトにセット
// 戻り値 : 無し
// *********************************************************
void LboxInifile::GetEntryNamesX( LPTSTR lpSection, LboxToken *obj )
{
	LPTSTR lpBuffer;

	lpBuffer = LboxInifileGetEnum(
		2,
		lpSection,
		LboxInifile::szIniFilePath
	);
	if ( lpBuffer == NULL ) {
		return;
	}

	int nPos;
	nPos = 0;
	while( 1 ) {
		if ( lpBuffer[nPos] == 0x00 ) {
			lpBuffer[nPos] = 0x1a;
			if ( lpBuffer[nPos+1] == 0x00 ) {
				break;
			}
		}
		nPos++;
	}

	char szDelim[4];
	szDelim[0] = 0x1a;
	szDelim[1] = 0x00;
	obj->CreateToken( lpBuffer, szDelim );

	GlobalFree( (HGLOBAL)lpBuffer );
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ