且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在另一个应用程序中创建一个子窗口

更新时间:2023-11-22 14:16:16

Windows 有 线程关联.这意味着创建窗口的线程将处理该窗口的消息.此外,父子链中的所有窗口都应该由同一个线程处理.否则,坏事发生.

Windows have thread affinity. This means that the thread that creates the window will be processing the messages for that window. Furthermore, all windows in a parent-child chain should be processed by the same thread. Otherwise, bad things happen.

那么 - 您的代码是如何运行的?如果它是一个单独的可执行文件,那么***将窗口保留为***窗口,并简单地监视目标窗口的移动事件(使用 UI 自动化,例如)并让您的窗口适当移动.

So - how is your code being run? If it's a separate executable, you're going to be much better off leaving your window as a top-level window, and simply monitoring the target window for move events (using UI Automation, for example) and having your window move appropriately.

否则,您将需要将代码注入游戏可执行文件中,并让它在适当的线程上创建窗口.我不建议这样做.

Otherwise, you're going to need to inject your code into the game executable, and have it create the windows on the appropriate thread. I wouldn't recommend that.