Re: SetParent across processes - how does OLE do!? Focus and painting problems.

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: anon (geek_at_internet.com)
Date: 04/07/04


Date: Wed, 7 Apr 2004 15:57:33 -0700

OLE just uses SetParent and SetWindowPos - nothing fancy - and i've not seen
anything to say SetParent doesn't work across process boundaries - it
obviously does .. although theres something about a task switch that
happens when you sendmessage from child to parent or visa-versa... the
sending UI thread effectivly gets suspended until the call returns...
(don't quote me on that)
does your child window depend on its original parent to do any of it's
painting? or anything at all for that matter?
if it does, then re-parenting would obviously pull the rug from under its
feet in a nasty way...

"aron" <anonymous@discussions.microsoft.com> wrote in message
news:00273CC9-5335-4413-A249-A92D95841375@microsoft.com...
> When I embed an Excel spread*** within a Word document, Excel runs in a
separate process within the Word document window. All window painting works
flawlessly and Excel can display modal dialogs that are modal to the
"parent" process, i.e. Word, as well. I'd like to do the same but without
involving OLE.
>
> I've written an out-of-process plug-in for an imaging application. The
plug-in acquires the host window handle and uses SetParent to put its main,
top-level window (which is a .Net System.Windows.Forms.Form, but I guess
that shouldn't really matter) inside the host application window. It also
calls SetWindowLong to add the WS_CHILD style, and SetWindowPos because
according to the MSDN docs, this is required after calling SetWindowLong.
Everything works as I like - plug-in is contained within host application
window and follows when I move the host application window etc - except for
two things:
>
> 1) The new window is not repainted as it should. Seems like it doesn't
receive paint messages at all.
> 2) When showing modal dialogs (using Form.ShowDialog), these aren't modal
within the plugin process nor within the host application process - i.e. I
can change focus to any other control (the dialog stays on top though). If I
click a dialog it usually receives focus for a short while (like half a sec)
but then focus is lost, I think to the top-level window in the hosting
application. If I have the plug-in run without calling SetParent,
SetWindowLong, and SetWindowPos, painting works ok and my dialogs are modal
as you would expect.
>
> I've spent quite some time searching the newsgroups and the web and found
out that a lot of people seem to have similar problems, but nowhere have I
found a solution. MSDN docs say SetParent shouldn't be used across processes
but again: how does OLE do, then!? I'm sure there's some way around this.
I'm able to add code in both processes and so it would be possible to
forward window messages from the host process to the plug-in though that
doesn't sound very appealing...also, I wouldn't know which messages to
forward. Any and all suggestions are greatly appreciated. Thanks.


Quantcast