在线程持续时间内更改光标
在 MFC 应用程序中,我想在线程运行时显示等待光标(沙漏),但从
SetCursor(LoadCursor(NULL, IDC_WAIT));
静态 ThreadProc 成员函数内部调用没有任何效果。有什么帮助吗?
谢谢,RSel
编辑
搞清楚了。这是一种方法:
在构造函数中调用 LoadCursor:
m_cursor = LoadCursor(NULL, IDC_WAIT);
在 AfxBeginThread 之前调用 SetCursor:
SetCursor(m_cursor);
AfxBeginThread( ... );
覆盖 OnSetCursor 以防止光标过早变回原样:
CMyView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (m_thread_is_running)
{
return false;
}
else
{
return CView::OnSetCursor(pWnd, nHitTest, message);
}
}
In an MFC application I want to show the wait cursor (hour glass) for as long as a thread is running, but calling
SetCursor(LoadCursor(NULL, IDC_WAIT));
from inside the static ThreadProc member function doesn't have any effect. Any help?
Thanks, RSel
Edit
Figured it out. This is one way to do it:
Call LoadCursor in the constructor:
m_cursor = LoadCursor(NULL, IDC_WAIT);
Call SetCursor right before AfxBeginThread:
SetCursor(m_cursor);
AfxBeginThread( ... );
Overwrite OnSetCursor to prevent the cursor from changing back prematurely:
CMyView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (m_thread_is_running)
{
return false;
}
else
{
return CView::OnSetCursor(pWnd, nHitTest, message);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有检查过,但我认为每次鼠标移动时光标都会更新。因此,您可以在每次收到 WM_SETCURSOR 消息时调用 SetCursor(),或者更改默认光标。请注意,不应在每次设置光标时都调用 LoadCursor()。
默认光标在 WNDCLASS 窗口的结构。
有关详细信息,请参阅 WM_SETCURSOR。
I haven't checked, but I think that the cursor is updated every time the mouse moves. So you would either call SetCursor() every time you get a WM_SETCURSOR message or you change the default cursor. Note that you should not call LoadCursor() every time you set the cursor.
The default cursor is set in the WNDCLASS struct of a window.
See WM_SETCURSOR for more details.
当您启动线程时从主线程调用它,然后在线程退出时将自定义消息 PostMessage 到主线程并禁用该消息上的沙漏。
Call it form the main thread when you start the thread then PostMessage a custom message to the main thread when the thread exits and disable the hour glass on that message.