但是宏信衡如果提问者说的是路径选择对话框则应是蔽做如下代坦燃码(代码中采用控制台的形式给出SHBrowseForFolder()的用法):
#include <stdio.h>
#include <Windows.h>
#include <shlobj.h>
int main()
{
BROWSEINFO stInfo = {NULL}
LPCITEMIDLIST pIdlst
TCHAR szPath[MAX_PATH]
stInfo.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_USENEWUI
stInfo.lpszTitle= "请选择路径:"
pIdlst = SHBrowseForFolder(&stInfo)
if(!pIdlst) return 1
if(!SHGetPathFromIDList(pIdlst, szPath)) return 1
printf(szPath)
return 0
}
选择所选择的文件夹,获取文件夹的路辩烂径:CString
m_FileDir
BROWSEINFO
bi
ZeroMemory(&bi,
sizeof(BROWSEINFO))
bi.hwndOwner
=
m_hWnd
bi.ulFlags
=
BIF_RETURNONLYFSDIRS
LPITEMIDLIST
pidl
=
SHBrowseForFolder(&bi)
BOOL
bRet
=
FALSE
TCHAR
szFolder[MAX_PATH*2]
szFolder[0]
=
_T('')
if
(pidl)
{
if
(SHGetPathFromIDList(pidl,
szFolder))
bRet
=
TRUE
IMalloc
*pMalloc
=
NULL
if
(SUCCEEDED(SHGetMalloc(&pMalloc))
&&
pMalloc)
{
pMalloc->Free(pidl)
pMalloc->Release()
}
}
m_FileDir
=
szFolder//选择的者携文件夹路径
查找所有MDB文件(记录数组自己写吧)
CFileFind
ff
BOOL
res
=
ff.FindFile(m_FileDir+"*.mdb")
while(res)
{
res
=
ff.FindNextFile()
//不遍历子目录
if(!ff.IsDirectory()
&&
!ff.IsDots())
{
CString
strFile
=
ff.GetFileName()
…//
在这里写需要的代码
}
}
ff.Close()
//
不携嫌漏要忘记关闭
BROWSEINFO bInfoZeroMemory(&bInfo, sizeof(bInfo))
bInfo.hwndOwner =GetSafeHwnd()
bInfo.lpszTitle = _T("请选择需要监视文件夹的路径: ")
bInfo.ulFlags = BIF_RETURNONLYFSDIRS
LPITEMIDLIST lpDlist//用来保存返回信息的IDList
lpDlist = SHBrowseForFolder(&bInfo) //显示选择对话框
if(lpDlist != NULL) //用户按了确定按钮
{
TCHAR chPath[MAX_PATH]//用来存储路径的字符串
SHGetPathFromIDList(lpDlist, chPath)//把喊乱项目标识列孝渗段表转化成字符串
CString m_strPath = chPath//将巧誉TCHAR类型的字符串转换为CString类型的字符串
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)