views:

89

answers:

1

Hi,

I'm trying to hijack an existing window and replace it with the contents of a Winforms I own. I figured it would be pretty cool swapping the form's inner handle with the one I want to override, and wondered if anyone ever tried it?

Cheers, Florian

A: 

This should easy to try if you are executing in the process and thread of the window you want to replace. If you aren't running on the process and thread of the original window then it's much less likely to work. If this is a part of the Windows shell that you are trying to replace, then it's very unlikely that you will get this to work.

If you can do the window replacement, you will have to respond the the parent window in the way that it expects the original child window to respond, but presumably you have already thought about that.

If the parent window is holding the window handle of the original child, then your attempt to replace it will just fail (it will still try and talk to the original handle). but if it's keeping track of the child by id, then all you have to do is give your window the same window id, and use SetWindowPos to give it the same size and location and z-order as the original child, and then destroy the original child.

I wish you luck, this is high risk behavior, but so are all of the other hacks that you could try instead like subclassing and hooking.

John Knoeller