我用this指针传了一个对话框的指针
threadID=AfxBeginThread(UpdateShowFunc,this);
然后再另一线程里面把它强制转换成对话框指针,其他的使用都行,但是就是在
UpdateData的时候出现好多
ASSERT警告:
ASSERT((p = pMap->LookupPermanent(m_hWnd)) != NULL ||
(p = pMap->LookupTemporary(m_hWnd)) != NULL);
ASSERT((CWnd*)p == this); // must be us
不知道为什么?
you can try Attach & Detach
first use this->m_hWnd or (HWND)this->Detach to pass thread parameter
then in your WinThread derived class, try
CMyDialog* pDlg=(CMyDialog*)CWnd::Attach(hwnd);
其实masterz说的应该是没错的,你说的错误会不会是其他原因引起的呢?
传递对话框句柄
交换数据不要采用ddv ddx
采用采用CMyDialog* pDlg=(CMyDialog*)CWnd::FromHandle(hwnd);
来重建对话框类应该不能同时重建数据交换机制。
所以最好自己用api更新就是了
UINT MyThreadProc( LPVOID pParam )
{
HWND hwnd = (HWND)pParam;
CAboutDlg adlg;
adlg.Attach(hwnd);
//use adlg here
adlg.Detach();//before adlg goes out of scope, detach it.
return 0; // thread completed successfully
}
你自定义一个消息,
你可以在线程结束时,向你的窗口类上面的那个消息,
同时,你在你的窗口处理过程中增加一个消息处理函数,
在这个消息处理函数里面进行UpdateData()。
可以这样试一试:
1。将m_hWnd作为参数传递。
2。另写一个全局函数对m_hWnd重绘)
3。在所开的新的线程中调用此函数。
以上方法我在播放AVI文件中使用正常