vs 建 单文档的 时候 或者 多文档的 时候 有专门的 demo
多文档的时候 视觉样式猛毕晌 和颜色枝锋 用 vs 2008
如数耐图
对应的类 CClassView
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)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)