m_File 在类 .h 文件里面定义, CString m_File
或者直接在函数里面定义也可以
首先从对话框的按钮处理函数中获得mainframe指针cmainframe *pmain=(cmaimframe *)afxgetapp()->m_pmainwnd
然后获得相应视图指针cyourview *pview=(cyourview *)pmain->getactiveview()
最后获得视图对应的当前文档指针 cdocument * pcurrentdoc =(cframewnd *)m_pmainwnd->getactivedocument()
在MFC中,使用CFileFind类,可以枚举一个目录下的所有文件和子目录。
示例:
void ListFolder(const CString & sPath){
CFileFind ff
BOOL bFound = ff.FindFile(sPath + "\\*.*")
while(bFound)
{
bFound = ff.FindNextFile()
if(ff.IsDirectory()) //是目录
{
if(!ff.IsDots()) //不是本级目录或父目录(.和..)
ListFolder(ff.GetFilePath()) //递归子目录
}
else
{
AfxMessageBox("文件:" + ff.GetFilePath())
}
}
ff.Close()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)