2个回答
展开全部
win7 + vs2008 下通过:
#include <commdlg.h>
#include <shlobj.h>
///****************************************************************************
//获取文件路径对话框 (树目录,可以同时打开文件夹和文件)
//回调函数BrowseCallbackProc用于指定初始化目录为szDir
//****************************************************************************/
static
INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) // lParam member of the BROWSEINFO structure used in the call to SHBrowseForFolder
{
switch(uMsg)
{
case BFFM_INITIALIZED:
{
// WParam is TRUE since you are passing a path.
// It would be FALSE if you were passing a pidl.
// TCHAR szDir[MAX_PATH]={0};
// GetCurrentDirectory(sizeof(szDir)/sizeof(TCHAR), szDir);
// SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)"D:\\Qt\\Qt5.2.1_mingw48");
}
break;
case BFFM_SELCHANGED:
{
}
break;
}
return 0;
}
static
BOOL GetFilePath(TCHAR *FilePath,
HWND hParentWnd,
TCHAR* InstructionString=NULL, //提醒语句
UINT ulFlags=BIF_USENEWUI //BIF_USENEWUI拥有新特性,有新建文件夹按钮,可以调整大小,一般加上
|BIF_RETURNFSANCESTORS //Only return file system ancestors
|BIF_RETURNONLYFSDIRS //Only return file system directories
|BIF_BROWSEINCLUDEFILES//The browse dialog will display files as well as folders
)
{
BROWSEINFO bInfo={0};
bInfo.hwndOwner=hParentWnd;
bInfo.pszDisplayName=FilePath;
bInfo.lpszTitle=InstructionString;
bInfo.ulFlags= ulFlags;
bInfo.lpfn=BrowseCallbackProc; // bInfo.lpfn=NULL;
bInfo.lParam=0; // BrowseCallbackProc lpData
LPITEMIDLIST pidl= ::SHBrowseForFolder(&bInfo);
if (pidl == NULL)
return false;
if (::SHGetPathFromIDList(pidl,FilePath) == FALSE)
return false;
return true; //default return
}
//调用测试:
TCHAR FilePath[MAX_PATH]="D:\\Qt\\Qt5.2.1_mingw48";
if( GetFilePath(FilePath,hWnd,"请选择一个文件") )
{
::MessageBox(::GetFocus(),FilePath,"标题",MB_OK);
}
追问
谢谢了,不过我说的是VC6.0的……
追答
先编译一下,我记得以前也用过vc6 编译过这段代码 。好像要
#define _WIN32> 0x5000 之类的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询