VC++ MFC 对话框控件里,将一个响应函数通过多线程编程程序就执行不了了。请教是什么原因呢

VC++ MFC 对话框控件里,将一个响应函数通过多线程编程程序就执行不了了。请问是什么原因呢?
本来响应函数为:
[code=C/C++][/code]
void CDlg::function()
{
CvCapture* capture = 0;  
capture = cvCaptureFromCAM(0);  
if( !capture )
{
fprintf(stderr,"Could not initialize capturing...\n");

}  
for(;;)
{
IplImage* frame = 0;  
frame = cvQueryFrame( capture );
if( !frame )
break;  
CDC *pDC = GetDlgItem(IDC_STATIC)->GetDC();
CvvImage cimg;
HDC hDC= pDC->GetSafeHdc();
CRect rect;
GetDlgItem(IDC_STATIC)->GetClientRect(&rect);  
cimg.CopyOf(frame); //gFrame是那帧图像
cimg.DrawToHDC(hDC,&rect);  
ReleaseDC(pDC);
}
 
 cvReleaseCapture( &capture );
}
为了用多线程编程,我将它写在线程函数中,(为了能用全局函数,我定义了 CVideo dlg,也不知道是否正确)如下:
[code=C/C++][/code]
 DWORD WINAPI LoadVideo(LPVOID pParam)
 {
  CVideoDlg dlg;
CvCapture* capture = 0;  
capture = cvCaptureFromCAM(0);  
if( !capture )
{
//fprintf(stderr,"Could not initialize capturing...\n");
AfxMessageBox("Could not initialize capturing...");
}  
for(;;)
{
IplImage* frame = 0;  
frame = cvQueryFrame( capture );
if( !frame )
break;  
CDC *pDC = dlg.GetDlgItem(IDC_STATIC)->GetDC();
CvvImage cimg;
HDC hDC= pDC->GetSafeHdc();
CRect rect;
dlg.GetDlgItem(IDC_STATIC)->GetClientRect(&rect);  
cimg.CopyOf(frame); //gFrame是那帧图像
cimg.DrawToHDC(hDC,&rect);  
dlg.ReleaseDC(pDC);
}  
 cvReleaseCapture( &capture );
 return 1;
}
然后再通过CreateThread(或者AfxBeginThread函数,都用过了,不行)调用,结果编译没问题,但是点击按钮的时候弹出错误。不能运行。
由于不能上传图片,我描述下:
Debug Assertion Failed!
Program:......
File:winocc.cpp
Line:76
For information on how your program can cause anassertion failure,see the ......

------解决方案--------------------
1. 窗口对象不允许跨线程使用,所以你的目的无法实现

2. 在线程内部定义的那个dlg和你实际想操作的dlg毫无关系,楼主关于“实例”的概念还是需要搞搞

------解决方案--------------------
探讨
1. 窗口对象不允许跨线程使用,所以你的目的无法实现

2. 在线程内部定义的那个dlg和你实际想操作的dlg毫无关系,楼主关于“实例”的概念还是需要搞搞

------解决方案--------------------

1. 我有个问题,这里为什么一定要使用多线程?

2. 尝试一下,把 DC 作为参数传入线程启动函数。
------解决方案--------------------

恩。是要用多线程。

我对这个问题是这样考虑的。你关于动画的代码包括这么几个部分。

1. 准备 frame
2. 获得 dc
3. 绘制

由于你需要 dc ,因此选择了在线程中创建 Dialog。

但实际上,绘制这件事情跟 Dialog 是没有关系的。而 Dialog 阻碍了线程。

我建议你把 dc 作为线程的启动函数的参数,传入。它也可能是包含在某个结构中,结构做为参数传入。仍然使用工作线程好了。在Dialog初始化以后,也许是OnInitialize函数内,创建这个工作线程。