我做了一个程序,现在我简单的给大家描述下逻辑:
我建立一个对话框(直接拖放的,非动态生成的),然后上面有个进度条,这个对话框启动的时候,就是要启动一个线程(这个线程是在这个窗口产生的类中的静态函数),然后开始下载。而这个线程需要向模态对话框传递消息,就是一直传递下载的进度啦。
然后下次有人再次点击的时候,我一看有个这个实例在运行,就直接在下载队列的末尾加载这个新的下载项,这也涉及到发送消息的问题,请问,我怎么才能解决呢?两次发送消息:
情况一:它自己启动的线程(静态函数),向它发送下载进度
情况二:需要向这个对话框发送下载任务消息;
但是好像模态对话框直接阻塞了,高手请指点,我在这洗耳恭听
我建立一个对话框(直接拖放的,非动态生成的),然后上面有个进度条,这个对话框启动的时候,就是要启动一个线程(这个线程是在这个窗口产生的类中的静态函数),然后开始下载。而这个线程需要向模态对话框传递消息,就是一直传递下载的进度啦。
然后下次有人再次点击的时候,我一看有个这个实例在运行,就直接在下载队列的末尾加载这个新的下载项,这也涉及到发送消息的问题,请问,我怎么才能解决呢?两次发送消息:
情况一:它自己启动的线程(静态函数),向它发送下载进度
情况二:需要向这个对话框发送下载任务消息;
但是好像模态对话框直接阻塞了,高手请指点,我在这洗耳恭听
void CWnd::AssertValid() const
{
if (m_hWnd == NULL)
return; // null (unattached) windows are valid // check for special wnd??? values
ASSERT(HWND_TOP == NULL); // same as desktop
if (m_hWnd == HWND_BOTTOM)
ASSERT(this == &CWnd::wndBottom);
else if (m_hWnd == HWND_TOPMOST)
ASSERT(this == &CWnd::wndTopMost);
else if (m_hWnd == HWND_NOTOPMOST)
ASSERT(this == &CWnd::wndNoTopMost);
else
{
// should be a normal window
ASSERT(::IsWindow(m_hWnd)); // should also be in the permanent or temporary handle map
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL); CObject* p;
// 在下面一句出错
ASSERT((p = pMap->LookupPermanent(m_hWnd)) != NULL ||
(p = pMap->LookupTemporary(m_hWnd)) != NULL);
ASSERT((CWnd*)p == this); // must be us // Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
}
}
注意这几句:
In general, CWnd objects should be passed by HWND from
one thread to another. The receiving thread can wrap
the HWND with a CWnd object by using CWnd::FromHandle. 一般地,CWnd对象应该转递句柄从一个线程到另一个线程。接收线程可以通过CWnd::FromHandle函数获取一个CWnd对象。