线程的创建步骤如下:
1.声明成员函数
UINT myThread(LPVOID pParam);
2.建立线程(仔细阅读以下代码)
AfxBeginThread(LThread,this); //添加声明线程的名字
//说明AfxBeginThread()返回值为CWinThread 类的指针,用类的指针来调用类的成员函数
/*
CWinThread* AfxBeginThread(
AFX_THREADPROC pfnThreadProc,
LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);
CWinThread* AfxBeginThread(
CRuntimeClass* pThreadClass,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);
*/
3.线程函数
UINT LThread(LPVOID pParam)
{
//编写该线程需要做的工作
// ......
return 0;
}
本人用的版本是VS2017 Enterprise