I was used to using WndProc for handling proc messages, but now I have a console project and I want somehow to handle a custom WM_TRAYICON
message.
I have the callback function, I just need to make Windows call it whenever someone interacts with the tray icon. In a recent program I did I used SetWindowsHookEx
, can something similar be used?
You need to create a hidden window to use with the notification icon. Call
CreateWindow
as usual to create a window, but just refrain from showing it. Make sure that you do not passWS_VISIBLE
when creating the window.The other issue is that you need a message loop. Since a console application will not run a message loop by default, the simplest solution is to run the notification icon out of a separate thread which implements the message loop. Naturally this implies that the hidden window needs to be created and destroyed in that thread also.
I propose you do not make your project console. If you want to handle window messages in legitimate way (without hooks and hacks) and you want to have a console then typical solution is to use AllocConsole function.