{"id":20,"date":"2015-12-14T23:50:37","date_gmt":"2015-12-14T23:50:37","guid":{"rendered":"http:\/\/www.goodbits.ca\/?p=20"},"modified":"2017-09-24T04:14:18","modified_gmt":"2017-09-24T04:14:18","slug":"how-to-detect-if-your-system-tray-icon-has-gone-missing","status":"publish","type":"post","link":"https:\/\/www.goodbits.ca\/index.php\/2015\/12\/14\/how-to-detect-if-your-system-tray-icon-has-gone-missing\/","title":{"rendered":"How to detect if your system tray icon has gone missing, C\/C++, Win32"},"content":{"rendered":"<h1>The Problem:<\/h1>\n<p>Sometimes if either the desktop crashes or windows decides to go wrong for whatever reason, it re-creates the system tray. There is no way to detect when that happens and your icon is now missing but your system tray application is still running.<\/p>\n<h1>The Solution:<\/h1>\n<p>Windows does send a windows message to be notified when the system tray is being created. \u00a0It won&#8217;t be sent to you unless you register to receive\u00a0it.<\/p>\n<p>To register to receive the message do the following and store the ID that is returned. The simplest way to do this is to store it in a global variable.<\/p>\n<pre class=\"lang:c++ decode:true\">const int uTaskbarCreatedMsg = RegisterWindowMessageA(\"TaskbarCreated\");\r\n\r\n<\/pre>\n<p>Then later on in your windows message loop handle the message.<\/p>\n<pre class=\"lang:c++ decode:true \">LRESULT CALLBACK WndProc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)\r\n{\r\n    \/\/ ... handle other messages\r\n    if (msg == uTaskbarCreatedMsg) {\r\n        \/\/ Destroy any existing icon and recreate it\r\n        CreateSystemTrayIcon();\r\n        return 0;\r\n    }\r\n    \/\/ ... default message handling\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h1>Related Links<\/h1>\n<ul>\n<li><a href=\"http:\/\/www.codeproject.com\/Articles\/74\/Adding-Icons-to-the-System-Tray\">System Tray SDK<\/a><\/li>\n<li><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms644947(v=vs.85).aspx\">MSDN RegisterWindowMessage API<\/a><\/li>\n<\/ul>\n<h1>Related Searches<\/h1>\n<ul>\n<li>how to detect if the system tray is gone msdn<\/li>\n<li>how to detect if the system tray is gone<\/li>\n<li>systray icon restart after explore.exe crashes<\/li>\n<li>catch explore restart message msdn<\/li>\n<li>win32 message for when explorer.exe starts msdn<\/li>\n<li>windows message for when explorer.exe starts msdn<\/li>\n<li>systray icon dissapears after sleep<\/li>\n<li>windows message for when system awakes from sleep<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The Problem: Sometimes if either the desktop crashes or windows decides to go wrong for whatever reason, it re-creates the system tray. There is no way to detect when that happens and your icon is now missing but your system tray application is still running. The Solution: Windows does send a windows message to be &hellip; <a href=\"https:\/\/www.goodbits.ca\/index.php\/2015\/12\/14\/how-to-detect-if-your-system-tray-icon-has-gone-missing\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to detect if your system tray icon has gone missing, C\/C++, Win32<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,3,20],"tags":[15,5,16,14,13],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-android","category-development","category-win32","tag-c","tag-development","tag-systray","tag-win32","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":10,"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":48,"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/posts\/20\/revisions\/48"}],"wp:attachment":[{"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.goodbits.ca\/index.php\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}