简体   繁体   English

工作线程使主线程MFC处于非活动状态对话框

[英]Work thread makes inactive dialog of the main thread MFC

I have MFC dialog based app that has one dialog. 我有一个对话框的基于MFC对话框的应用程序。 On button click i start another work thread. 在按钮上单击我开始另一个工作线程。 Unfortunately, while function of work thread is running a can not access to controls on my dialog. 不幸的是,工作线程功能正在运行时,无法访问我的对话框上的控件。

void CrMainDlg::OnBnClickedButton1()
{
   //...
   CWinThread* fonThread = AfxBeginThread(WorkerThreadProc, iP, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
   //...
 } 

UINT CrMainDlg::WorkerThreadProc(LPVOID Param)
{
//...
       while(/*some bool*/)
       {
           //makesomething
           Sleep(1000);
       }
       //...
}

Only if i write Sleep(1000) i could have access to ScrollBar or another button or something else on the main dialog. 仅当我编写Sleep(1000)时,我才能访问ScrollBar或其他按钮或主对话框中的其他内容。 If i do not - i could access to controls only after while ends... 如果我不这样做-我只能在结束后才能访问控件...

What am i doing wrong? 我究竟做错了什么?

(1) The worker thread function must be static. (1)工作线程函数必须是静态的。 If it is not declared static the code you have posted will not compile. 如果未声明为静态,则您发布的代码将无法编译。 (2) The worker thread should not access any controls, only data. (2)工作线程不应访问任何控件,而只能访问数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM