0

I have a EXE implemented as a MFC CPropertySheet (for diagnostic interface) that acts as a server process to a main application. The main application launches it on startup, and I want the server to be initially invisible and background.

I am using CreateProcess (have also tried WinExec) and while the process does launch hidden, it always steals the activation (ie. deactivates the main application) when it launches, even when invisible.

I have tried so many things to stop this happening:

  1. Setting the STARTUPINFO parameters
  2. Overriding OnWindowPosChanging with SWP_NOACTIVATE in the server
  3. Creating the CPropertySheet as modeless with Create instead of DoModal

It doesn't happen with a CDialog based process that I grafted in as a test, so it seems to be an issue only with the CPropertySheet or the underlying Windows common control that implements it.

Does anyone have any ideas why this is happening? Or any tips on trying to diagnose where the activation is occurring? I'm really stumped.

stephen
  • 303
  • 1
  • 8
  • Thanks Jonathon, well spotted, yes the previous question is right on target for what I am looking for. Wow, it's not good news though, is it? – stephen Oct 14 '15 at 05:39
  • I stumbled across what might a good solution, is there a reason it wasn't mentioned in the other thread? I can use LockSetForegroundWindow(LSFW_LOCK) in the calling process to override that nasty internal call to SetForegroundWindow() within the property sheet creation code. Works a treat, and might work within the server process itself as well. About to do some experimentation to see what the options are. I'm afraid I don't have enough reputation to add a comment to the original question with this update. – stephen Oct 14 '15 at 05:59
  • Hmm interesting. If that works then it seems to be a good answer for the original question (and indeed for yours). Why not post it as an alternative answer on the original question? – Jonathan Potter Oct 14 '15 at 06:11
  • Cheers, Jonathon, I just did. Thanks for the pointer and your obvious involvement on this issue in the past. – stephen Oct 14 '15 at 07:15

0 Answers0