1、选择文件并获取相应的路径
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = _T("所有文件\0*.*");
ofn.nFilterIndex = 1;
ofn.lpstrFile = FileName;
ofn.nMaxFile = sizeof(FileName);
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = TEXT("请选择文件");
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NODEREFERENCELINKS;
//ofn.hwndOwner = hWnd;
if (GetOpenFileName(&ofn))
{
}
2、选择文件夹获取对应的路径
BROWSEINFO bi;
bi.hwndOwner = NULL;
bi.pidlRoot = CSIDL_DESKTOP;
bi.pszDisplayName = NULL;
bi.lpszTitle = NULL;
bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lpfn = NULL;
LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);
if (pIDList)
{
SHGetPathFromIDList(pIDList, szResult);
}