Solved

How to Refresh Windows Explorer Items using SHChangeNotify

Posted on 2012-03-20
8
2,073 Views
Last Modified: 2012-04-01
I have the path of a folder, I need to refresh that folder to display the new icon on it.

In the below API, I tried different combinations of parameters, but it seems not working:

SHChangeNotify(SHCNE_UPDATEIMAGE |SHCNE_RENAMEITEM | SHCNE_MKDIR,0, 0, "C:\Watch\Test);
0
Comment
Question by:HPFE455
  • 5
  • 3
8 Comments
 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 500 total points
ID: 37748703
the SHCNE_UPDATEIMAGE would work if you changed an item in the system image list.

then the call would be

SHChangeNotify(SHCNE_UPDATEIMAGE, SHCNF_DWORD, 0, idx);

Open in new window


 
the SHCNF_DWORD tells that the input is a DWORD (unsigned integer) and idx is the index of the image which had changed.

Sara
0
 

Author Comment

by:HPFE455
ID: 37755239
thanks Sara, I will try your solution tomorrow.
0
 

Author Comment

by:HPFE455
ID: 37757064
How shell will know which folder icon need to be changed. I am maintaining a list of folders /Files and that need to be refreshed, so  the updated icon will be displayed.

 The below code is not updating the folde icon.
SHChangeNotify(SHCNE_UPDATEIMAGE, SHCNF_DWORD, 0, idx);
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 37760428
can you show the code where you changed the system image list?

the Explorer would refresh all files and folders - similar to response on f5 - and would have exchanged the image identified by idx in the cache.

Sara
0
 

Assisted Solution

by:HPFE455
HPFE455 earned 0 total points
ID: 37767479
Sara,
 I am using QT for my development.

refresh( const QString systemPath)
{

//wchar_t* systemPath = L"C:\\Users\\guest\\Desktop\\Test";
systemPath = L"C:\\Users\\guest\\Desktop\\Test";

    IShellFolder *psfParent = NULL; 
    LPITEMIDLIST pidlSystem = NULL; 
    HRESULT hr; 

  hr = SHGetDesktopFolder(&psfParent);

if (SUCCEEDED(hr)) 
{
hr =psfParent->ParseDisplayName(NULL,NULL, systemPath ,0, &pidlSystem,NULL);
SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST, pidlSystem, 0);
}

}

Open in new window


The above code seems working while using Visual Studio 2010. But the same code is giving compilation for the below line

hr =psfParent->ParseDisplayName(NULL,NULL, systemPath ,0, &pidlSystem,NULL);
0
 

Assisted Solution

by:HPFE455
HPFE455 earned 0 total points
ID: 37768549
sara,
 I have changed my code   and it worked.

hr =psfParent->ParseDisplayName(NULL,NULL, (LPOLESTR)path.utf16(),0, &pidlSystem,NULL);


Thanks for you help,  I will be accepting your solution after my testing
0
 
LVL 33

Expert Comment

by:sarabande
ID: 37769976
the QString::utf16 returns const ushort* what is equivalent to const wchar_t * or LPCWSTR (long pointer to "wide" unicode string). unfortunately the third argument of ParseDisplayName is a non-const LPWSTR (or LPOLESTR) though documented as [in] what means read-only. therefore the cast you made which casts from const to non-const is ok.

a solution without cast is like

wchar_t wszbuf[MAX_PATH+1];
wcscpy(wszbuf, path.utf16());
hr =psfParent->ParseDisplayName(NULL,NULL,wszbuf,0, &pidlSystem,NULL); 

Open in new window


Sara
0
 

Author Closing Comment

by:HPFE455
ID: 37792667
I have updated my code  after sara's comments and it helped me to resolve the issue
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question