c++ MFC选择文件夹

c++ MFC选择文件夹

void openDir(){
    //选择文件夹	
	string _Path,root;
	TCHAR szDir[MAX_PATH];
	BROWSEINFO bi;
	ITEMIDLIST *pidl;
	bi.hwndOwner = this->m_hWnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = szDir;//这个是输出缓冲区   
	bi.lpszTitle = _T("文件夹:"); //标题  
	bi.ulFlags = BIF_NEWDIALOGSTYLE;//使用新的界面,在win7中效果较好//BIF_RETURNONLYFSDIRS;   
	bi.lpfn = NULL;
	bi.lParam = 0;
	bi.iImage = 0;
	pidl = SHBrowseForFolder(&bi);//弹出对话框   
	if (pidl == NULL)//点了取消,或者选择了无效的文件夹则返回NULL  
		return;

	if (SHGetPathFromIDList(pidl, szDir)) {
		int length = WideCharToMultiByte(CP_ACP, 0, szDir, -1, NULL, 0, NULL, NULL);
		char ch[] = "";
		WideCharToMultiByte(CP_ACP, 0, szDir, -1, ch, length, NULL, NULL);
		root = string(ch);
	}	
}

 

你可能感兴趣的:(MFC,C++)