基本的MFC多线程

      多线程程序我本来是能够来写的。但是由于在图像处理的过程中,对于这方面知识使用的比较少,造成重复忘记的情况。这里再次进行整理学习,特别注重和“图像处理”理清关系,为下一步使用奠定基础。

这里实现的是工作者线程
在.h文件中定义
struct threadInfo
{
    UINT nMilliSecond;
    CProgressCtrlpctrlProgress;
};
UINT ThreadFunc(LPVOID lpParam); 
这些是需要在dlg文件外部的
CWinThreadpThread
在内部的。
在.cpp文件中,实现ThreadFunc,并且将参数进行转换
threadInfo Info
UINT ThreadFunc(LPVOID lpParam)
{
    threadInfopInfo=(threadInfo*)lpParam;
    for(int i=0;i<100;i++)
    {
        int nTemp=pInfo->nMilliSecond;
 
        pInfo->pctrlProgress->SetPos(i);
 
        Sleep(nTemp);
    }
    return 0;
}
最后在事件中进行驱动
void CMFCApplication1Dlg::OnBnClickedButton1()
{
    // TODO: 在此添加控件通知处理程序代码
    UpdateData(TRUE);
    Info.nMilliSecond=m_nMilliSecond;
    Info.pctrlProgress=&m_ctrlProgress;
 
    pThread=AfxBeginThread(ThreadFunc,&Info);
 
}
可以看到,线程的创建已经最后简化到了(函数名,参数)的形式,应该说是非常不错的。
但是反思一下,这种机制如何在图像处理中运用了?





原文地址:https://www.cnblogs.com/jsxyhelu/p/5493320.html