NOTIFYICONDATA - GUID problem

让人想犯罪 __ 提交于 2019-12-04 07:06:38

Here's a complete list of possibilities that I'm aware of:

  • sign your EXE with a valid certificate;
  • do not ever move the EXE (precludes portable programs);
  • do not assign a GUID to your notify icon,
  • the hacky approach you linked to,
  • generate a GUID based on your application path.

Let's take a look at that last idea, in particular. Windows wants a unique GUID for every path. We just want a GUID that doesn't change for as long as the path is fixed. That's actually trivial to achieve. Here's an outline:

  • generate a random GUID using a service like make a guid
  • obtain your executable path
  • hash your path with a hash function that outputs at least 128 bits, like MD5 or SHA-1
  • XOR your GUID with the path hash, truncating to 128 bits
  • use the result as the tray icon GUID

This comes with a gotcha: the application path is not necessarily unique. But this shouldn't be a major problem because firstly, most of the time it's unique, and secondly, the worst that will happen if run via an alternative path is that the user will have to reposition the tray icon once.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!