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/>}