class LboxInfo

  オブジェクトの作成と削除



LboxInfo は単独で作成しても良いですが、LboxDlg は LboxInfo を継承していますからその中で使用できます
( 実際は、LboxWin を経由して継承しています )

  
LboxDlg *Dlg;

LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message ) {
		case WM_INITDIALOG:
			Dlg = new LboxDlg( hDlg );
			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				Dlg->End( LOWORD(wParam) );
				delete Dlg;
			}
			break;
	}
	return FALSE;
}
  



  ComputerName



  
// *********************************************************
// コンピュータ名の取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : 失敗した場合は 0
// *********************************************************
int LboxInfo::ComputerName( LboxString *LString )
{
	int nLen;

	while( 1 ) {
		nLen = LboxInfo::ComputerName(
			LString->szLboxString,
			LString->nLboxString
		);
		if ( nLen == 0 ) {
			return nLen;
		}
		nLen = lstrlen( LString->szLboxString );
		if ( nLen >= (int)(LString->nLboxString) - 2 ) {
			if ( LString->nLboxString > LBOX_STRINGMAX ) {
				break;
			}
			LString->Resize( LString->nLboxString + 32 );
			continue;
		}
		break;
	}
	return nLen;

}
int LboxInfo::ComputerName( LPTSTR lpBuffer, int nSize )
{
	int ret;
	BOOL bRet;

	ret = nSize;
	bRet = GetComputerName(
		lpBuffer,  // コンピュータ名
		(LPDWORD)(&ret)
	);

	if ( bRet ) {
		return ret;
	}
	else {
		return 0;
	}
}
  



  UserName

  
// *********************************************************
// ユーザ名の取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : 失敗した場合は 0
// *********************************************************
int LboxInfo::UserName( LboxString *LString )
{
	int nLen;

	while( 1 ) {
		nLen = LboxInfo::UserName(
			LString->szLboxString,
			LString->nLboxString
		);
		if ( nLen == 0 ) {
			return nLen;
		}
		nLen = lstrlen( LString->szLboxString );
		if ( nLen >= (int)(LString->nLboxString) - 2 ) {
			if ( LString->nLboxString > LBOX_STRINGMAX ) {
				break;
			}
			LString->Resize( LString->nLboxString + 32 );
			continue;
		}
		break;
	}
	return nLen;

}
int LboxInfo::UserName( LPTSTR lpBuffer, int nSize )
{
	int ret;
	BOOL bRet;

	ret = nSize;
	bRet = GetUserName(
		lpBuffer,
		(LPDWORD)(&ret)
	);

	if ( bRet ) {
		return ret;
	}
	else {
		return 0;
	}
}
  



  WindowsDirectory

  
// *********************************************************
// Windows ディレクトリのパスを取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : 失敗した場合は 0
// *********************************************************
int LboxInfo::WindowsDirectory( LboxString *LString )
{
	UINT nLen;

	while( 1 ) {
		nLen = GetWindowsDirectory(
			LString->szLboxString,
			(UINT)(LString->nLboxString)
		);
		if ( nLen == 0 ) {
			return 0;
		}
		if ( (int)nLen >= (int)(LString->nLboxString) - 2 ) {
			if ( LString->nLboxString > LBOX_STRINGMAX ) {
				break;
			}
			LString->Resize( LString->nLboxString + MAX_PATH );
			continue;
		}
		break;
	}
	return (int)nLen;
}
int LboxInfo::WindowsDirectory( LPTSTR lpBuffer, int nSize )
{
	int ret;
	UINT uRet;

	uRet = GetWindowsDirectory(
		lpBuffer,
		0
	);
	if ( uRet > (UINT)nSize ) {
		return 0;
	}

	ret = (int)GetWindowsDirectory(
		lpBuffer,
		(UINT)nSize
	);

	return ret;
}
  



  SystemDirectory

  
// *********************************************************
// システムディレクトリのパスを取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : 失敗した場合は 0
// *********************************************************
int LboxInfo::SystemDirectory( LboxString *LString )
{
	int ret;
	UINT uRet;

	uRet = GetSystemDirectory(
		LString->szLboxString,
		0
	);
	if ( uRet > (UINT)(LString->nLboxString) ) {
		LString->Resize( uRet + 1 );
	}

	ret = (int)GetSystemDirectory(
		LString->szLboxString,
		(UINT)LString->nLboxString
	);

	return ret;
}
int LboxInfo::SystemDirectory( LPTSTR lpBuffer, int nSize )
{
	int ret;
	UINT uRet;

	uRet = GetSystemDirectory(
		lpBuffer,
		0
	);
	if ( uRet > (UINT)nSize ) {
		return 0;
	}

	ret = (int)GetSystemDirectory(
		lpBuffer,
		(UINT)nSize
	);

	return ret;
}
  



  CurrentDirectory

  
// *********************************************************
// カレントディレクトリのパスを取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : 失敗した場合は 0
// *********************************************************
int LboxInfo::CurrentDirectory( LboxString *LString )
{
	int ret;
	DWORD nRet;

	nRet = GetCurrentDirectory(
		0,
		LString->szLboxString
	);
	if ( nRet > LString->nLboxString ) {
		LString->Resize( nRet+1 );
	}

	ret = (int)GetCurrentDirectory(
		LString->nLboxString,
		LString->szLboxString
	);

	return ret;
}
int LboxInfo::CurrentDirectory( LPTSTR lpBuffer, int nSize )
{
	int ret;
	DWORD nRet;

	nRet = GetCurrentDirectory(
		0,
		lpBuffer
	);
	if ( nRet > (DWORD)nSize ) {
		return 0;
	}

	ret = (int)GetCurrentDirectory(
		(DWORD)nSize,
		lpBuffer
	);

	return ret;
}
  



  Date

  
// *********************************************************
// システム日付を文字列で取得(9999/99/99)
// 戻り値 : 無し
// *********************************************************
void LboxInfo::Date( LboxString *LString )
{
	if ( LString->nLboxString < 32 ) {
		LString->Resize( 32 );
	}
	LboxInfo::Date( LString->szLboxString );
}
void LboxInfo::Date( LPTSTR lpBuffer )
{
	SYSTEMTIME st;

	GetLocalTime(
		&st   // システム日時
	);

	wsprintf(
		lpBuffer,
		"%04d/%02d/%02d",
		st.wYear,
		st.wMonth,
		st.wDay
	);
}
  



  Time

  
// *********************************************************
// システム時刻を文字列で取得(99:99:99 999)
// 戻り値 : 無し
// *********************************************************
void LboxInfo::Time( LboxString *LString )
{
	if ( LString->nLboxString < 32 ) {
		LString->Resize( 32 );
	}
	LboxInfo::Time( LString->szLboxString );
}
void LboxInfo::Time( LPTSTR lpBuffer )
{
	SYSTEMTIME st;

	GetLocalTime(
		&st   // システム日時
	);

	wsprintf(
		lpBuffer,
		"%02d:%02d:%02d %03d",
		st.wHour,
		st.wMinute,
		st.wSecond,
		st.wMilliseconds
	);
}
  



  Dayofweek

  
// *********************************************************
// 現在の曜日を文字列で取得(日〜土)
// 戻り値 : 無し
// *********************************************************
void LboxInfo::Dayofweek( LboxString *LString )
{
	LboxInfo::Dayofweek( LString->szLboxString );
}
void LboxInfo::Dayofweek( LPTSTR lpBuffer )
{
	SYSTEMTIME st;

	GetLocalTime(
		&st   // システム日時
	);

	switch( st.wDayOfWeek ) {
		case 0:
			lstrcpy( lpBuffer, "日" );
			break;
		case 1:
			lstrcpy( lpBuffer, "月" );
			break;
		case 2:
			lstrcpy( lpBuffer, "火" );
			break;
		case 3:
			lstrcpy( lpBuffer, "水" );
			break;
		case 4:
			lstrcpy( lpBuffer, "木" );
			break;
		case 5:
			lstrcpy( lpBuffer, "金" );
			break;
		case 6:
			lstrcpy( lpBuffer, "土" );
			break;
	}

}
  



  Executable

  
// *********************************************************
// ファイルに対する実行プログラムの取得
// 戻り値 : 無し
// *********************************************************
BOOL LboxInfo::Executable( LboxString *LstrTarget, LboxString *LString )
{
	LString->Resize( MAX_PATH );
	return LboxInfo::Executable(
		LstrTarget->szLboxString,
		LString->szLboxString
	);
}
BOOL LboxInfo::Executable( LPCTSTR lpTarget, LPTSTR lpBuffer )
{
	HINSTANCE hRet;
	hRet = FindExecutable(
		lpTarget,
		NULL,
		lpBuffer
	);

	if ( (DWORD)hRet > 32 ) {
		return true;
	}
	else {
		return false;
	}

}
  



  VolumeName

  
// *********************************************************
// ドライブのボリューム名
// lpDrive には、"C:\\" のようにセット
// 戻り値 : 失敗した場合は 0
// *********************************************************
int LboxInfo::VolumeName( LPCTSTR lpDrive, LboxString *LString )
{
	int nLen;

	while( 1 ) {
		nLen = LboxInfo::VolumeName(
			lpDrive,
			LString->szLboxString,
			LString->nLboxString
		);
		if ( nLen == 0 ) {
			return nLen;
		}
		nLen = lstrlen( LString->szLboxString );
		if ( nLen >= (int)(LString->nLboxString) - 2 ) {
			if ( LString->nLboxString > LBOX_STRINGMAX ) {
				break;
			}
			LString->Resize( LString->nLboxString + 32 );
			continue;
		}
		break;
	}
	return nLen;

}
BOOL LboxInfo::VolumeName( LPCTSTR lpDrive, LPTSTR lpBuffer, int nSize )
{
	DWORD MaximumComponentLength,FileSystemFlags;

	return GetVolumeInformation(
		lpDrive,
		lpBuffer,
		(DWORD)nSize,
		NULL,
		&MaximumComponentLength,
		&FileSystemFlags,
		NULL,
		NULL
	);

}
  



  TempPath

  
// *********************************************************
// テンポラリ用のディレクトリパスを取得
// 戻り値 : 失敗した場合は 0,成功すると取得した文字列の長さ
// *********************************************************
int LboxInfo::TempPath( LboxString *LString )
{
	LString->Resize( MAX_PATH );
	return LboxInfo::TempPath(
		LString->szLboxString,
		LString->nLboxString
	);
}
int LboxInfo::TempPath( LPTSTR lpBuffer, int nSize )
{
	DWORD nRet;

	nRet = GetTempPath( (DWORD)nSize, lpBuffer );
	if ( nRet > (DWORD)nSize ) {
		return 0;
	}

	return (int)nRet;

}
  



  SpecialFolderPath

nTarget には、LboxConst のメンバ変数をパラメータヒントから選択します

  
// *********************************************************
// 特殊フォルダのパスを取得
// LBOX_SPFOLDER_STARTUP : スタートアップ
// 戻り値 : 失敗した場合は false,成功すると true
// *********************************************************
BOOL LboxInfo::SpecialFolderPath( int nTarget, LboxString *LString )
{
	LString->Resize( MAX_PATH );
	return LboxInfo::SpecialFolderPath(
		nTarget,
		LString->szLboxString
	);
}
BOOL LboxInfo::SpecialFolderPath( int nTarget, LPTSTR lpBuffer )
{
	HRESULT hRet;

	hRet = SHGetSpecialFolderPath(
		NULL,
		lpBuffer,
		nTarget,
		false
	);
	if ( hRet == NOERROR ) {
		return true;
	}

	return false;

}
  



  DateDiff

  
// *********************************************************
// 指定日からシステム日付までの経過日数
// 戻り値 : 無し
// *********************************************************
int LboxInfo::DateDiff( SYSTEMTIME *st )
{
	int nRet,nFrom,nTo;
	SYSTEMTIME stTo;
	SYSTEMTIME stNow;

	CopyMemory( &stTo, st, sizeof( SYSTEMTIME ) );
	GetLocalTime( &stNow );

	if ( stTo.wMonth == 1 ) {
		stTo.wYear = stTo.wYear - 1;
		stTo.wMonth = 13;
	}
	if ( stTo.wMonth == 2 ) {
		stTo.wYear = stTo.wYear - 1;
		stTo.wMonth = 14;
	}
	if ( stNow.wMonth == 1 ) {
		stNow.wYear = stNow.wYear - 1;
		stNow.wMonth = 13;
	}
	if ( stNow.wMonth == 2 ) {
		stNow.wYear = stNow.wYear - 1;
		stNow.wMonth = 14;
	}
	
	nFrom = 
		stNow.wYear * 365 + 
		stNow.wYear / 4 -
		stNow.wYear / 100 +
		stNow.wYear / 400 +
		30 * stNow.wMonth +
		( stNow.wMonth + 1 ) * 3 / 5 +
		stNow.wDay - 34;

	nTo = 
		stTo.wYear * 365 + 
		stTo.wYear / 4 -
		stTo.wYear / 100 +
		stTo.wYear / 400 +
		30 * stTo.wMonth +
		( stTo.wMonth + 1 ) * 3 / 5 +
		stTo.wDay - 34;

	nRet = nFrom - nTo;

	return nRet;
}
  



  SearchFromPath

  
// *********************************************************
// ファイル名だけで実行可能なディレクトリに存在する
// ファイルのフルパスを取得
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxInfo::SearchFromPath( LboxString *LFile, LboxString *LString )
{
	return SearchFromPath( LFile->szLboxString, LString );
}
BOOL LboxInfo::SearchFromPath( LPTSTR lpFile, LboxString *LString )
{
	LPTSTR lpDummy;
	DWORD nRet;

	if ( LString->nLboxString < MAX_PATH ) {
		LString->Resize( MAX_PATH );
	}
	nRet = SearchPath(
		NULL,
		lpFile,
		NULL,
		MAX_PATH,
		LString->szLboxString,
		&lpDummy
	);
	if ( nRet == 0 ) {
		return false;
	}

	return true;
}
  










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





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

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ