当儿童窗口冻结时,父窗口冻结,来自另一个过程 [英] Parent window freezes when child window freezes altough it's from another process

查看:111
本文介绍了当儿童窗口冻结时,父窗口冻结,来自另一个过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:我不熟悉Win32 API,特别是Windows如何工作。此外,这是我在SO上的第一篇文章。这个问题可能是非常愚蠢的。

Disclaimer: I'm not familiar with the Win32 API, especially how windows work. Also, this is my first post on SO. This question might be incredibly stupid.

我想让一些进程的窗口是另一个进程的子窗口。这两个过程也是父母和子女。但我不认为那件事情。到目前为止,一切都像一个魅力一样 - 直到我冻结了子窗口的主线程。

I'd like to make the window of some process a child window of another process. The two processes are also parent and child. But I don't think that matters. So far, everything works like a charm - Until I freeze the main thread of the child window.

想像一下容器'not'和someApplication.exe

当我暂停一些 someApplication.exe 的主线程几秒钟,它的窗口被冻结那段时间。这是完全可以理解的。但是,容器的窗口同时挂起。其他托管进程的子窗口(如 notepad.exe )将继续正常运行。

When I suspend the main thread of someApplication.exe for a few seconds, its window is frozen for that amount of time. That's perfectly understandable. But the window of container.exe will also hang for the same time. The child windows of other hosted processes (like notepad.exe) will continue to work fine.

我正在使用 SetParent 命令使常规非子窗口成为我的container.exe的一个孩子:

I am using the SetParent command to make a regular non-child window a child of my container.exe:

SetParent(
    childProcess.HWND,
    myOwnHWND
);

之后,我使用 setWindowPos

SetWindowPos(
    childProcess.HWND,
    HWND_TOP,
    someXPos,
    someYPos,
    0,
    0,
    SWP_FRAMECHANGED or SWP_NOSIZE or SWP_SHOWWINDOW
)

由于 MSDN文章SetParent 建议,我还清除 WS_POPUP 样式属性,并添加一个 WS_CHILD 属性。既然这也没有帮助,我还添加了一个 WS_EX_NOACTIVATE 扩展样式属性,两者都使用 SetWindowLongPtr 命令。最后,我尝试发送两个窗口一个 WM_UPDATEUISTATE ,然后发送一个 WM_CHANGEUISTATE 消息,但也没有改变任何事情。

As the MSDN article on SetParent suggests, I also clear the WS_POPUP style attribute and add a WS_CHILD attribute. Since that didn't help either, I also added a WS_EX_NOACTIVATE extended style attribute, both by using the SetWindowLongPtr command. Finally, I tried sending both windows a WM_UPDATEUISTATE and then a WM_CHANGEUISTATE message but that also didn't change a thing.

令我困惑的是,父进程的窗口继续被正常绘制,直到我触摸它。然后它完全冻结,直到儿童窗户解冻。我怀疑有人称之为输入队列。 MSDN文章关于 WM_ACTIVATE 消息声明:

The thing that confuses me is that the window of the parent process continues to be drawn normally, until I touch it. Then it freezes completely until the child window unfreezes. I suspect something called an 'input queue'. The MSDN article about a WM_ACTIVATE message states:


发送到正在激活的窗口和窗口被禁用。如果windows 使用相同的输入队列,消息将同步发送 ,首先到顶级窗口的窗口过程被禁用,然后到窗口过程正在激活顶级窗口。如果窗口使用不同的输入队列,则该消息是异步发送的,因此该窗口立即被激活。

Sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately.

因此,我对 WS_EX_NOACTIVATE 扩展样式属性寄予厚望

Because of that, I had high hopes for the WS_EX_NOACTIVATE extended style attribute.

总结起来:实际上可以托管另一个进程的窗口,并且在子窗口冻结时不冻结自己的窗口?

To sum it up: Is actually possible to host the window of another process and to not freeze your own window when the child window freezes?

推荐答案

你不能期望阻止任何进程的GUI线程。在你的场景中,有两个GUI线程有点复杂。但是,通过在这些进程的窗口之间建立父/子关系,您还会引入两个GUI线程及时获得服务的要求。

You cannot expect to block the GUI thread of any process. In your scenario things are a little more complex because there are two GUI threads. One for each process.

处于父/子关系的Windows将发送对方的消息。如果这些消息是同步的,那么发送而不是发布,那么阻止一个GUI线程将导致另一个被阻止。

Windows that are in a parent/child relationship will send each other messages. And if those messages are synchronous, that is sent rather than posted, then blocking one GUI thread will lead to the other being blocked.

GUI编程的黄金规则保持在强制:不要阻止GUI线程。如果你有一个很长的运行任务,然后将其移动到后台线程。

The golden rule of GUI programming remains in force: do not block a GUI thread. If you have a long running task, then move it onto a background thread.

更新

确定,如此处所述当您将来自不同线程的窗口相关联时,将其消息队列相互连接。因此,如果您阻止一个线程,则阻止所有附加的线程。

OK, as explained here when you relate windows from different threads you attach their message queues to each other. And so if you block one thread, you block all of the attached threads.

所以,不要阻止GUI线程。

So, don't block a GUI thread.

这篇关于当儿童窗口冻结时,父窗口冻结,来自另一个过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆