About GUI threads in C ++

Source: Internet
Author: User

As you know, there are two types of threads in C ++: one is the worker thread and the other is the GUI thread. As for their differences, you can search for them online.

Here I just want to explain what you need to pay attention to when creating a GUI thread.

Some Windows-related threads should be placed in the GUI thread. The GUI thread has optimized the window or special controls properly because of the initial operations related to the window or special controls, if the worker thread needs to perform these operations on its own, it is often difficult for us to do so. If the created MFC program creates another sub-thread in the main window thread to generate a window, the GUI thread is used. At this time, because there are two GUI threads in the process, after wm_close is sent to the newly created window, the window is closed, but the newly created GUI thread does not exit, causing memory leakage. Therefore, the thread created later must be processed by itself, and the thread exit event. The specific operations are as follows:

The window class in the newly created GUI thread needs to process the ondestroy message and call postquitmessage (0) in this function. After the thread is terminated, all resources can be released.

 

 

Hope to help you, if you have any questions, please contact me, guyuewuhua@163.com

Related Article

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.