英文:
wxFrame does not receive events
问题
Scenario 1: 创建一个wxFrame,通常的方式,向其中添加UI元素,并通过Connect()或事件表将事件与该wxFrame关联。这正常工作。
Scenario 2: 相同的应用程序由外部调用者使用。这个调用者打开一个本机(非wxWidgets)窗口,并提供此窗口或子元素(例如某种子面板)的HWND句柄。现在,在上面提到的wxFrame的构造函数中,我调用以下序列,让这个wxFrame使用调用者的HWND来显示其内容,而不是打开一个新的窗口:
SetHWND((WXHWND)in_initValues->hWnd);
SubclassWin((WXHWND)in_initValues->hWnd);
AdoptAttributesFromHWND();
wxTheApp->SetTopWindow(this);
这段代码片段是从wxWidgets示例中提取的。它部分地工作,也就是说,wxFrame不再作为单独的窗口打开,但是在这种情况下,我的事件都不会到达。
所以...有什么想法,可能出了什么问题或遗漏了什么吗?
谢谢
英文:
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
答案1
得分: 1
首先,你应该真正使用wxNativeContainerWindow
,而不是上面的 hack。
其次,不获取事件的最明显解释是没有运行 wx 事件循环 -- 可能是因为你运行了其他应用程序的消息循环。你需要将相关事件传递给 wx,就像wx/msw/mfc.h
中的wxMFCApp
那样做的一样。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论