You defined a message handler, but you did not connect to to the message ID. In the declaration of the form type, change the TrayMessage
declaration to be:
procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY;
Beyond that I have the following comments:
- Always check Win32 function return values for errors.
- You write
Main.Show
andMain.Hide
in aTMain
method. You should simply removeMain.
and call these methods on the implicitSelf
object. - Use bitwise
or
rather than arithmethic+
to combine flags. - You use the form handle for the notification icon. If the form is re-created, your icon will be orphaned. Instead you need to use a stable window handle obtained by a call to
AllocateHWnd
.