Solved

How to Refresh Windows Explorer Items using SHChangeNotify

Posted on 2012-03-20
8
2,024 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

895 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

14 Experts available now in Live!

Get 1:1 Help Now