mfc中文件路径的获取

mfc中文件路径的获取,第1张

'm_File' : undeclared identifier ,没有这个变量,要先定义的类型的;

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()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11689503.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存