【问题标题】:How to access the file name from the particular location using Listcontrol in MFC?如何使用 MFC 中的 Listcontrol 从特定位置访问文件名?
【发布时间】:2012-07-31 11:57:45
【问题描述】:

我是 Visual Studio C++ 的初学者。我正在使用 MFC 创建一个基于对话框的应用程序。我想读取一些文件并在对话框中显示该文件中的一些必需文本。

代码是:

   CFileFind finder;
    bool bFound;

   CString filename = "C:\\FilesLocation\\*.txt";

   bFound = finder.FindFile(filename);
   if(bFound) 
 {

   m_List.AddString(finder.GetFileName());  }

 in the last line,   error appears, whereas m_List is the member variable for List Control/

并且 Clistctrl 没有成员 Addstring。

如何获取文件名并在对话框中显示??

【问题讨论】:

    标签: visual-studio-2010 visual-c++ mfc


    【解决方案1】:

    根据您要达到的具体目标,使用CListCtrl::InsertItem 或使用CListBox 而不是CListCtrlCListBoxAddString 方法。

    【讨论】:

    • 我已经在做 ClistCtrl 功能了。我现在无法切换到 Clistbox。不了解 CListCtrl::InsertItem
    • @Nabeel:我在回答中提供了指向 MSDN 的链接。
    【解决方案2】:

    使用

    HANDLE WINAPI FindFirstFile(
      __in   LPCTSTR lpFileName,
      __out  LPWIN32_FIND_DATA lpFindFileData
    );
    

    在哪里

    pFileName [in] 目录或路径以及文件名,可以包含通配符,例如星号 (*) 或问号 (?)。

    lpFindFileData [out] 指向 WIN32_FIND_DATA 结构的指针,该结构接收有关找到的文件或目录的信息。

    WIN32_FIND_DATA ffd;
    HANDLE hFind = FindFirstFile(path of the directory,&ffd);
    if (INVALID_HANDLE_VALUE == hFind) 
        {
            return;
        } 
        else
        {
                    ffd.cFileName;
    
             }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 2020-08-22
      • 1970-01-01
      • 2019-06-26
      • 1970-01-01
      • 2011-12-01
      • 2019-08-16
      相关资源
      最近更新 更多