各位大侠,
vc里面可以选中文件夹的窗口是
什么函数?
vc里面可以选中文件夹的窗口是
什么函数?
解决方案 »
- 增加了MSComm控件,做了一个串口通信
- 第一次做ActiveX控件,遇到几个问题,大家帮忙解答
- VC与数据库连接问题
- _CrtIsValidHeapPointer(pUserData)断言失败的原因?
- 关于模式对话框的问题
- 怎样修改activex控件的版本号??
- 初学问题100分:关于static控件
- 为什么我用CopyFile不能复制根目录下的文件,但可以复制根目录文件夹里的文件?
- 从文件中截取一块(如:10K),如何保证最后一个字不被分割?然后计算出正常块的size.
- 请问连接数据库是不是不安全
- 高分求高手,短信软件怎么写?
- 我已经没有分了,但是还得请教各位. 还希望各位大力帮忙(如何读取到一段文字后.抽取单个的汉字)
myDlg.DoModal();
HWND hWnd, LPCSTR lpszTitle, UINT nFlags)
{
// We're going to use the shell to display a
// "Choose Directory" dialog box for the user.
CString strResult = "";
LPMALLOC lpMalloc; // pointer to IMalloc
if (::SHGetMalloc(&lpMalloc) != NOERROR)
return strResult; // failed to get allocator char szDisplayName[_MAX_PATH];
char szBuffer[_MAX_PATH]; BROWSEINFO browseInfo;
browseInfo.hwndOwner = hWnd;
// set root at Desktop
browseInfo.pidlRoot = NULL;
browseInfo.pszDisplayName = "monkey";
browseInfo.lpszTitle = "monkey"; // passed in
browseInfo.ulFlags = BIF_EDITBOX; // also passed in
browseInfo.lpfn = NULL; // not used
browseInfo.lParam = 0; // not used
LPITEMIDLIST lpItemIDList; if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo))
!= NULL)
{
// Get the path of the selected folder from the
// item ID list.
if (::SHGetPathFromIDList(lpItemIDList, szBuffer))
{
// At this point, szBuffer contains the path
// the user chose.
if (szBuffer[0] == '\0')
{
// SHGetPathFromIDList failed, or
// SHBrowseForFolder failed.
//AfxMessageBox(IDP_FAILED_GET_DIRECTORY,
// MB_ICONSTOP|MB_OK);
return strResult;
}
// We have a path in szBuffer!
// Return it.
strResult = szBuffer;
return strResult;
}
else
{
// The thing referred to by lpItemIDList
// might not have been a file system object.
// For whatever reason, SHGetPathFromIDList
// didn't work!
//AfxMessageBox(IDP_FAILED_GET_DIRECTORY,
// MB_ICONSTOP|MB_OK);
return strResult; // strResult is empty
}
lpMalloc->Free(lpItemIDList);
lpMalloc->Release();
}// If we made it this far, SHBrowseForFolder failed.
return strResult;
}
result="NONE";BrowseInfo.hwndOwner=this->m_hWnd;BrowseInfo.pidlRoot=NULL;BrowseInfo.pszDisplayName=buf;BrowseInfo.lpszTitle="Please select a folder";BrowseInfo.ulFlags=BIF_BROWSEINCLUDEFILES|BIF_USENEWUI;// BrowseInfo.ulFlags=BIF_USENEWUI;BrowseInfo.lpfn=NULL;BrowseInfo.lParam=0;BrowseInfo.iImage=0;
CoInitialize(NULL);SHGetMalloc(&pMalloc);
pidlSelectedFolder = SHBrowseForFolder(&BrowseInfo);if (pidlSelectedFolder){hr = SHBindToParent(pidlSelectedFolder,IID_IShellFolder, (void **)
&psfParent, &pidlRelative);psfParent->GetDisplayNameOf(pidlRelative, SHGDN_INFOLDER, &strDispName);StrRetToBuf(&strDispName, pidlRelative, pszDisplayName, MAX_PATH);uAttr = SFGAO_FOLDER;psfParent->GetAttributesOf(1, (LPCITEMIDLIST *) &pidlRelative, &uAttr);if(uAttr & SFGAO_FOLDER)SHGetPathFromIDList(pidlSelectedFolder,pathbuff);else if (ReturnFile)SHGetPathFromIDList(pidlSelectedFolder,pathbuff);elseAfxMessageBox("You must select a folder");}else{ //user cancelledresult="CANCELED";pMalloc->Release();return result;}if (strlen(pathbuff) != 0 ){result = pathbuff;pMalloc->Free(pidlSelectedFolder);psfParent->Release();return result;}pMalloc->Release();return result;}
void CBackupRestore::OnButtonFindBackup()
{
BROWSEINFO info;
CString str_Path = "";
memset(&info, 0, sizeof info);
info.lpszTitle = "选择将要存放备份文件所在路径";
LPCITEMIDLIST pidl;
pidl = SHBrowseForFolder(&info);
if(pidl != NULL)
{
char pszPath[4096];
if(!SHGetPathFromIDList(pidl, pszPath))
return;
if(strlen(pszPath) < 3)
return;
str_Path = pszPath;
}
}
#include "Shlobj.h"
#pragma comment( lib , "Shell32.lib" )