My goal is to have a single icon for all the windows of my application.
After some reading, my understanding is that creating a tray icon is achieved through
Shell_NotifyIcon(). This function gets a
NOTIFYICONDATA structure which contains a
hWnd field. This
HWND is used by the system to notify the corresponding window of tray icon events. These events are handled by a
WindowProc callback that is set on the window with
Hence my questions:
Shell_NotifyIcon()multiple times with different
NOTIFYICONDATAstructures, each one with a different
hWnd, but with the same icon ?
Would creating a hidden proxy window be an appropriate solution ?
Some background: my application calls the WinAPI with C (using js-ctypes), and should ideally work on all Windows versions from XP on.
You practically answered your own question in the question itself. The best thing to do is create a hidden window that survives as long as you need the tray icon to exist.
You would call
Shell_NotifyIcon() only once with the
hWnd referring to this hidden window, and have this window post the messages to the individual windows that need to receive them.
This also gives you the flexibility of being able to decide to skip sending messages to a particular window, or being able to send a different message to each window, depending on the requirements of your particular application.