在线程持续时间内更改光标 [英] Change cursor for the duration of a thread

查看:98
本文介绍了在线程持续时间内更改光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MFC应用程序中,只要线程正在运行,我想显示等待光标(沙漏),但是调用

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));

静态ThreadProc成员函数内部的

无效.有帮助吗?

from inside the static ThreadProc member function doesn't have any effect. Any help?

谢谢,RSel

修改

弄清楚了.这是一种方法:

Figured it out. This is one way to do it:

在构造函数中调用LoadCursor:

Call LoadCursor in the constructor:

m_cursor = LoadCursor(NULL, IDC_WAIT);

在AfxBeginThread之前调用SetCursor:

Call SetCursor right before AfxBeginThread:

SetCursor(m_cursor);
AfxBeginThread( ... );

覆盖OnSetCursor以防止光标过早地变回原处:

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);
    }
}

推荐答案

我没有检查,但是我认为每次鼠标移动时都会更新光标.因此,您将在每次收到WM_SETCURSOR消息时调用SetCursor()或更改默认光标.请注意,您不应在每次设置游标时都调用LoadCursor().

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.

默认光标在 WNDCLASS中设置窗口的结构.

The default cursor is set in the WNDCLASS struct of a window.

有关更多详细信息,请参见 WM_SETCURSOR .

See WM_SETCURSOR for more details.

这篇关于在线程持续时间内更改光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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