【发布时间】:2015-05-29 17:17:25
【问题描述】:
我有一个由多个线程组成的 MFC 应用程序,但问题出在特定的两个线程上。
- 第一个线程(CGuiThread)负责GUI(它不是主线程)并包含一个窗口对象(CMainWindow),其中包含一个内部窗口对象(CInnerWindow),它显示多个进度显示并具有滚动条。
- 第二个线程(CStatusDispatcherThread)负责向gui线程发送消息,其中包含一些计算过程相关的进度状态信息。
计算开始后,状态调度程序将带有状态的消息发送到 GUI 线程。 gui 线程相应地更新内部窗口中的进度条。
当我移动或按住内部窗口滚动条的拇指时,问题就开始了 - 由于进度条不再更新,GUI 线程似乎停止处理来自状态调度程序线程的状态消息。不仅如此,我希望状态消息在我释放 tumb 后在某处停止并处理,但它没有发生。新消息到达,但点击时的消息丢失。
如果有人知道可能是什么原因,我将非常感激。
我尝试在 CGuiThread::PreaTranslateMessage 函数中“捕捉”状态消息,但似乎在按住滚动拇指后,它们不再到达那里,即使 CStatusDispatcherThread 的 PostThreadMessage 指示它们已成功发送。
#define MY_MESSAGE 1
class CStatusDispatcherThread : public CWinThread
{
//...
// This class sends progress status percentaget to gui thread via PostThreadMessage
OnTimer(UINT nIDEvent)
{
PostThreadMessage(iThreadID,MY_MESSAGE,100,0);
}
};
class CGuiThread : public CWinThread
{
//...
BEGIN_MESSAGE_MAP(CGuiThread, CWinThread)
ON_THREAD_MESSAGE(MY_MESSAGE,OnStatusMessage)
END_MESSAGE_MAP()
private:
CMyMainWindow m_mainWindow;
void OnStatusMessage(WPARAM iStatus, LPARAM dummy);
{
m_mainWindow.updateStatus((int)iStatus)
}
};
class CMyMainWindow : public CWnd
{
//...
void updateStatus(int iStatus)
{
m_sbarWindow.updateStatusBar(iStatus);
}
private:
CInnerWindow m_sbarWindow;
};
class CInnerWindow : public CWnd
{
//...
void updateStatusBar(int iStatus)
{
//...
}
private:
BOOL Create(...)
{
CWnd::Create(strClassName, strWindowTitle, WS_DLGFRAME | WS_CHILD| WS_VISIBLE | WS_VSCROLL,
rectRectOfWnd, pParentWnd, iID, NULL);
}
void OnVScroll(nSBCode, nPos, pScrollBar)
{
//...
}
};
提前致谢, 加尔
【问题讨论】:
标签: multithreading mfc messages