// pointer to IMalloc LPMALLOC pMalloc = NULL; //Retrieves a pointer to the shell's IMalloc interface. if (SHGetMalloc(&pMalloc)==E_FAIL) { AfxMessageBox("IDS_ERR_SHGETMALLOC"); return; }
BROWSEINFO bi; ZeroMemory(&bi, sizeof(bi)); // Fill in the BROWSEINFO structure. bi.lpszTitle = "请选择"; bi.hwndOwner = m_hWnd; bi.pszDisplayName = lpBuffer; bi.ulFlags = BIF_NEWDIALOGSTYLE|BIF_DONTGOBELOWDOMAIN ; //Displays a dialog box that enables the user to select a shell folder. LPITEMIDLIST IIDList = SHBrowseForFolder(&bi); if(IIDList !=NULL) { //Converts an item identifier list to a file system path. SHGetPathFromIDList(IIDList, lpBuffer); pMalloc->Free(IIDList);
{ char lpBuffer[_MAX_PATH];
// pointer to IMalloc
LPMALLOC pMalloc = NULL;
//Retrieves a pointer to the shell's IMalloc interface.
if (SHGetMalloc(&pMalloc)==E_FAIL)
{
AfxMessageBox("IDS_ERR_SHGETMALLOC");
return;
}
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(bi));
// Fill in the BROWSEINFO structure.
bi.lpszTitle = "请选择";
bi.hwndOwner = m_hWnd;
bi.pszDisplayName = lpBuffer; bi.ulFlags = BIF_NEWDIALOGSTYLE|BIF_DONTGOBELOWDOMAIN ; //Displays a dialog box that enables the user to select a shell folder.
LPITEMIDLIST IIDList = SHBrowseForFolder(&bi);
if(IIDList !=NULL)
{
//Converts an item identifier list to a file system path.
SHGetPathFromIDList(IIDList, lpBuffer);
pMalloc->Free(IIDList);
CString strDirectory = CString(lpBuffer);
AfxMessageBox(strDirectory);
}
pMalloc->Release();
pMalloc = NULL;
}
{
cstring
filepathname;
cfiledialog dlg(true);///true为open对话框,false为save as对话框
if(dlg.domodal()==idok)
filepathname=dlg.getpathname();
}
相关信息:cfiledialog 用于取文件名的几个成员函数:
假如选择的文件是c:\windows\test.exe
则:
(1)getpathname();取文件名全称,包括完整路径。取回c:\windows\test.exe
(2)getfiletitle();取文件全名:test.exe
(3)getfilename();取回test
(4)getfileext();取扩展名exe
if(filedlg.domodal()==idok)//当操作者选择ok时,程序,取得选择文
//件的全路径名(包括文件的路径及文件名称),并将相应的数值传输给相
//关的控件变量。
{
m_filename=filedlg.getpathname();//m_filename是文件名称。
}