When you access a control in a thread or perform operations on the control, such as calling setwindowtext, an error may occur when the window is closed.
The reason is: when the window is closed, the control is destroyed first, and then the thread is destroyed. when the control is destroyed, an error occurs if the thread continues to access the control.
Another possibility is that, when a thread accesses a control, it does not obtain the control handle and directly operates on the control, such as the list box m_listctrl.addstring ("hello "), in this case, the thread hides the handle that does not contain the list box, and an error is returned when you operate the list box. (here, the addstring function has its own solution assert (iswnd (m_hwnd ))... Will be interrupted)
Therefore, it is best to add an Assert (iswnd (m_hwnd ))...
How to obtain the handle pointer of the Main Window: cwnd * pwnd = afxgetmainwnd ();
Of course, this idea is also suitable for other aspects of thread programming... Do not forget!