Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to refresh folder

How to refresh folder

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MKC002
    wrote on last edited by
    #1

    If any folder is open in window explorer then how to refresh its contents. Say c:/xyz is open, it contains some files and folders, i want to progratically refresh the children.

    C L A 3 Replies Last reply
    0
    • M MKC002

      If any folder is open in window explorer then how to refresh its contents. Say c:/xyz is open, it contains some files and folders, i want to progratically refresh the children.

      C Offline
      C Offline
      Chandrasekharan P
      wrote on last edited by
      #2

      Are you working on mfc?? if yes then, i think you can just redraw whatever it is that you want on the screen.

      Every new day is another chance to change your life.

      1 Reply Last reply
      0
      • M MKC002

        If any folder is open in window explorer then how to refresh its contents. Say c:/xyz is open, it contains some files and folders, i want to progratically refresh the children.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        How exactly do you mean "programmatically"? With an external program or an explorer addin?

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        M 1 Reply Last reply
        0
        • M MKC002

          If any folder is open in window explorer then how to refresh its contents. Say c:/xyz is open, it contains some files and folders, i want to progratically refresh the children.

          A Offline
          A Offline
          App_
          wrote on last edited by
          #4

          Here you go.

          // Call for each explorer window

              HWND hExplorer = FindWindowEx(GetDesktopWindow(), NULL, L"ExploreWClass", NULL);
          
              while(hExplorer != NULL)
              {
                  EnumChildWindows(hExplorer, RefreshFolderSelectionCB, (LPARAM)&packet);
          
                  hExplorer = FindWindowEx(GetDesktopWindow(), hExplorer, L"ExploreWClass", NULL);
              }
          

          ...
          ...
          ...

          BOOL CALLBACK RefreshFolderSelectionCB(HWND hWnd, LPARAM lParam)
          {
          WCHAR sBuffer[MAX_PATH] = {0};

          ::GetClassName(hWnd, sBuffer, MAX\_PATH);
          
          if (wcscmp(L"SysTreeView32", sBuffer) == 0)
          {
              RefreshFolderSelectionPacket\* pPacket = (RefreshFolderSelectionPacket\*)lParam;
          
              // Refreshes the tree nodes that match the contained full paths, and all their open descendants
              // Paths are updated by calling UpdateItem (below)
              // Cache is used across explorer instances to ensure no path is updated twice.
          
              RefreshSelection(pPacket);
          }
          
          return TRUE;
          

          }

          ...
          ...
          static void UpdateItem(IShellFolder* pDesktop, const std::wstring& rsFullPath)
          {
          PIDLIST_RELATIVE pIDL;

          if (SUCCEEDED(pDesktop->ParseDisplayName(NULL, NULL, (LPWSTR)rsFullPath.c\_str(), NULL, &pIDL, NULL)))
          {
              SHChangeNotify(SHCNE\_UPDATEITEM, SHCNF\_IDLIST|SHCNF\_NOTIFYRECURSIVE|SHCNF\_FLUSH, pIDL, NULL);
          
              ILFree(pIDL);
          }
          

          }

          D M 2 Replies Last reply
          0
          • A App_

            Here you go.

            // Call for each explorer window

                HWND hExplorer = FindWindowEx(GetDesktopWindow(), NULL, L"ExploreWClass", NULL);
            
                while(hExplorer != NULL)
                {
                    EnumChildWindows(hExplorer, RefreshFolderSelectionCB, (LPARAM)&packet);
            
                    hExplorer = FindWindowEx(GetDesktopWindow(), hExplorer, L"ExploreWClass", NULL);
                }
            

            ...
            ...
            ...

            BOOL CALLBACK RefreshFolderSelectionCB(HWND hWnd, LPARAM lParam)
            {
            WCHAR sBuffer[MAX_PATH] = {0};

            ::GetClassName(hWnd, sBuffer, MAX\_PATH);
            
            if (wcscmp(L"SysTreeView32", sBuffer) == 0)
            {
                RefreshFolderSelectionPacket\* pPacket = (RefreshFolderSelectionPacket\*)lParam;
            
                // Refreshes the tree nodes that match the contained full paths, and all their open descendants
                // Paths are updated by calling UpdateItem (below)
                // Cache is used across explorer instances to ensure no path is updated twice.
            
                RefreshSelection(pPacket);
            }
            
            return TRUE;
            

            }

            ...
            ...
            static void UpdateItem(IShellFolder* pDesktop, const std::wstring& rsFullPath)
            {
            PIDLIST_RELATIVE pIDL;

            if (SUCCEEDED(pDesktop->ParseDisplayName(NULL, NULL, (LPWSTR)rsFullPath.c\_str(), NULL, &pIDL, NULL)))
            {
                SHChangeNotify(SHCNE\_UPDATEITEM, SHCNF\_IDLIST|SHCNF\_NOTIFYRECURSIVE|SHCNF\_FLUSH, pIDL, NULL);
            
                ILFree(pIDL);
            }
            

            }

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            http://social.msdn.microsoft.com/Forums/en/windowssdk/thread/cc4a702f-1b2f-4d19-bf68-c88967544172[^] Where do RefreshFolderSelectionPacket and RefreshSelection() come from?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

            A 1 Reply Last reply
            0
            • D David Crow

              http://social.msdn.microsoft.com/Forums/en/windowssdk/thread/cc4a702f-1b2f-4d19-bf68-c88967544172[^] Where do RefreshFolderSelectionPacket and RefreshSelection() come from?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

              A Offline
              A Offline
              App_
              wrote on last edited by
              #6

              uh huh, I ripped that code from there :cool:

              1 Reply Last reply
              0
              • L Lost User

                How exactly do you mean "programmatically"? With an external program or an explorer addin?

                Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                M Offline
                M Offline
                MKC002
                wrote on last edited by
                #7

                My program hides a file say from c: drive. If window explorer is open (c drive) i found file still display. If i refresh window explorer manually then file disappear.

                1 Reply Last reply
                0
                • A App_

                  Here you go.

                  // Call for each explorer window

                      HWND hExplorer = FindWindowEx(GetDesktopWindow(), NULL, L"ExploreWClass", NULL);
                  
                      while(hExplorer != NULL)
                      {
                          EnumChildWindows(hExplorer, RefreshFolderSelectionCB, (LPARAM)&packet);
                  
                          hExplorer = FindWindowEx(GetDesktopWindow(), hExplorer, L"ExploreWClass", NULL);
                      }
                  

                  ...
                  ...
                  ...

                  BOOL CALLBACK RefreshFolderSelectionCB(HWND hWnd, LPARAM lParam)
                  {
                  WCHAR sBuffer[MAX_PATH] = {0};

                  ::GetClassName(hWnd, sBuffer, MAX\_PATH);
                  
                  if (wcscmp(L"SysTreeView32", sBuffer) == 0)
                  {
                      RefreshFolderSelectionPacket\* pPacket = (RefreshFolderSelectionPacket\*)lParam;
                  
                      // Refreshes the tree nodes that match the contained full paths, and all their open descendants
                      // Paths are updated by calling UpdateItem (below)
                      // Cache is used across explorer instances to ensure no path is updated twice.
                  
                      RefreshSelection(pPacket);
                  }
                  
                  return TRUE;
                  

                  }

                  ...
                  ...
                  static void UpdateItem(IShellFolder* pDesktop, const std::wstring& rsFullPath)
                  {
                  PIDLIST_RELATIVE pIDL;

                  if (SUCCEEDED(pDesktop->ParseDisplayName(NULL, NULL, (LPWSTR)rsFullPath.c\_str(), NULL, &pIDL, NULL)))
                  {
                      SHChangeNotify(SHCNE\_UPDATEITEM, SHCNF\_IDLIST|SHCNF\_NOTIFYRECURSIVE|SHCNF\_FLUSH, pIDL, NULL);
                  
                      ILFree(pIDL);
                  }
                  

                  }

                  M Offline
                  M Offline
                  MKC002
                  wrote on last edited by
                  #8

                  I get compile error for RefreshFolderSelectionPacket how to call UpdateItem

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups