MFC 点击按钮穿件线程,分为四步:
1、按钮响应OnBnClickedButtonStart()
2、开始创建线程:CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Thread_point, LPVOID(this), 0, NULL);
3、静态线程入口 Thread_point() , 必须位 static DWORD 类型
4、调用成员函数StartCalc(),真正的功能函数,做一系列的处理。
头文件
afx_msg void OnBnClickedButtonStart();
static DWORD CtoushizhuanhuanDlg::Thread_point(LPVOID lparam);
void CtoushizhuanhuanDlg::StartCalc();
cpp文件
void CtoushizhuanhuanDlg::OnBnClickedButtonStart()
{
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Thread_point, LPVOID(this), 0, NULL);
}
//静态入口线程
DWORD CtoushizhuanhuanDlg::Thread_point(LPVOID lparam)
{
CtoushizhuanhuanDlg* pthis = (CtoushizhuanhuanDlg*)lparam;
pthis->StartCalc();
return 0;
}
void CtoushizhuanhuanDlg::StartCalc()
{
}