新建一个对话框工程;
添加2个编辑框,2个按钮;
对话框头文件添加,
public:
CWinThread *m_pthread1;
CWinThread *m_pthread2;
static UINT hellothread(LPVOID lparam);
static UINT testthread(LPVOID lparam);
CCriticalSection g_criticalsection;
BOOL flag;
int i1, i2;
对话框构造函数中添加,flag = true;
OnInitDialog()中添加,文章来源:https://www.toymoban.com/news/detail-802287.html
i1 = 0;
i2 = 0;
m_pthread1 = AfxBeginThread(hellothread, this, THREAD_PRIORITY_NORMAL, 0, 0);
m_pthread2 = AfxBeginThread(testthread, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
线程函数和按钮单击代码;文章来源地址https://www.toymoban.com/news/detail-802287.html
UINT CthrddemoDlg::hellothread(LPVOID lparam)
{
CthrddemoDlg *threadol = (CthrddemoDlg*)lparam;
while (threadol->flag)
{
//threadol->g_criticalsection.Lock();
threadol->i1 = threadol->i1 + 1;
threadol->SetDlgItemInt(IDC_EDIT1, threadol->
到了这里,关于MFC多线程编程示例1的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!