1

I'm developing a multi-process framework for a complex application. A Host process acts as a container, and one or more guest processes can be spawn from it. A Window of such guest processes is reparented to a Hosts's window (such as a notebook tabSheet). (InterProcess Communication is not an issue here - it works) Imagine something similar to Google Chrome. I've read many answers about reparenting windows across processes, but I can't figure out what's happening in this case:

  • My Host (container) process happens to be doing aWaitForMultipleObjects on some Handles;
  • A Guest Process invokes a MessageBox, but hangs.

Doesn't the guest process run on a separate message queue? What am I missing?

I think I followed the best guidelines about SetParent when I embedded the Guest Form:

SetWindowLong(GuestHWnd, GWL_STYLE, GetWindowLong(GuestHWND, GWL_STYLE) and WS_EX_NOPARENTNOTIFY and (not WS_POPUP) or WS_CHILD);
SetParent(GuestHWnd, HostHWnd);
PostMessage(GuestHWnd, WM_UPDATEUISTATE, UIS_INITIALIZE, 0);
SendMessage(HostHWnd, WM_UPDATEUISTATE, UIS_INITIALIZE, 0);
SetWindowPos(GuestHWnd, 0, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_FRAMECHANGED);

Notice also that I haven't called any sort of AttachThreadInput. The problem doesn't arise if the Host is not blocked, or if the Guest window is not a child of a host's (obviously).

Thank you.

yankee
  • 509
  • 2
  • 9
  • 18
  • I suggest you to read [this](http://blogs.msdn.com/b/oldnewthing/archive/2011/03/31/10147981.aspx). I'm not sure it will solve your problem, but it can highlight some unconsidered details. – mg30rg Jul 01 '14 at 10:28
  • @mg30rg: please note that he uses "child/parent" and not "child/owner" relationship. Which in turn is explained in more recent post (see answer below) – Daniel Jul 01 '14 at 10:35
  • Thank you. I see it is a dangerous solution, so I think I'll go for a detached solution. – yankee Jul 01 '14 at 10:37
  • @Daniel Didn't you link the exactly same article? - Nevermind. I was just trying to feel smart. :D – mg30rg Jul 01 '14 at 10:42
  • 1
    This sounds exactly like my question [Parent window freezes when child window freezes altough it's from another process](http://stackoverflow.com/questions/16817112/parent-window-freezes-when-child-window-freezes-altough-its-from-another-proces) – Günther the Beautiful Jul 01 '14 at 11:04
  • @Gunther: Yes, it is exactly where I found the same link Daniel suggests below :-) – yankee Jul 01 '14 at 13:44

1 Answers1

1

I can only recommend Raymond chen's explanation to this: http://blogs.msdn.com/b/oldnewthing/archive/2013/04/12/10410454.aspx

Long story short:

Creating a cross-thread parent/child or owner/owned window relationship implicitly attaches the input queues of the threads which those windows belong to.

The problem is in this statement:

Notice also that I haven't called any sort of AttachThreadInput. The problem doesn't arise if the Host is not blocked, or if the Guest window is not a child of a host's (obviously).

Since it's a child/parent relationship, there IS an implicit AttachThreadInput.

Daniel
  • 1,041
  • 7
  • 13
  • 1
    I think its more comment than answer material. (And I have already commented about it. :v) – mg30rg Jul 01 '14 at 10:33
  • 1
    Thank you. I was just reading the same page in the meantime :-) I think I'll try a "detached" solution - No parent/child relationship – yankee Jul 01 '14 at 10:35