Solved

How to Refresh Windows Explorer Items using SHChangeNotify

Posted on 2012-03-20
8
2,193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 34

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

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 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

617 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