class LboxCommdlg

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



コンストラクタに渡す引数は、オーナーウインドウのハンドルです

  
LboxDlg *Dlg;
LboxCommdlg *Commdlg;

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

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



  コンストラクタ



lpstrDefExt は、入力時に拡張子を省略した場合のデフォルトです(ピリオドは必要ありません)
以下は使用サンプルです

  
// コモンダイアログオブジェクト
Commdlg = new LboxCommdlg( );
Commdlg->lpstrFilter = "CSV,*.csv,全て,*.*";
Commdlg->lpstrDefExt = "csv";
  


  
// *********************************************************
// デフォルトコンストラクタ
// *********************************************************
LboxCommdlg::LboxCommdlg()
{
	LboxCommdlg::hWndOwner	= GetDesktopWindow();
	LboxCommdlg::lpstrTitle = NULL;
	LboxCommdlg::lpstrFilter = NULL;
	LboxCommdlg::nFilterIndex = 1;
	LboxCommdlg::Flags = 0;
	LboxCommdlg::uFolderFlg = BIF_RETURNONLYFSDIRS;
	LboxCommdlg::lpstrInitialDir = NULL;
	LboxCommdlg::lpstrDefExt = NULL;
	LboxCommdlg::lpfnHook = NULL;
}

// *********************************************************
// 拡張コンストラクタ
// *********************************************************
LboxCommdlg::LboxCommdlg( HWND hWnd )
{
	LboxCommdlg::hWndOwner	= hWnd;
	LboxCommdlg::lpstrTitle = NULL;
	LboxCommdlg::lpstrFilter = NULL;
	LboxCommdlg::nFilterIndex = 1;
	LboxCommdlg::Flags = 0;
	LboxCommdlg::uFolderFlg = BIF_RETURNONLYFSDIRS;
	LboxCommdlg::lpstrInitialDir = NULL;
	LboxCommdlg::lpstrDefExt = NULL;
	LboxCommdlg::lpfnHook = NULL;
}

// *********************************************************
// デストラクタ
// *********************************************************
LboxCommdlg::~LboxCommdlg()
{

}
  



  OpenFileName

  
// *********************************************************
// 読込むファイルのパスを取得する
// *********************************************************
BOOL LboxCommdlg::OpenFileName( LboxString& LString )
{
	return LboxCommdlg::OpenFileName( &LString );

}
BOOL LboxCommdlg::OpenFileName( LboxString *LString )
{
	LString->Resize( MAX_PATH );

	return LboxCommdlg::OpenFileName(
		LString->szLboxString
	);

}
BOOL LboxCommdlg::OpenFileName( LPTSTR lpstrFile )
{
	return LboxOpenFileName(
		LboxCommdlg::hWndOwner,
		LboxCommdlg::lpstrTitle,
		LboxCommdlg::lpstrFilter,
		LboxCommdlg::nFilterIndex,
		lpstrFile,
		LboxCommdlg::Flags,
		LboxCommdlg::lpstrInitialDir,
		LboxCommdlg::lpstrDefExt,
		LboxCommdlg::lpfnHook
	);
}
  



  SaveFileName

  
// *********************************************************
// 保存するファイルのパスを取得する
// *********************************************************
BOOL LboxCommdlg::SaveFileName( LboxString& LString )
{
	return LboxCommdlg::SaveFileName( &LString );

}
BOOL LboxCommdlg::SaveFileName( LboxString *LString )
{
	LString->Resize( MAX_PATH );

	return LboxCommdlg::SaveFileName(
		LString->szLboxString
	);

}
BOOL LboxCommdlg::SaveFileName(LPTSTR lpstrFile)
{
	return LboxSaveFileName(
		LboxCommdlg::hWndOwner,
		LboxCommdlg::lpstrTitle,
		LboxCommdlg::lpstrFilter,
		LboxCommdlg::nFilterIndex,
		lpstrFile,
		LboxCommdlg::Flags,
		LboxCommdlg::lpstrInitialDir,
		LboxCommdlg::lpstrDefExt,
		LboxCommdlg::lpfnHook
	);
}
  



  LboxOpenFileName

  
// *********************************************************
// 読込むファイルのパスを取得する
// *********************************************************
BOOL LboxOpenFileName(
	HWND		hwndOwner,
	LPCTSTR		lpstrTitle,
	LPCTSTR		lpstrFilter,
	DWORD		nFilterIndex,
	LPTSTR		lpstrFile,
	DWORD		Flags
)
{
	OPENFILENAME ofn;
	char szFilter[512];

	// メモリの初期化
	ZeroMemory( &ofn, sizeof( ofn ) );
	ZeroMemory( szFilter, sizeof( szFilter ) );

	// 環境
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hwndOwner;
	ofn.hInstance = NULL;

	// タイトル
	if ( lpstrTitle == NULL || 
		*lpstrTitle == 0x00 ) {
		ofn.lpstrTitle = "ファイルのパスの取得";
	}
	else {
		ofn.lpstrTitle = lpstrTitle;
	}

	// フィルタの設定
	unsigned char *pszToken;
	if ( lpstrFilter == NULL ||
		*lpstrFilter == 0x00 ) {
		lstrcpy( szFilter, "全て,*.*" );
	}
	else {
		lstrcpy( szFilter, lpstrFilter );
	}
	pszToken = _mbstok(
		(unsigned char *)szFilter,
		(const unsigned char *)","
	);
	while( pszToken != NULL ) {
		pszToken = _mbstok( NULL, (const unsigned char *)"," );
	}
	ofn.lpstrFilter = szFilter;
	if ( nFilterIndex == 0 ) {
		ofn.nFilterIndex = 1;
	}
	else {
		ofn.nFilterIndex = nFilterIndex;
	}

	// ファイルのパスが格納されるバッファ
	ofn.lpstrFile = lpstrFile;
	ofn.nMaxFile = MAX_PATH;

	// オプションフラグ
	if ( Flags == 0 ) {
		ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
	}
	else {
		ofn.Flags = Flags;
	}

	// API 関数の呼び出し
	BOOL ret;
	ret = GetOpenFileName( &ofn );
	if ( ret ) {
		return TRUE;
	}
	return FALSE;

}
  




  LboxSaveFileName

  
// *********************************************************
// 保存するファイルのパスを取得する
// *********************************************************
BOOL LboxSaveFileName(
	HWND		hwndOwner,
	LPCTSTR		lpstrTitle,
	LPCTSTR		lpstrFilter,
	DWORD		nFilterIndex,
	LPTSTR		lpstrFile,
	DWORD		Flags
)
{
	OPENFILENAME ofn;
	char szFilter[512];

	// メモリの初期化
	ZeroMemory( &ofn, sizeof( ofn ) );
	ZeroMemory( szFilter, sizeof( szFilter ) );

	// 環境
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hwndOwner;
	ofn.hInstance = NULL;

	// タイトル
	if ( lpstrTitle == NULL || 
		*lpstrTitle == 0x00 ) {
		ofn.lpstrTitle = "保存ファイルのパスの取得";
	}
	else {
		ofn.lpstrTitle = lpstrTitle;
	}

	// フィルタの設定
	unsigned char *pszToken;
	if ( lpstrFilter == NULL ||
		*lpstrFilter == 0x00 ) {
		lstrcpy( szFilter, "全て,*.*" );
	}
	else {
		lstrcpy( szFilter, lpstrFilter );
	}
	pszToken = _mbstok(
		(unsigned char *)szFilter,
		(const unsigned char *)","
	);
	while( pszToken != NULL ) {
		pszToken = _mbstok( NULL, (const unsigned char *)"," );
	}
	ofn.lpstrFilter = szFilter;
	if ( nFilterIndex == 0 ) {
		ofn.nFilterIndex = 1;
	}
	else {
		ofn.nFilterIndex = nFilterIndex;
	}

	// ファイルのパスが格納されるバッファ
	ofn.lpstrFile = lpstrFile;
	ofn.nMaxFile = MAX_PATH;

	// オプションフラグ
	if ( Flags == 0 ) {
		ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
	}
	else {
		ofn.Flags = Flags;
	}

	// API 関数の呼び出し
	BOOL ret;
	ret = GetSaveFileName( &ofn );
	if ( ret ) {
		return TRUE;
	}
	return FALSE;

}
  



  GetFolderName

  
// *********************************************************
// ディレクトリのパスを取得する
// *********************************************************
BOOL LboxCommdlg::GetFolderName( LboxString& LString )
{
	return LboxCommdlg::GetFolderName( &LString );
}
BOOL LboxCommdlg::GetFolderName( LboxString *LString )
{
	LString->Resize( MAX_PATH );

	return LboxCommdlg::GetFolderName(
		LString->szLboxString
	);

}
BOOL LboxCommdlg::GetFolderName( LPTSTR lpstrPath )
{
	BROWSEINFO bi;
	LPITEMIDLIST lpi;

	bi.hwndOwner = LboxCommdlg::hWndOwner;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = NULL;
	if ( LboxCommdlg::lpstrTitle == NULL ) {
		bi.lpszTitle = "ディレクトリの選択";
	}
	else {
		bi.lpszTitle = LboxCommdlg::lpstrTitle;
	}
	bi.ulFlags = LboxCommdlg::uFolderFlg;
	bi.lpfn = NULL;
	bi.lParam = 0;
	bi.iImage = 0;
	lpi = SHBrowseForFolder( &bi );
	if ( lpi != NULL ) {
		SHGetPathFromIDList( lpi, lpstrPath );
		return true;
	}
	else {
		return false;
	}
}
  



  GetFolderName の使用例

  
// ディレクトリ(ドライブ)変更
case IDM_GETFOLDER:
	if ( Commdlg->GetFolderName( szBuffer ) ) {
		Fs.ChangeDirectory( szBuffer );
		LoadFile( );
	}
	break
  
;










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





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

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ