问题描述
我已经为三个线程创建了三个复选框控件,每个都将通过检查复选框控件开始。当用户取消选中复选框时,我想打开其他线程控件上的等待游标,而不是完全禁用它们的时间实例,让特定的线程停止。
I have created three checkbox controls for three threads and each would start by checking a checkbox control. When a user unchecks a checkbox, I want to turn on the Wait Cursor on the other thread controls rather than completely disabling them for an instance of time, letting a particular thread to stop.
如何为特定控件设置IDC_WAIT游标ID或者应该让用户按顺序自由启动/停止多个线程?
How would you set a IDC_WAIT cursor id for a specific control or should i let the user to freely start/stop multiple threads in order?
推荐答案
很多人不明白等待游标是怎么样的...我犹豫说要工作。
Many people do not understand how "wait" cursors are ... I hesitate to say indended to work.
邮件的历史真的然而,告诉:WM_SETCURSOR自Windows 3.1以来就一直存在 - 一个16位的协同操作多任务操作系统。因为只有一个线程(正在进行协同多任务处理),当应用程序忙时,非驱动程序级代码不可能运行。因此,忙游标的处理方式如下:
The history of the message is really telling however: WM_SETCURSOR has existed since Windows 3.1 - a 16 bit co-operatively multitasked operating system. Because there was only a single thread (Being co-operatively multitasked) - it was not possible for non driver level code to run while an application was "busy". Hence, the handling for "busy" cursors was like this:
WM_SETCURSOR将始终以适当的非忙碌光标进行响应。
WM_SETCURSOR would always respond with the appropriate "non busy" cursor.
任何繁忙的代码将如下所示:
Any code that was going to be "busy" would look like:
SetCursor(hHourglass);
DoBusyThing();
SetCursor(hRegular);
这会将硬件光标更改为沙漏 - DoBusyThing会占用线程,而WM_SETCURSOR消息不会,并且无法处理,直到它退出。
This would change the hardware cursor to the hourglass - DoBusyThing would occupy the thread, and WM_SETCURSOR messages would not, and could not, be handled until it exited.
Win32改变了语义一点 - 它记住每个线程的最后一个光标一个窗口上的线程集 - 允许Windows 3.1的协作逻辑在异步多任务Win32环境中工作:如果一个线程很忙(即没有消息),那个线程上的窗口的WM_SETCURSOR消息只会在消息队列中被卡住 - 因此沙漏光标仍然存在
Win32 changed the semantics a little - It remembers on each thread the last cursor a window on that thread set - allowing the co-operative logic of Windows 3.1 to work in the casynchronously multitasked Win32 environment: If a thread is busy (i.e. not pumping messages) WM_SETCURSOR messages for windows on that thread will just get "stuck" in the message queue - hence the hourglass cursor remains the default cursor for all windows owned by the blocked thread, until the busy operation completes and the thread returns to the message processing loop.
当然,这个逻辑没有一个工作原理在现代世界中,我们不再阻塞UI线程: - 忙碌的工作现在偏移到一个工作线程,意味着UI线程调度WM_SETCURSOR消息,并将忙碌的光标重置为类光标。
Of course, none of this logic works really well in the modern world where we no longer block UI threads:- The busy work is now offset to a worker thread, meaning the UI thread is dispatching WM_SETCURSOR messages and resetting the busy cursor back to the class cursor.
这不是一个真正的问题:等待游标总是意味着应用程序是不响应,一个正常的UI线程+繁忙的工作线程不是这个反馈机制真正设计或打算
This is not really a problem: The wait cursor have always implied that the application is non responsive and a functioning UI thread + busy worker thread is not what this feedback mechanism is really designed or intended to cover.
我认为正确的做法是将光标单独放置,并在UI上反映其他方式(停止按钮旁边的图标)进一步的线程不能/不应该启动。
I think the correct thing to do would be to leave the cursor alone, and reflect on the UI some other way (stop icons next to the buttons?) that further threads can not / should not be launched.
这篇关于在线程控制上等待光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!