I use the following code in the FormCreate event handler to create a system tray icon. When I run my program the system tray icon appears fine.
I set my application be started automatically on windows start up. When I restart the computer my application's process is started but the system tray icon never appears.
I think it might be something to do with the timing of when the code is run, that perhaps the system tray isn't ready to be populated.
I get my app to run at start up via it's NSIS installer : WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "MyApp" "$INSTDIR\ MyApp.exe"
Code to create system tray icon :
with TrayIconData do
begin
cbSize := SizeOf(TrayIconData);
Wnd := Handle;
uID := 0;
uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
uCallbackMessage := WM_ICONTRAY;
hIcon := Application.Icon.Handle;
StrPCopy(szTip, Application.Title);
end;
Shell_NotifyIcon(NIM_ADD, @TrayIconData);