The following reprint "Gu su old poplar": http://www.cnblogs.com/fdyang/archive/2012/06/15/2858730.html
Pass parameters to the thread through the struct.
Purpose: in a dialog box, click the button to start multiple threads calling external programs (batch), get the return value, and then update the results to multiple edit controls
idea: control data updates in the thread function by passing parameters to the threads through a struct that contains control information.
steps:
1. Create a struct in the header file XXXDlg.h of the dialog class, including a pointer to the control.
struct threadinfo{CEdit *pedit1_1; }
Next, declare the thread function: UINT threadfunc (LPVOID lpparam);
Note that both of the above should be outside the class Cxxxdlg.
2. Define public variables in the XXXDlg.cpp file: (global variable)
Threadinfo Mthreadinfo;
3. In the message handler function of the button, create the thread, calling the thread function. (1) Set the value of the instance of Threadinfo . mthreadinfo.pedit1_1=&edit1_1; //point to edit control //(2) Start a thread cwinthread *pthread=afxbeginthread ( threadFunc, &mThreadInfo, THREAD_PRIORITY_NORMAL, 0, create_suspended ); pthread->resumethread (); //(3) Add a threading function outside the class Uint threadfunc (lpvoid lpparam) { threadinfo *pinfo= ( threadinfo*) lpparam; //A pointer to an instance of the struct body. //calls the batch handler function and displays the returned result (CString) to the edit control. pinfo->pedit1_1->setwindowtext (Docheck (Batfilepath)); return 0; }