【问题标题】:calling Beginwaitcursor function from worker thread in MFC从 MFC 中的工作线程调用 Beginwaitcursor 函数
【发布时间】:2016-02-08 13:54:43
【问题描述】:

有人可以帮助我理解 VC++(MFC) 中的工作线程吗? 以下是我的工作线程函数

UINT ThreadFunc(LPVOID pParam)
{
// some initialization... etc..

AfxGetApp()->BeginWaitCursor();

...
..
/// some operations

AfxGetApp()->End WaitCursor();

}

可以从工作线程调用 WaitCursor() 函数吗?

【问题讨论】:

  • “没问题”,但不会达到预期的效果。 UI 线程将立即更改它们。更好的解决方案是在窗口/对话框本身上显示一个控件,指示后台正在发生某些事情。
  • 在 MFC 中你可以使用CWaitCursor x; 并且当x 超出范围时完成。然而,由于前面解释过的原因,它在这里仍然没有做任何事情。

标签: c++ multithreading mfc


【解决方案1】:

BeginWaitCursorEndWaitCursor 的可用文档未提及与线程相关的问题。

提到的一件事,

BeginWaitCursor 的操作在单个消息处理程序之外并不总是有效,因为其他操作(例如 OnSetCursor 处理)可能会更改光标。

当您的工作线程工作时,其他线程也可以更改光标。

如果将ON_WM_SETCURSOR() 宏添加到CWnd 派生类的消息映射中,您还需要考虑处理WM_SETCURSOR 消息的CWnd 消息处理程序OnSetCursor() 的操作。见Prevent MFC application to change cursor back to default icon

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-02
    • 2011-10-27
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    相关资源
    最近更新 更多