编程模仿Windows资源管理器, 用TreeCtrl显示文件目录树,ListCtrl显示文件列表。在TreeCtrl部份,
当目录有变化时(如何被其它程序删除、改名或新生成目录等)如何自动刷新目录树?要求:刷新接近WINDOWS资源管理器刷新效果。1、刷新前已展开的项刷新后仍为展开状态。
2、刷新前被选择的项,如果其对应目录未出现变化,则刷新后仍为选中状态。如果出现变化则其上级目录将被选中。
3、刷新时间尽可能的短。分不够可再加!现成的类更好!

解决方案 »

  1.   

    http://www.codeproject.com/file/filewatch.asp监控文件的改变.
      

  2.   

    DO NOT REFRESH DIRECTORY TREEVIEW SO OFTEN
    删除文件夹的时候可以删除节点,但是新增的时候建议不要同时刷新……看看资源管理器怎么干的
      

  3.   

    MFC编程扩展实例上面有这个例子,编号为:43
    可以看看。但这个实例程序没有将目录的功能添加进来。
    但能够实现刷新。
    给我来信,我把源代码给你。[email protected]
    请注明你是谁,要什么例子。因为来信太多了。我都快分不清楚来信的目的了。
      

  4.   

    coyer(网中一虫) :
    源码已收到. 谢谢!
      

  5.   

    有几种办法:
    win32中,FindFirstChangeNotification,但是缺点是有限的记录,并且信息不完善。但是对于你的东西,应该也够用了。msdn例子:DWORD dwWaitStatus; 
    HANDLE dwChangeHandles[2]; 
     
    // Watch the C:\WINDOWS directory for file creation and 
    // deletion. 
     
    dwChangeHandles[0] = FindFirstChangeNotification( 
        "C:\\WINDOWS",                 // directory to watch 
        FALSE,                         // do not watch the subtree 
        FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes 
     
    if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) 
        ExitProcess(GetLastError()); 
     
    // Watch the C:\ subtree for directory creation and 
    // deletion. 
     
    dwChangeHandles[1] = FindFirstChangeNotification( 
        "C:\\",                        // directory to watch 
        TRUE,                          // watch the subtree 
        FILE_NOTIFY_CHANGE_DIR_NAME);  // watch dir. name changes 
     
    if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) 
        ExitProcess(GetLastError()); 
     
    // Change notification is set. Now wait on both notification 
    // handles and refresh accordingly. 
     
    while (TRUE) 

     
        // Wait for notification.
     
        dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, 
            FALSE, INFINITE); 
     
        switch (dwWaitStatus) 
        { 
            case WAIT_OBJECT_0: 
     
            // A file was created or deleted in C:\WINDOWS. 
            // Refresh this directory and restart the 
            // change notification. RefreshDirectory is an 
            // application-defined function. 
     
                RefreshDirectory("C:\\WINDOWS") 
                if ( FindNextChangeNotification( 
                        dwChangeHandles[0]) == FALSE ) 
                    ExitProcess(GetLastError()); 
                break; 
     
            case WAIT_OBJECT_0 + 1: 
     
            // A directory was created or deleted in C:\. 
            // Refresh the directory tree and restart the 
            // change notification. RefreshTree is an 
            // application-defined function. 
     
                RefreshTree("C:\\"); 
                if (FindNextChangeNotification( 
                        dwChangeHandles[1]) == FALSE) 
                    ExitProcess(GetLastError()); 
                break; 
     
            default: 
                ExitProcess(GetLastError()); 
        } 
    } 另一种办法,可以通过ChangeJournal,这个市ntfs5的新特性。
    第三种办法:optunity lock,可以对文件进行访问控制,其他用户如果需要访问一个文件的话,需要加锁的程序的权限许可。嗬嗬,这个感觉不错,不过不知道能不能用在目录上面。
    第四种办法:ReadDirectoryChangesW ,自己看看msdn的api
      

  6.   

    ReadDirectoryChangesW
    http://vip.6to23.com/NowCan1/tech/dirwatch.htm
      

  7.   

    文件监视部分我已经做好了, 只是不知如何刷新显示文件目录的CTreeCtrl, 如题目中的要求那样.
      

  8.   

    我只能判断出有变化, 但不知哪个目录变化的.(在WIN98/2000下)
    刷新节点如何操作?