Search code examples
wxwidgets

wxFrame does not receive events


I have a somewhat complicated application, where in one scenario the events do not arrive at my main window.

Scenario 1: a wxFrame is created the usual way, UI elements are added to it and events are linked to that wxFrame via Connect() or via event-table. This works properly.

Scenario 2: the same application is used by a caller from outside. This caller opens a native (means non-wxWidgets) window and provides the HWND handle of this window or of an sub-element (e.g. some kind of sub-panel). Now within the same constructor of the wxFrame mentioned above, I call this sequence to let this wxFrame make use of the callers HWND instead of opening an own one:

SetHWND((WXHWND)in_initValues->hWnd);
SubclassWin((WXHWND)in_initValues->hWnd);
AdoptAttributesFromHWND();
wxTheApp->SetTopWindow(this);

This code snippet was taken somewhere from the wxWidgets examples. It works partially, means the wxFrame is not opened as separate window any more but the application makes use of the HWND to display its contents there. But as said, none of my events arrive in this scenario.

So...any idea what could be wrong or missing here?

Thanks :-)


Solution

  • First of all, you should be really using wxNativeContainerWindow instead of the hack above.

    Second, the most obvious explanation for not getting events is not running the wx event loop -- as you probably don't, because you run the message loop of the other application. You need to feed the relevant events to wx, as is done by wxMFCApp from wx/msw/mfc.h, for example.