[Original] Create a thread in VC and PASS Parameters

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.