Window not activating when opened

I have a trayitem, and right-clicking it opens a window. I have a text field in it that gets the focus when the window is opened, and that is fine. My problem is that the whole window has to be clicked to activate it, which is annoying. Is there any way I can tell Windows to activate the window when it opens?

Curiously, if I close the window then right-click the trayitem a second time, the window activates and I can start typing in my text field right away.

Excuse me if I post this now and get back to it tomorrow morning. Thanks.

If it works after you close then re-open, the app doesn’t consider it ever lost the focus when it was hidden.
You might try using a set focus in the paint event.
Or closing the window fully if it is dismissed, so that every tray item event causes a new window and the full activation sequence.

Thanks, Jeff.
I tried getting the trayitem to give the window focus, and getting the window to give itself the focus (like a set focus in the paint event) but as you say the application seems to think the window has the focus.
You made me think of switching off Implicit Instance and getting the trayitem to create a new window with the new operator but then things that needed to be in existence weren’t so I gave that away.
I solved it with an idea from another conversation - I made the window visible to start with rather than invisible and included a timer to immediately close it. The timer only works when the application is first opened. After that, subsequent right-clicks open an activated window rather than one without the focus.

Good to hear

That sounds like ‘those things needed to be properties of the App, not of the window’. Then turning off implicit instance would have solved it.