It seems a bit brittle to make these changes only if there's no systray icons. The problem will be back whenever there is one for whatever reason (AutoHotkey, Steam, or any other application).
What about using NOACTIVATE instead, possibly unconditionally like we do already for icon windows. The systray should also perhaps be created with WS_EX_NOACTIVATE, I don't know exactly what difference it makes but the taskbar tray has it.
Note that it possibly won't solve the issue, I don't think we handle NOACTIVATE very well at the moment (ie: it might get focused nonetheless because mapped windows get focused by default), or maybe at least it will help when WM_TAKE_FOCUS is used.