wxPython frames as children of foreign window?

Hi, I am considering using wxPython as it clearly offers so many
features. However, I have a large existing legacy application that already
includes a GUI. I would like to take things one step at a time,
such as adding in one wxPython frame and interactors, such as wxGrid,
but will need to have this be a child of my exiting window.
I can get existing window handles in C++. App is C++ based, uses
MFC and Motif on respective platforms. Ripping out the whole existing
GUI and replacing it with wxPython is tempting but not feasible in
the time frame.

Is this possible? Has anyone done this before? Are there examples to
follow?

Thanks! - Ian

···

--
-- ianc@acm.org ---

Ian Curington wrote:

Hi, I am considering using wxPython as it clearly offers so many
features. However, I have a large existing legacy application that already
includes a GUI. I would like to take things one step at a time,
such as adding in one wxPython frame and interactors, such as wxGrid,
but will need to have this be a child of my exiting window.
I can get existing window handles in C++. App is C++ based, uses
MFC and Motif on respective platforms. Ripping out the whole existing
GUI and replacing it with wxPython is tempting but not feasible in
the time frame.

Is this possible? Has anyone done this before? Are there examples to
follow?

It is theoretically possible, although I havn't really tried it. It is possible to create a wxWindow that wraps an existing HWND, and then you can use that as a parent for other windows, etc.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin, thanks!

Can you elaborate on this idea of creating a wxWindow that wraps an
existing HWND? What are the steps? Can I do it from python or
do I need to extend the wxWindows C++ layer?
Has anyone else on the list done this?

-Ian

···

In message Robin Dunn <robin@alldunn.com> writes:

It is theoretically possible, although I havn't really tried it. It is possible
to create a wxWindow that wraps an existing HWND, and then you can use that as a
parent for other windows, etc.

Ian Curington wrote:

Robin, thanks!

Can you elaborate on this idea of creating a wxWindow that wraps an
existing HWND? What are the steps? Can I do it from python or
do I need to extend the wxWindows C++ layer?

There is a wxWindow_FromHWND function (see below) in wxPython that has been there forever, but a couple months ago there was some messages on wx-dev or wx-users that made me think that I didn't do it right, but I havn't been able to look further into it since then because of higher priorities. I don't remember the details, but I think that there was one or two more steps needed to wrap wxWindow around the HWND, and more importantly the wxWindow should be "unsubclassed" when it is being destroyed. So perhaps it should be changed into a new C++ class that derives from wxWindow, does the right thing in it's contructor, and then in it's destructor does the unsubclassing.

If you are able to experiment with this and figure out the right thing to do (and a test case would be nice) I would appreciate it, otherwise I don't know when I will get to it. There is some code in wxWindow::CreateWindowFromHWND that can be used as a pattern (it can't be used directly because it is geared for creating specific wx controls on a wxWindow parent.)

Here is the current function, from wxPython/src/windows.i:

#ifdef __WXMSW__
%inline %{
wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
     wxWindow* win = new wxWindow;
     win->SetHWND(hWnd);
     win->SubclassWin(hWnd);
     return win;
}
%}
#endif

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I played with this a bit and was able to create child windows of a 3rd
party app (a 3D CAD program written in C++ using MFC, I assume) however
whenever events came into the picture it would crash. I could process
mouse clicks, etc. in the child window but minimizing the parent app, and
maximizing it again (thus minimizing and maximizing the child wxWindow)
would crash it. It seemed to be related to paint events. Anyway - I guess
it makes sense...the parent app has no clue about wxEvents.

I tried adding the window as one which blocked all events from passing up,
and I even tried writing my own OnPaint method but it didn't work as
expected. Anyway - it would be cool to be able to do this but it was
beyond my skills at the time to figure it all out (and probably still is).
If I get more time to play with it - I would definitely like to try to get
it working.

Mark.

···

Robin Dunn <robin@alldunn.com> wrote on 16/05/2003 01:16:23 PM: > Ian Curington wrote:

> Robin, thanks!
>
> Can you elaborate on this idea of creating a wxWindow that wraps an
> existing HWND? What are the steps? Can I do it from python or
> do I need to extend the wxWindows C++ layer?

There is a wxWindow_FromHWND function (see below) in wxPython that has
been there forever, but a couple months ago there was some messages on
wx-dev or wx-users that made me think that I didn't do it right, but I
havn't been able to look further into it since then because of higher
priorities. I don't remember the details, but I think that there was
one or two more steps needed to wrap wxWindow around the HWND, and more
importantly the wxWindow should be "unsubclassed" when it is being
destroyed. So perhaps it should be changed into a new C++ class that
derives from wxWindow, does the right thing in it's contructor, and then
in it's destructor does the unsubclassing.

If you are able to experiment with this and figure out the right thing
to do (and a test case would be nice) I would appreciate it, otherwise I
don't know when I will get to it. There is some code in
wxWindow::CreateWindowFromHWND that can be used as a pattern (it can't
be used directly because it is geared for creating specific wx controls
on a wxWindow parent.)

Here is the current function, from wxPython/src/windows.i:

#ifdef __WXMSW__
%inline %{
wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
     wxWindow* win = new wxWindow;
     win->SetHWND(hWnd);
     win->SubclassWin(hWnd);
     return win;
}
%}
#endif