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);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With