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