本文介绍了如何使另一个应用程序窗口的 wx 窗口成为父窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何让别人的应用程序窗口成为我的 wx 窗口的父窗口.

我知道这是可能的,因为 twain 模块就是这样做的.

例如,您可以传入 pygame.display 的句柄,它将充当将出现的扫描对话框的父级.你可以直接给它一个你的 Tk() 或 wx.Frame() 的句柄(但无论如何它只会抓取句柄号).

或者你可以传入一个完全不同的应用程序的句柄,例如记事本.

我想实现这一目标.以便我的 wx 对话框或弹出窗口以模态模式显示在另一个应用程序上.

您已经推断出我想在 MS Windows 上执行此操作.嗯,我想跨平台做,但其他平台也不会傻到让任何人在其他应用程序的界面上乱作一团.我当然认为这是可能的,但要困难得多.因此,目前仅适用于 Windows.

我想为此我需要模拟 wx.Window 或 Frame 或 Panel 或基于所选窗口句柄的东西以将其传递给我的对话框.或者类似的东西.

有什么想法吗?

解决方案

我没有解决我的问题.对我来说幸运的是,客户端应用程序和我想成为其父应用程序的应用程序都是我的,所以我使用 wxPython 重写了父应用程序,并在其中添加了必要的接口,即创建了新应用程序.起初我不愿意这样做,这就是我寻找育儿"解决方案的原因.

然而,在这 2 年里,我偶然发现了一些关于它的有用信息:

  1. 我发现了一个名为 _CreateWindowFromNativeWindow() 或 _CreateWindowFromHandle() 之类的工厂函数.这是 wxPython 中的一个内部函数,但就我所见,它可以从我们的代码中调用.但是因为对它的热爱,我再也找不到它了.我没有尝试过,所以这只是一个提示.也许有人可以把它挖出来.

  2. 我找到了 wx.Window.AssociateHandle() 方法,但是这是真实的并且应该可以工作.我们不能在没有父级的情况下创建 wx.Window(),但是我们可以创建 wx.Frame().所以是这样的:

f = wx.Frame(无)f.AssociateHandle(hwnd)

应该可以.现在 f 应该链接到另一个应用程序的本机窗口,如果 hwnd 是正确的并且我们有适当的权限,我们应该能够将它用作其他 wx 窗口的父窗口.谁尝试过,请发表评论让我们知道它是否按预期工作.

如果我们知道如何让 wxWidgets 意识到操作系统改变了窗口的句柄,那么总是有一个 ctypes 解决方案.我没有,因为我停下来看那个方向.此外,还有一个解决方案,通过修改wxPython源并构建它们来暴露wxWidgets的未记录方法setHWND(),根据某些来源应该存在该方法.

I wish to know how to make another's application window be a parent to my wx window.

I know that it is possible because twain module does just that.

For instance, you can pass in pygame.display's handle and it will act as a parent of scanning dialog that will appear.You can give it a handle of your Tk() or wx.Frame() directly (but it will grab out only the handle number anyway).

Or you can pass in a handle of completely different application, notepad for example.

I would like to achieve this. So that my wx dialog or pop up window appear in Modal mode over another application.

You already deduced that I want to do it on MS Windows.Well, I'd like to do it cross-platform, but other platforms aren't so stupid to let anyone messing in other app's interface.Sure I think it is possible, but much harder. So, for now Windows only.

I guess for this I will need to emulate wx.Window or Frame or Panel or something based on a chosen window handle to pass it to my dialog. Or something like that.

Any ideas?

解决方案

I did not resolve my problem. Fortunately for me, both applications, the client one, and the one that I wanted to be its parent, were mine, so I rewrote the parent one using wxPython and added necessary interface into it, i.e. created the new application. I was unwilling to do that at first, that's why I searched for a "parenting" solution.

However, In this 2 years I happen to stumble on some useful info about it:

  1. I found a factory function called something like _CreateWindowFromNativeWindow() or _CreateWindowFromHandle() or something like that.That was an internal function in wxPython but was callable from our code as far as I saw. But for the love of it I cannot find it again. I did not try it, so it is a tip only. Perhaps somebody can dig it out.

  2. I found the method wx.Window.AssociateHandle() This however is real and should work. We cannot create a wx.Window() without a parent, but wx.Frame() we can. So something like this:


f = wx.Frame(None)
f.AssociateHandle(hwnd)

should work. Now f should be linked to the native window of another app, if the hwnd is right and we have appropriate permissions, and we should be able to use it as a parent for other wx windows. Whomever tries it, please post a comment to let us know whether it works as expected.

There is always a ctypes solution if we know how to make wxWidgets realise that the OS changed a handle of the window. I don't because I stopped to look in that direction. Also, there is a solution of exposing undocumented method setHWND() of wxWidgets, which should exist according to some sources, by modifying the wxPython sources and building them.

这篇关于如何使另一个应用程序窗口的 wx 窗口成为父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:22