什么线程处理在.net模式对话框窗口?线程、对话框、窗口、模式

2023-09-04 03:11:42 作者:无情便是王

我有GUI线程消息循环的pretty的基本认识,但我很好奇,如何适用于一个窗口启动一个模态窗口。如果我猜的话,我会说这两个窗口都被以相同的GUI线程,而一些参数表明只有在子窗口(模态的)事件中执行运行,否则指出模态窗口,给用户

I have a pretty basic understanding of the GUI thread and the message loop, but I'm curious as to how that applies to one window starting a modal window. If I had to guess, I'd say that both windows are being run under the same GUI thread and that some parameter indicates that only events with the child window (the modal one) be executed, otherwise point out the modal window to the user.

这是一个简单的半猜测,我承认我可能是错的广场之一。我甚至不知道GUI线程是正确的名称,该线程,但人们通常能猜到我说的。

This is simply a semi-educated guess and I accept that I may be wrong from square one. I'm not even sure if "GUI thread" is the right name for that thread, but people usually can guess what I'm talking about.

因此​​,在短期,如何线程和模态窗口相处在一起吗?

So in short, how do threads and modal windows get along together?

推荐答案

这也许是矛盾的,但没有,没有新的线程启动了新的窗口。然而,一个新的消息循环被打开。这样可以使流经Windows消息,并避免暂停其他应用程序。

This maybe contradictory, but no, no new thread is started for the new windows. However, a new message loop is opened. This keeps messages flowing through Windows and avoids halting other applications.

消息将到达,可分派给所有者窗口的消息循环。在所有者窗口,键盘和鼠标输入被禁用,但所有其他信息将被发送至。 注意从汉斯帕桑特:其实,同样的线程中的所有顶级窗口将被禁用这种方法的

Messages will arrive and may be dispatched to the owner window's message loop. On the owner window, keyboard and mouse input have been disabled, but all other messages will be send through. Note from Hans Passant: actually, all top level windows of the same thread will be disabled this way.

正如你已经触及到你的问题的一个例子, WM_PAINT 是通过发送到父窗口。而且 WM_TIMER ,例如。如 WM_NCHITTEST 的消息将不会被发送过,因为它是一个输入消息。也不会对 WM_KEYDOWN 和类似。

As an example that you already touch on in your question, WM_PAINT is send through to the parent window. But also WM_TIMER, for instance. A message like WM_NCHITTEST will not be send through, as it is an input message. Nor will WM_KEYDOWN and similar.

这样,一个消息可以移动,和底层的业主被整齐地重新粉刷,或滴答作响的时钟仍继续滴答作响。

This way, a messagebox can be moved, and the underlying owner gets neatly repainted, or a ticking clock still continues ticking.

部分从校长和新人的Win32编程,页面信息752+,老了,但仍然是有价值的和有效的信息。此信息适用于 DialogBox的 DialogBoxParam DialogBoxIndirect 和DialogBoxIndirectParam 以及任何的 ..恩版本。在内部,这些Win32 API函数被称为的WinForms 的

Information partially from Rector and Newcomer's Win32 Programming, page 752+, old, but still valuable and valid info. This info applies to DialogBox, DialogBoxParam, DialogBoxIndirect and DialogBoxIndirectParam as well as any of the ..Ex versions. Internally, these Win32 API functions are called by WinForms.