Demonstrate how to create a thread and pass parameters to the thread function.
1. Create a dialog box-based MFC ApplicationProgram
2. Declare a thread function (select as a global function)
Uint killwindow (lpvoid pparam );
3. Implement thread Functions
Uint killwindow (lpvoid pparam) {bool bkilled = false; cstring * Title = (cstring *) pparam; while (! Bkilled) {hwnd = findwindow (null, * Title); If (hwnd) {: postmessage (hwnd, wm_close, null, null ); // close the specified window bkilled = true;} return 0 ;}
4. Call the API as needed. For example, add a button and click the event to call the API.
Void ctestfaxdlg: onbutton1 () {int iret; cstring srcdir = "D: \ srcfile"; cstring destdir = "d :\\ smart"; vector <cstring> list; cstring Title = "XXXXX"; afxbeginthread (killwindow, & title); // creates a thread that is used to close the list of windows with the title. push_back (_ T ("htm.htm "));......}
Then, when you click the button, the thread is created and running!