3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VC++ のフォルダ選択ダイアログ

Posted at

VC++ のフォルダ選択ダイアログ

VisualC++ でダイアログから フォルダを選択しようと思い 調べていたら SHBrowseForFolder に関する情報があったので使ってみたが、UIが古い上に インプリも難しい。
CFileDialog に似たものはないか調べていたら、、、何のことは無い、とても便利なクラスが用意されていた。

1. フォルダ選択ダイアログ CFolderPickerDialog

    CFolderPickerDialog dlg;
	if( dlg.DoModal() != IDOK )
		return;

    CStringW fileNameW = dlg.GetPathName() ;

2. おまけ

ファイル選択ダイアログのファイルフィルタ

CFileDialog でフィルタ条件を 追加した時のサンプル

	CStringW ffilter ;
	ffilter  = L"all files (*.*)|*.*|" ;
	ffilter += L"text file (*.txt)|*.txt|" ;
	ffilter += L"csv file (*.csv)|*.csv|" ;
	ffilter += L"cpp source (*.cpp)|*.cpp|" ;
	ffilter += L"c  header (*.h)|*.h|" ;

    CFileDialog dlg(TRUE, L"cpp", L"*.cpp", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, ffilter ) ;
	if( dlg.DoModal() != IDOK )
		return ;

    CStringW fileNameW = dlg.GetPathName() ;
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?