The use of ccriticalsection is actually demonstrated below MFC

Source: Internet
Author: User


What is Q:ccriticalsection?

A:ccriticalsection is a thread synchronization strategy or technique or method in short, that's what it means ....

Resources:

http://blog.csdn.net/akof1314/article/details/5773076

Http://www.cnblogs.com/hlxs/archive/2013/03/31/2991752.html

Http://baike.baidu.com/view/2471016.htm

First step: Open VS2010 to create a single document MFC program. and run OK to make sure the creation process

Step Two: Add a header file in the view header file # include "Afxmt.h"

And instantiate a CCriticalSection object in the implementation file of the view class.

Specifically, this object is not part of the view class, where it is defined as a global variable.

CCriticalSection gsz_criticalsection;

  

Step three: Define the two functions in the implementation file in the view. These two functions are brought back to be specified as thread functions. These two functions are not member functions of the view class.

UINT  
AfxGetMainWnd function Gets the main frame class pointer in MFC program is a common practice of CWnd *pmainwnd = AfxGetMainWnd (); :: MessageBox (Pmainwnd->m_hwnd, PMessage, _t ("Thread message"), MB_OK); Gsz_criticalsection.unlock (); return 0; } UINT
AfxGetMainWnd function Gets the main frame class pointer in MFC program is a common practice
CWnd *pmainwnd = AfxGetMainWnd ();



}

Fourth step: Add the left mouse button message response function function to the view class is written as follows:

Note that this needs to be clicked as shown below to find a left-click response function.

void Ctestgszview::onlbuttondown (UINT nflags, CPoint Point)
{
TODO: Add Message Handler code and/or call default values here
AfxBeginThread (MessageThread1, _t ("Thread is Started")); Start thread 1
AfxBeginThread (MessageThread2, _t ("Thread is Started")); Start Thread 2

Cview::onlbuttondown (nflags, point);
}

Fifth step: Run the test.

Click the View area

There's the following stuff.

The use of ccriticalsection is actually demonstrated below MFC

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.