|
|
// *********************************************************
// コンストラクタ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;
}
| |
|
|
RemoveSection, RemoveEntry |
|
|
// *********************************************************
// 初期化ファイル内の各種一覧データを取得する
// 戻り値 : バッファのポインタ
// 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;
}
| |
|
|
|
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 );
}
| |
|
|
|
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 );
}
| |
|
|
|
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 );
}
| |
|
|
|