vc++_MFC多线程_线程间通信_主线程与子线程实例,实现控件更新

https://blog.csdn.net/txwtech/article/details/115696293

按钮触发事件,启动线程:

pThread=new CWinThread();
    pThread->m_bAutoDelete=false;
    // m_pMainDlg = ::AfxGetMainWnd();


    pThread=AfxBeginThread(ThreadProc, this);
    if(pThread==NULL)
    {
        //MessageBox(L"启动失败,自动关闭");
        //return FALSE;
    }
    b_ThreadRunning=TRUE;
void CInfoBridgeDlg::CheckRequestInfo()
{
    int cnt=0;

    cnt=m_ListCtrl_Entity.GetItemCount();             
    CString show_content=L"有请求,请处理";
    CString no_show_content=L"无请求";
    if(cnt>0)
    {
        if(timer_has_entity_id_count%2==1)
        {
            m_bSendMessage.Attach(IDC_BUTTON_SendMessage, this, RED, WHITE, DKGRAY);    
            Invalidate();
            SetDlgItemText(IDC_STATIC_entity_id_notification,show_content);
            FlashWindow(TRUE);
        }
        else
        {
            m_bSendMessage.Attach(IDC_BUTTON_SendMessage, this, BLUE, WHITE, DKGRAY);
            Invalidate();
        }


        timer_has_entity_id_count++;


    }
    else
    {
        timer_has_entity_id_count=0;
        m_bSendMessage.Attach(IDC_BUTTON_SendMessage, this, BLUE, WHITE, DKGRAY);
        Invalidate();
        SetDlgItemText(IDC_STATIC_entity_id_notification,no_show_content);
        FlashWindow(FALSE);
    }
    Sleep(1000);
}

bool b_ThreadRunning=TRUE;

// CInfoBridgeDlg message handlers
 static unsigned int ThreadProc(LPVOID pParam)
{
   while(b_ThreadRunning)
   {
       ((CInfoBridgeDlg*)pParam)->CheckRequestInfo();
       Sleep(1000);
   }
   return 0;
}
欢迎讨论,相互学习。 txwtech@163.com
原文地址:https://www.cnblogs.com/txwtech/p/15261452.html