{"id":5283,"date":"2013-02-11T07:00:00","date_gmt":"2013-02-11T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/02\/11\/display-an-overlay-on-the-taskbar-button\/"},"modified":"2013-02-11T07:00:00","modified_gmt":"2013-02-11T07:00:00","slug":"display-an-overlay-on-the-taskbar-button","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130211-00\/?p=5283","title":{"rendered":"Display an overlay on the taskbar button"},"content":{"rendered":"<p><P>\nToday&#8217;s &#8220;Little Program&#8221;\ndisplays an overlay on the taskbar button.\nI&#8217;ve seen some people call this a &#8220;badge&#8221;,\nbut &#8220;overlay&#8221; is the official term.\n<\/P>\n<P>\nStart with our\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nscratch program<\/A>\nand make the following changes:\n<\/P>\n<PRE>\n#include &lt;comip.h&gt;\n#include &lt;comdef.h&gt;\n#include &lt;shlobj.h&gt;\n#include &lt;shellapi.h&gt;<\/p>\n<p>_COM_SMARTPTR_TYPEDEF(ITaskbarList3, __uuidof(ITaskbarList3));\n<\/PRE>\n<P>\nI decided to shake things up and use a different smart\npointer library:\n<CODE>com_ptr_t<\/CODE>.\n(That&#8217;ll teach you to complain that I don&#8217;t use a smart\npointer library in my samples.\nNow you get to complain that I use the <I>wrong<\/I>\nsmart pointer library.)\n<\/P>\n<PRE>\nHICON g_hicoAlert;\nUINT g_wmTaskbarButtonCreated;<\/p>\n<p>BOOL\nOnCreate(HWND hwnd, LPCREATESTRUCT lpcs)\n{\n  <FONT COLOR=\"blue\">g_hicoAlert = LoadIcon(nullptr, IDI_EXCLAMATION);\n  g_wmTaskbarButtonCreated = RegisterWindowMessage(\n                              TEXT(&#8220;TaskbarButtonCreated&#8221;));<\/FONT>\n  return TRUE;\n}\n<\/PRE>\n<P>\nOur overlay icon is the system exclamation point icon.\nI chose this because I&#8217;m lazy.\n<\/P>\n<PRE>\nbool g_fHasOverlay = false;<\/p>\n<p>void UpdateOverlayIcon(HWND hwnd)\n{\n  HICON hicon = g_fHasOverlay ? g_hicoAlert : nullptr;\n  PCWSTR pszDescription = g_fHasOverlay ?\n                        L&#8221;Attention required&#8221; : nullptr;\n  ITaskbarList3Ptr sptb3;\n  sptb3.CreateInstance(CLSID_TaskbarList);\n  sptb3-&gt;<A HREF=\"http:\/\/msdn.microsoft.com\/library\/windows\/desktop\/dd391696.aspx\">SetOverlayIcon<\/A>(hwnd, hicon, pszDescription);\n}<\/p>\n<p>void OnChar(HWND hwnd, TCHAR ch, int cRepeat)\n{\n  if (ch == &#8216; &#8216;) {\n    g_fHasOverlay = !g_fHasOverlay;\n    UpdateOverlayIcon(hwnd);\n  }\n}<\/p>\n<p>    HANDLE_MSG(hwnd, WM_CHAR, OnChar);<\/p>\n<p>    default:\n      if (uiMsg != 0 &amp;&amp; uiMsg == g_wmTaskbarButtonCreated) {\n        UpdateOverlayIcon(hwnd);\n      }\n      break;\n<\/PRE>\n<P>\nA real program would have error checking, of course.\n<\/P>\n<P>\nPress the space bar, and the overlay will be toggled on and off.\n<\/P>\n<P>\nIf you&#8217;re really clever, you might generate your overlay icons\non the fly,\nsay, if you wanted to report the number of\nunread messages or something.\n<\/P>\n<P>\nI&#8217;ve heard that there&#8217;s one program out there that abuses the\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/windows\/desktop\/dd391697.aspx\">\n<CODE>ITaskbar&shy;List3::Set&shy;Progress&shy;State<\/CODE><\/A>\nmethod\nby changing its progress state repeatedly,\ncausing its taskbar button to cycle through different colors\nto get the user&#8217;s attention.\n<\/P>\n<P>\nJust a reminder: The user interface guidelines say that the way\nto get the user&#8217;s attention is to flash your taskbar button.\nVarious parts of the system understand this convention and\nrespond to it.\n(For example, the taskbar will temporarily unhide if a button\nstarts flashing,\nand accessibility tools know how to signal the flash state to\nthe user.)\nAs always, the shell reserves the right to block this sort of\nabusive behavior in the future,\njust like it has done with abusive notification icons.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s &#8220;Little Program&#8221; displays an overlay on the taskbar button. I&#8217;ve seen some people call this a &#8220;badge&#8221;, but &#8220;overlay&#8221; is the official term. Start with our scratch program and make the following changes: #include &lt;comip.h&gt; #include &lt;comdef.h&gt; #include &lt;shlobj.h&gt; #include &lt;shellapi.h&gt; _COM_SMARTPTR_TYPEDEF(ITaskbarList3, __uuidof(ITaskbarList3)); I decided to shake things up and use a different smart [&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-5283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Today&#8217;s &#8220;Little Program&#8221; displays an overlay on the taskbar button. I&#8217;ve seen some people call this a &#8220;badge&#8221;, but &#8220;overlay&#8221; is the official term. Start with our scratch program and make the following changes: #include &lt;comip.h&gt; #include &lt;comdef.h&gt; #include &lt;shlobj.h&gt; #include &lt;shellapi.h&gt; _COM_SMARTPTR_TYPEDEF(ITaskbarList3, __uuidof(ITaskbarList3)); I decided to shake things up and use a different smart [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5283","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=5283"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5283\/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=5283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=5283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=5283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}