Examples——C++线程

创建线程的例子:此代码是在微软基础类库(MFC)基础上编写。

void CThreadDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	if(h_thread == NULL)
	{
		h_thread = CreateThread(
			NULL, 0, &ThreadProc, this, 0, NULL); 		
	}
}
挂起线程
SuspendThread(h_thread);
恢复线程
ResumeThread(h_thread);
结束线程
TerminateThread(h_thread, 0);
CloseHandle(h_thread);
线程函数
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
	CThreadDlg* pthis = (CThreadDlg*)lpParameter;
	while(1)
	{
		pthis->m_go.StepIt();
		Sleep(100);
	}
	return 0;
}

m_go是控件变量。
线程函数中所写的就是你想要线程干的工作。




猜你喜欢

转载自blog.csdn.net/qq_36663718/article/details/80063057