-1

I've developed an application that starts external processes (e.g. like the notepad etc.) and displays the main window of the process inside a panel in my application. (Like described in this thread)

The problem is that I get a lot of focus problems with that. E.g. when a window is over my application's window and I click on the window of the sub process, the main window does not come to the foreground.

I've tried to solve this problem by calling SetForegroundWindow from the main application when the child process receives focus, but as this and this thread describes this only works if the process is being debugged or if it is the foreground process. There is a workaround by calling AttachThreadInput, but that doesn't work 100% reliable.

SetForegroundWindow should also work if "The process was started by the foreground process", but in my case it is the other way arround. (The foreground process was started by the process)

Is there a way to get the right to set the foreground window if the focussed window is a child process of my process?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
TheNetStriker
  • 67
  • 1
  • 5
  • Stop everything you are doing and take a moment to read: [Is it legal to have a cross-process parent/child or owner/owned window relationship?](https://blogs.msdn.microsoft.com/oldnewthing/20130412-00/?p=4683). – IInspectable Nov 02 '18 at 11:29
  • Thanks for the hint. I didn't know that embedding windows from external processes can generate such problems. I didn't have any problems so far with the processes I'am embedding, but maybe other processes will make problems. I think I will implement a setting if the process should be implemented or just start normally to handle this for future processes. – TheNetStriker Nov 02 '18 at 12:28

1 Answers1

1

SetForegroundWindow sets the thread that created the specified window into the foreground.

BringWindowToTop brings the specified window to the top of the Z order.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98
  • I just tried this and "BringWindowToTop" seams to work even when the executing process is not the foreground process. I will test some more and hope that this is the solution for my problem. Thanks for the quick help! – TheNetStriker Nov 02 '18 at 12:32