{"id":833,"date":"2014-06-02T07:00:00","date_gmt":"2014-06-02T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/06\/02\/obtaining-information-about-the-users-wallpaper-on-multiple-monitors\/"},"modified":"2014-06-02T07:00:00","modified_gmt":"2014-06-02T07:00:00","slug":"obtaining-information-about-the-users-wallpaper-on-multiple-monitors","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140602-00\/?p=833","title":{"rendered":"Obtaining information about the user&#039;s wallpaper on multiple monitors"},"content":{"rendered":"<p>\nToday we&#8217;re going to dump information about the user&#8217;s wallpaper\nsettings on multiple monitors.\n<\/p>\n<p>\nThe idea is simple. You use the\n<code>IDesktop&shy;Wallpaper<\/code> interface on the\n<code>Desktop&shy;Wallpaper<\/code> object\nto get information about the desktop wallpaper.\nIt will tell you the wallpaper positioning information,\nwhether a single image is being used for all monitors,\nwhere those monitors are,\nand which image is on which monitor.\n<\/p>\n<pre>\n#define UNICODE\n#define <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/02\/12\/71851.aspx\">_UNICODE<\/a>\n#define STRICT\n#include &lt;windows.h&gt;\n#include &lt;shlobj.h&gt;\n#include &lt;atlbase.h&gt;\n#include &lt;atlalloc.h&gt;\n#include &lt;stdio.h&gt; \/\/ horrors! mixing C and C++!\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 \/\/ Create the DesktopWallpaper object\n CComPtr&lt;IDesktopWallpaper&gt; spdw;\n CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_ALL,\n                  IID_PPV_ARGS(&amp;spdw));\n \/\/ See if there is a single wallpaper on all monitors.\n CComHeapPtr&lt;wchar_t&gt; spszCommonWallpaper;\n HRESULT hr = spdw-&gt;GetWallpaper(nullptr, &amp;spszCommonWallpaper);\n switch (hr) {\n case S_OK:\n  printf(\"Same wallpaper on all monitors: %ls\\n\",\n         static_cast&lt;wchar_t *&gt;(spszCommonWallpaper));\n  break;\n case S_FALSE:\n  printf(\"Different wallpaper on each monitor\\n\");\n  break;\n default:\n  printf(\"Mysterious error: 0x%08x\\n\", hr);\n  break;\n }\n \/\/ Get the number of monitors,\n UINT count;\n spdw-&gt;GetMonitorDevicePathCount(&amp;count);\n printf(\"There are %d monitors\\n\", count);\n \/\/ Print information about each monitor.\n for (UINT i = 0; i &lt; count; i++) {\n  \/\/ Get the device path for the monitor.\n  CComHeapPtr&lt;wchar_t&gt; spszId;\n  spdw-&gt;GetMonitorDevicePathAt(i, &amp;spszId);\n  printf(\"path[%d] = %ls\\n\",\n         i, static_cast&lt;wchar_t *&gt;(spszId));\n  \/\/ Get the monitor location.\n  RECT rc;\n  spdw-&gt;GetMonitorRECT(spszId, &amp;rc);\n  printf(\"rect = (%d, %d, %d, %d)\\n\",\n         rc.left, rc.top, rc.bottom, rc.right);\n  \/\/ Get the wallpaper on that monitor.\n  CComHeapPtr&lt;wchar_t&gt; spszWallpaper;\n  hr = spdw-&gt;GetWallpaper(spszId, &amp;spszWallpaper);\n  printf(\"image = %ls\\n\",\n         static_cast&lt;wchar_t *&gt;(spszWallpaper));\n }\n return 0;\n}\n<\/pre>\n<p>\nThe program proceeds in a few basic steps.\n<\/p>\n<p>\nWe create the <code>Desktop&shy;Wallpaper<\/code> object.\nThat object will give us the answers to our questions.\n<\/p>\n<p>\nOur first question is,\n&#8220;Is the same wallpaper being shown on all monitors?&#8221;\nTo determine that, we call\n<code>IDesktop&shy;Wallpaper::Get&shy;Wallpaper<\/code>\nand specify <code>nullptr<\/code> as the monitor ID.\nThe call succeeds with <code>S_OK<\/code> if the same wallpaper\nis shown on all monitors (in which case the shared wallpaper\nis returned).\nIt succeeds with <code>S_FALSE<\/code> if each monitor has a different\nwallpaper.\n<\/p>\n<p>\nTo get information about the wallpaper on each monitor,\nwe iterate through them,\nfirst asking for the monitor device path,\nsince that is how the\n<code>Desktop&shy;Wallpaper<\/code> object identifies monitors.\nFor each monitor, we ask for its location\nand the wallpaper for that monitor.\nNote that if the monitor is not displaying a wallpaper at all,\nthe <code>Get&shy;Wallpaper<\/code> method succeeds\nbut returns an empty string.\n<\/p>\n<p>\nAnd that&#8217;s it.\nYou can juice up this program by asking for wallpaper\npositioning information,\nand if you are feeling really adventuresome,\nyou can use the <code>Set&shy;Wallpaper<\/code>\nmethod to change the wallpaper.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we&#8217;re going to dump information about the user&#8217;s wallpaper settings on multiple monitors. The idea is simple. You use the IDesktop&shy;Wallpaper interface on the Desktop&shy;Wallpaper object to get information about the desktop wallpaper. It will tell you the wallpaper positioning information, whether a single image is being used for all monitors, where those monitors [&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-833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Today we&#8217;re going to dump information about the user&#8217;s wallpaper settings on multiple monitors. The idea is simple. You use the IDesktop&shy;Wallpaper interface on the Desktop&shy;Wallpaper object to get information about the desktop wallpaper. It will tell you the wallpaper positioning information, whether a single image is being used for all monitors, where those monitors [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/833","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=833"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/833\/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=833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}