locked
Change icon overlay at run-time based on state? RRS feed

  • Question

  • I've seen a couple of related posts that haven't really answered this (or if they have, it seems overly complicated):

    http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/93902cdc-b228-4b6d-8d5b-a454fad21e6a
    http://www.codeproject.com/Articles/18649/Multiple-Folder-Icons

    I have a couple of overlay handlers, and based on a run-time state (that changes dynamically), I need to update the icon overlay.  It looks like SHChangeNotify should be called when an app registers a new icon overlay handler, but the docs say: "Note, however, that icon overlay handlers are not reloaded."  Plus, the handlers are all registered at start time.  There is also SHNonLoadedIconOverlayIdentifiers, but the docs say: "SHLoadNonloadedIconOverlayIdentifiers alone does not load a new icon overlay; you also need to trigger an action that uses the overlay, such as a refresh of a Windows Explorer view".  Of course, I'm not about to do that at run-time.

    So the question is: ONCE I GET A NEW STATE, HOW CAN I PROGRAMMATICALLY TELL WINDOWS TO LOAD THE APPROPRIATE ICON OVERLAY HANDLER, SO IsMemberOf WILL GET CALLED AND THE PROPER OVERLAY WILL BE DISPLAYED ON DEMAND?

    Thanks

    Tuesday, July 17, 2012 4:53 PM

Answers

  • SHChangeNotify does work.  For a given file, the proper test code is:

    set some state
    std::wstring mypath = L"c:\\whateverdir\\whatever.txt";
    SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, mypath.c_str(), NULL);

    Then the icon overlay handler's IsMemberOf function can check the state and return S_OK if that state is appropriate to display the given overlay.  If so, the icon will change.

    • Marked as answer by fbs419 Wednesday, July 25, 2012 1:56 PM
    Wednesday, July 25, 2012 1:56 PM

All replies

  • Hi, have you try the link: http://www.codeproject.com/Articles/7484/How-to-overlay-an-icon-over-existing-shell-objects ?

    I think it can meet your demand, like Q&A and usage of IsMemberOf.


    Please not forget mark your answer, and unmark your disagreed point.

    Thursday, July 19, 2012 10:50 AM
  • Yes I have seen that article.  I actually have the handlers written and they work, but it didn't say how you would tell Explorer programmatically to update the icons.  I think SHChangeNotify  is used for that.  I am testing it out.
    • Proposed as answer by Elegentin XieModerator Friday, July 20, 2012 7:46 AM
    • Marked as answer by Elegentin XieModerator Wednesday, July 25, 2012 9:27 AM
    • Unmarked as answer by fbs419 Wednesday, July 25, 2012 1:43 PM
    • Marked as answer by fbs419 Wednesday, July 25, 2012 1:49 PM
    • Unmarked as answer by fbs419 Wednesday, July 25, 2012 1:50 PM
    • Unproposed as answer by fbs419 Wednesday, July 25, 2012 1:50 PM
    Thursday, July 19, 2012 9:38 PM
  • SHChangeNotify does work.  For a given file, the proper test code is:

    set some state
    std::wstring mypath = L"c:\\whateverdir\\whatever.txt";
    SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, mypath.c_str(), NULL);

    Then the icon overlay handler's IsMemberOf function can check the state and return S_OK if that state is appropriate to display the given overlay.  If so, the icon will change.

    • Marked as answer by fbs419 Wednesday, July 25, 2012 1:56 PM
    Wednesday, July 25, 2012 1:56 PM
  • Hi fbs419,

    Welcome back.
    Thanks for your sharing answer here, it’s very great and helpful for other community members who stunk in the similar issue.
    Regards,
    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 26, 2012 1:42 AM
    Moderator