Attention should be paid to access controls in the process

Source: Internet
Author: User

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!

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.