[Create] thread
The AfxBeginThread (outside thread function class, NULL);
The AfxBeginThread (thread function in a class, (LPVOID) the this );
[Thread function outside the class]
UINT function name (LPVOID pParam); // declared in header files, put outside class
UINT MyThreadA (LPVOID pParam) // cpp files embodied
{
}
[Thread function within the class]
static UINT function name (LPVOID pParam); // declared in header files, putting class
UINT CMFCApplication5Dlg :: MyThreadA (LPVOID pParam) // cpp file realization
{
}
[Case] IDC_OUTPUT_1 - Static Text
MyThreadA UINT (LPVOID pParam) { for ( int I = 0 ; I <= 100 ; I ++ ) { SetDlgItemInt (AfxGetApp () -> m_pMainWnd-> m_hWnd, IDC_OUTPUT_1, I, to false ); // window handle, particularly the control ID Sleep ( 100 ); } return 0 ; } void CMFCApplication5Dlg :: OnBnClickedButton1 () { // the TODO: in this addition control notification handler code the AfxBeginThread (MyThreadA, NULL ); }
UINT CMFCApplication5Dlg :: MyThreadA (LPVOID pParam) { CMFCApplication5Dlg * DLG = (CMFCApplication5Dlg * ) pParam; for ( int I = 0 ; I <= 100 ; I ++ ) { DLG -> SetDlgItemInt (IDC_OUTPUT_1, I, to false ); Sleep ( 100 ); } return 0 ; } void CMFCApplication5Dlg :: OnBnClickedButton1 () { // the TODO: in this addition control notification handler code the AfxBeginThread (MyThreadA, (LPVOID) the this ); //Passing this pointer }