Solved

How to Refresh Windows Explorer Items using SHChangeNotify

Posted on 2012-03-20
8
2,000 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 32

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
 
LVL 32

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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 32

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now