Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Refresh Windows Explorer Items using SHChangeNotify

Posted on 2012-03-20
8
Medium Priority
?
2,252 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 35

Assisted Solution

by:sarabande
sarabande earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Accepted Solution

by:
sarabande earned 2000 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 35

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

705 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