{"id":44013,"date":"2014-09-22T07:00:00","date_gmt":"2014-09-22T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/09\/22\/receiving-a-notification-any-time-the-selection-changes-in-an-explorer-window\/"},"modified":"2014-09-22T07:00:00","modified_gmt":"2014-09-22T07:00:00","slug":"receiving-a-notification-any-time-the-selection-changes-in-an-explorer-window","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140922-00\/?p=44013","title":{"rendered":"Receiving a notification any time the selection changes in an Explorer window"},"content":{"rendered":"<p>\nToday&#8217;s Little Program merely prints a message whenever the\nuser changes the selection on the desktop.\nI chose the desktop for expediency,\nsince it saves me the trouble of coming up with a way for the\nuser to specify which Explorer window they want to track.\nAlso, all I do is print a message saying &#8220;Selection changed!&#8221;;\nactually getting the selection was covered earlier\nin both\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/07\/20\/188696.aspx\">\nC++<\/a>\nand\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/04\/22\/10412906.aspx\">\nscript<\/a>.\n<\/p>\n<p>\nRemember that Little Programs do little to no error checking.\n<\/p>\n<pre>\n#define STRICT\n#include &lt;windows.h&gt;\n#include &lt;ole2.h&gt;\n#include &lt;shlobj.h&gt;\n#include &lt;shdispid.h&gt;\n#include &lt;atlbase.h&gt;\n#include &lt;stdio.h&gt;\nclass CShellFolderViewEventsSink :\n    public <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/06\/12\/10425215.aspx\">CDispInterfaceBase<\/a>&lt;DShellFolderViewEvents&gt;\n{\npublic:\n CShellFolderViewEventsSink() { }\n HRESULT SimpleInvoke(\n    DISPID dispid, DISPPARAMS *pdispparams, VARIANT *pvarResult)\n {\n  switch (dispid) {\n  case DISPID_SELECTIONCHANGED:\n   printf(\"Selection changed!\\n\");\n   break;\n  }\n  return S_OK;\n }\n};\nint __cdecl wmain(int, wchar_t **)\n{\n <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/05\/20\/135841.aspx\">CCoInitialize<\/a> init;\n CComPtr&lt;IShellFolderViewDual&gt; spFolderView;\n <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/11\/18\/10468726.aspx\">GetDesktopAutomationObject<\/a>(IID_PPV_ARGS(&amp;spFolderView));\n CComPtr&lt;CShellFolderViewEventsSink&gt; spSink;\n spSink.Attach(new CShellFolderViewEventsSink());\n spSink-&gt;Connect(spFolderView);\n MessageBox(NULL, TEXT(\"Click OK when bored.\"), TEXT(\"Title\"), MB_OK);\n spSink-&gt;Disconnect();\n return 0;\n}\n<\/pre>\n<p>\nOur\n<code>CShell&shy;Folder&shy;View&shy;Events&shy;Sink<\/code>\nsimply prints the message whenever it receives a\n<code>DISPID_SELECTION&shy;CHANGED<\/code> event.\n<\/p>\n<p>\nSure, this program isn&#8217;t useful on its own,\nbut you can incorporate into a program that\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/03\/25\/10145644.aspx\">\nuses an Explorer Browser<\/a>\nso that your application can do something based on the current\nselection.\n(For example, if your program is using an Explorer Browser\nto let the user select files for upload,\nyou can display the total file size of the current selection.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s Little Program merely prints a message whenever the user changes the selection on the desktop. I chose the desktop for expediency, since it saves me the trouble of coming up with a way for the user to specify which Explorer window they want to track. Also, all I do is print a message saying [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-44013","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Today&#8217;s Little Program merely prints a message whenever the user changes the selection on the desktop. I chose the desktop for expediency, since it saves me the trouble of coming up with a way for the user to specify which Explorer window they want to track. Also, all I do is print a message saying [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=44013"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44013\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=44013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=44013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=44013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}