Inter-thread Communication 1 global Variable 2 current main dialog pointer 3 message way 4 AfxBeginThread return value (pointer to CWinThread type) 5AfxGetApp

Source: Internet
Author: User





①, the most common way: global variables or multiple threads can see an East 1, global variable mode; int g_num = 100; UINT __cdecl Threadwriteproc (lpvoid lpparameter) {while (TRUE) {++g_num;Sleep (50);}return 100;}
UINT __cdecl Threadreadproc (lpvoid lpparameter) {CString strtipmsg;while (TRUE) {Strtipmsg.format (_t ("%d"), g_num);OutputDebugString (STRTIPMSG);Sleep (50);}
return 100;}
void Cthreadtestdlg::onbnclickedbtn () {CWinThread *pthread = AfxBeginThread (Threadwriteproc, NULL);AfxBeginThread (Threadreadproc, NULL);}
2, everyone can access to an east; 3, the global variable declaration way; ===================================================②, send message: postthreadmessage
#define MY_THREAD_MSG (wm_user+100) UINT __cdecl threadwriteproc (lpvoid lpparameter) {int ncount = 0;DWORD Dwthreadreadid = (DWORD) lpparameter;while (TRUE) {PostThreadMessage (Dwthreadreadid, My_thread_msg, ncount++, NULL);Sleep (50);}return 0;}
UINT __cdecl Threadprintproc (lpvoid lpparameter) {msg msg = {0};while (GetMessage (&msg, 0, 0, 0)){Switch (msg.message) {Case MY_THREAD_MSG:{int ncount = (int) Msg.wparam;CString StrText;Strtext.format (_t ("%d"), ncount);OutputDebugString (StrText);}Break}}
return 0;}
void Cthreadtestdlg::onbnclickedbtn () {CWinThread *pthreadprint = AfxBeginThread (Threadprintproc, NULL);CWinThread *pthreadwrite = AfxBeginThread (Threadwriteproc, (LPVOID) pthreadprint->m_nthreadid);//

Cwinthread::m_nthreadid

The ID of the current thread.

}===================================================









































From for notes (Wiz)

Inter-thread Communication 1 global Variable 2 current main dialog pointer 3 message way 4 AfxBeginThread return value (pointer to CWinThread type) 5AfxGetApp

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.