IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    MFC 线程代码片段

    天下发表于 2016-12-13 02:09:00
    love 0

    貌似 挂起线程 必须在主界面的UI线程去操作

    UINT UiThreadProcessProtocol(LPVOID lParam)
    {
        CCalcPPIView
    * view = (CCalcPPIView*)lParam;
        DmcControler
    * Dmc = &(view->Dmc);

        
    while (1)
        {
            
    //AfxTrace("%u \n",GetTickCount());
            Sleep(500);
        } 
        
    return 0;
    }

    CWinThread
    * m_ThreadProcessProtocol;
    m_ThreadProcessProtocol 
    = AfxBeginThread(UiThreadProcessProtocol,this);

    void CCalcPPIView::OnBtnRegulate()
    {
        
    if (m_ThreadProcessProtocol!=NULL) {
            m_ThreadProcessProtocol
    ->SuspendThread();
            AfxTrace(
    "SuspendThread() at %u \n",GetTickCount());
        }
        
        {
            CRegulate dlg(
    this);
            dlg.DoModal();
        }
        
    if (m_ThreadProcessProtocol!=NULL) {
            m_ThreadProcessProtocol
    ->ResumeThread();
            AfxTrace(
    "ResumeThread() at %u \n",GetTickCount());
        }
    }

    void CCalcPPIView::CloseDevice(BOOL bUpdateUI )
    {
        CCalcPPIView
    * view = this;
        AfxTrace(
    "CCalcPPIView::CloseDevice() Entry \n");

        Dmc.SetOpened(
    0);

        
    if (view->m_ThreadProcessProtocol!=NULL) {
            WaitForSingleObject(view
    ->m_ThreadProcessProtocol->m_hThread,INFINITE);
            view
    ->m_ThreadProcessPro NULL;
        }
    }

     

     



    天下 2016-12-13 10:09 发表评论


沪ICP备19023445号-2号
友情链接