471,338 Members | 1,127 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Odd Problem with SetParent

Hello to all,
I'm having something of a problem with the WinAPI call SetParent.
Here's the scenario.
I am trying to take an existing program, and run it within my own
window. I can make this
happen, the code looks like this:

/ Remove border and whatnot
long style = GetWindowLong(appWin, GWL_STYLE);
long new_style = WS_CHILD | WS_VISIBLE;
SetWindowLong(appWin, GWL_STYLE, new_style);

// Put it into this form
SetParent(appWin, this.panel1.Handle);
// Move the window to overlay it on this window
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
SendMessage((int)m_appWin, WM_PAINT, 0, "");

Where appWin is the handle to the main window of the program I start
with Process.Start and
Handle is the handle of the control I want to "reparent" the window
within. It works fine, the
application is "relocated" within my window. However...

For Itunes (which is the program I'm trying to reparent), I can launch
it, reparent it, and have
it display itself properly. However, once I do, it no longer receives
any mouse clicks. It doesn't
even act as if the mouse is getting to that window. I've checked to
see if the mouse clicks are
going to MY window handle, but they are not.

Any ideas?

Thanks
Matt
Jun 27 '08 #1
7 7191
On Thu, 08 May 2008 11:30:39 -0700, Matt <ma********@sprynet.comwrote:
[...]
For Itunes (which is the program I'm trying to reparent), I can launch
it, reparent it, and have
it display itself properly. However, once I do, it no longer receives
any mouse clicks. It doesn't
even act as if the mouse is getting to that window. I've checked to
see if the mouse clicks are
going to MY window handle, but they are not.

Any ideas?
Well, my first idea is that unless doing the exact same thing in an
unmanaged application works, but doesn't in your .NET application, this is
the wrong newsgroup for advice. I suspect that there's really nothing
about the question that relates to C# or .NET, and you'll get much better
advice posting to a newsgroup that is actually topical for the question.

Pete
Jun 27 '08 #2
On May 8, 12:40*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 08 May 2008 11:30:39 -0700, Matt <matttel...@sprynet.comwrote:
[...]
For Itunes (which is the program I'm trying to reparent), I can launch
it, reparent it, and have
it display itself properly. However, once I do, it no longer receives
any mouse clicks. It doesn't
even act as if the mouse is getting to that window. I've checked to
see if the mouse clicks are
going to MY window handle, but they are not.
Any ideas?

Well, my first idea is that unless doing the exact same thing in an *
unmanaged application works, but doesn't in your .NET application, this is*
the wrong newsgroup for advice. *I suspect that there's really nothing *
about the question that relates to C# or .NET, and you'll get much better *
advice posting to a newsgroup that is actually topical for the question.

Pete
Fair enough, I'm open to suggestions. What newsgroup would that be?

Matt
Jun 27 '08 #3
On Thu, 08 May 2008 11:46:37 -0700, Matt <ma********@sprynet.comwrote:
Fair enough, I'm open to suggestions. What newsgroup would that be?
I can't say for sure. However, typing "win32" into my newsreader's
newsgroup search interface, I find:

comp.os.ms-windows.programmer.win32
microsoft.public.win32.programmer
microsoft.public.win32.programmer.ui

I would expect any one of those to be more appropriate, and there may be
other newsgroups that don't have "win32" in the name that are also more
appropriate. You might try using "windows", "programmer", and/or
"programming" as other possible search terms.

Pete
Jun 27 '08 #4
On May 8, 2:30*pm, Matt <matttel...@sprynet.comwrote:
Hello to all,
* *I'm having something of a problem with the WinAPI call SetParent.
Here's the scenario.
I am trying to take an existing program, and run it within my own
window. I can make this
happen, the code looks like this:

* * * * * */ Remove border and whatnot
* * * * * * long style = GetWindowLong(appWin, GWL_STYLE);
* * * * * * long new_style = WS_CHILD | WS_VISIBLE;
* * * * * * SetWindowLong(appWin, GWL_STYLE, new_style);

* * * * * * // Put it into this form
* * * * * * SetParent(appWin, this.panel1.Handle);

* * * * * * // Move the window to overlay it on this window
* * * * * * MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
* * * * * * SendMessage((int)m_appWin, WM_PAINT, 0, "");
Where you got that code from?
I dnot think that you can do what you want (I might be wrong though).
Each program will have their own message pump and I don't know how you
are going to transfer the emsage from one to the other.
Jun 27 '08 #5
On May 8, 3:31*pm, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.comwrote:
On May 8, 2:30*pm, Matt <matttel...@sprynet.comwrote:


Hello to all,
* *I'm having something of a problem with the WinAPI call SetParent.
Here's the scenario.
I am trying to take an existing program, and run it within my own
window. I can make this
happen, the code looks like this:
* * * * * */ Remove border and whatnot
* * * * * * long style = GetWindowLong(appWin, GWL_STYLE);
* * * * * * long new_style = WS_CHILD | WS_VISIBLE;
* * * * * * SetWindowLong(appWin, GWL_STYLE, new_style);
* * * * * * // Put it into this form
* * * * * * SetParent(appWin, this.panel1.Handle);
* * * * * * // Move the window to overlay it on this window
* * * * * * MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
* * * * * * SendMessage((int)m_appWin, WM_PAINT, 0, "");

Where you got that code from?
I wrote it :)
I dnot think that you can do what you want (I might be wrong though).
Well, I've figured out a couple of ways to do most of this, I still
have some issues.
Each program will have their own message pump and I don't know how you
are going to transfer the emsage from one to the other.
The message pump really shouldn't matter. Clicks within the child
window should
be handled by it. At least I'd think so.

Matt

Jun 27 '08 #6
Hi Matt,
>>The message pump really shouldn't matter.
Of course it matters. Its message pump is not only on a different thread but
in a different process. We could speculate for example that the 'child'
thread attempts to route its messages to the outer frame window or some
other one of yours and then attempts to call its WindowProc. But this is in
a different process so different address space so the Window proc address is
garbage to the 'child'. So maybe it gets an exception and swallows the
message. Who knows really, but I'd be surprised if you could get this to
work.

Cheers
Doug Forster

Jun 27 '08 #7
On Thu, 08 May 2008 18:07:22 -0700, Doug Forster <no****@nowhere.com>
wrote:
Hi Matt,
>>The message pump really shouldn't matter.

Of course it matters. Its message pump is not only on a different thread
but in a different process. We could speculate for example that the
'child' thread attempts to route its messages to the outer frame window
or some other one of yours and then attempts to call its WindowProc. But
this is in a different process so different address space so the Window
proc address is garbage to the 'child'. So maybe it gets an exception
and swallows the message. Who knows really, but I'd be surprised if you
could get this to work.
Well, as the OP already said...for most applications it works fine, and
for iTunes it works fine at least at first.

Actually, it is not entirely uncommon for one process to host the window
of another process within itself. For example, OLE uses this for
out-of-proc servers. Windows will send the messages to the appropriate
window via the appropriate message queue (and thus the appropriate message
pump), assuming everything else has been configured correctly.

It's been so long since I've ever done anything like this, I can't
personally help the OP. And I really think that this newsgroup, where
most of the people are at the very least inexperienced with more
complicated unmanaged coding techniques, if not completely unfamiliar,
just isn't going to be a productive place to look for an answer.

It wouldn't surprise me if Willy or Ben, for example, know the answer to
the question but the fact is the OP is likely to have better luck in a
newsgroup where his question is actually on-topic.

Pete
Jun 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Raghavendran Muraleetharan | last post: by
8 posts views Thread by twoeyedhuman1111 | last post: by
reply views Thread by Jean Bon | last post: by
7 posts views Thread by Paul | last post: by
3 posts views Thread by miben | last post: by
reply views Thread by clarionprogrammer | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.