Multi-thread Summary!

Source: Internet
Author: User

You can simply use afxbeginthread in MFC.
Use cwinthread * to declare a thread, define a thread function, and use afxbeginthread to enable the thread function ~
For example:
Cwinthread * pthreadtest; </P> <p> uint _ testthread (lpvoid lparam) <br/>{</P> <p> hwnd hdlg = findwindow (null, text ("dxxtest"); // obtain the hwnd of another window <br/> cstring STR; <br/> // hwnd hdlgbtn = findwindow (null, text ("Stop Service"); <br/>: sendmessage (hdlg, wm_command, idc_button2, 0 ); // send a message to the idc_button2 button in the hdlg window <br/> for (INT I = 1; I <1000; I ++) <br/>{< br/> Str. format (text ("% d Service started! "), I); </P> <p> setdlgitemtext (hdlg, idc_static, STR); <br/> sleep (1000 ); <br/>}< br/> return 0; <br/>}</P> <p>
// Enable the thread in a proper place
Pthreadtest =: afxbeginthread (_ testthread, this );

 

For example:

Void cdxxtestdlg: onbnclickedbutton1 () <br/>{< br/> // todo: add the control notification handler code here <br/> cwinthread * pthreadtest; <br/> getdlgitem (idc_button1)-> enablewindow (false); <br/> // enable the thread where appropriate <br/> pthreadtest =: afxbeginthread (_ testthread, this); <br/>}

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.