How to create a managed container control capable of hosting controls using only their handles?

O

ObsesivelyCurious

I have a question for all you smart people out there. I need to create
a managed windows forms control that can contain controls knowing only
their handles. In fact, all it really needs to do is host a single
control in such a way that from the user's perspective it looks as if
only one control existed. I need to accomplish this by using only the
handle of the hosted control. I figured something like this could be
achieved by overriding WndProc of the container control and forwarding
(most of the) messages to the hosted control. Of course, just blindly
forwarding all messages won't work, but just exactly which messages do
I need to forward? And is this even the right thing to think about?

I know it may seem like a convoluted way of doing things, but there is
a good reason. I could explain it at length, but here's just a brief
description. Basically, I need to have the container control in one
app domain and the hosted control in another app domain. Simply
getting a reference to the hosted control and trying to add it to the
container control breaks, because of the internal design of windows
forms, which doesn't work across app domains. However, I know for a
fact that my hosted control can successfully be contained in an
unmanaged control (here, an IE sidebar), which must happen via the old
fashioned Win32 messages. So I simply figured I could mimic this
behavior.

I would appreciate if anyone could share their insight.

Thanks,

Andrew
 
M

Mattias Sjögren

Of course, just blindly
forwarding all messages won't work, but just exactly which messages do
I need to forward? And is this even the right thing to think about?

You can use the SetParent Win32 API to move a control to a certain
parent. How that affects maanged controls, especially ones created in
different appdomains, I don't know.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top