Several methods of MFC access control

Source: Internet
Author: User

Ways to access controls 

A control is an interactive tool that an application needs to access the control to query and set in some way. There are four ways to access controls:

    1. Access controls using the data Exchange features of the dialog box. This method is useful for automatically created controls. The data exchange between the dialog box and the control can be implemented by adding the data member variable corresponding to the control to the dialog class with ClassWizard and then calling UpdateData when appropriate. This method can exchange data only, cannot fully query and set the control, and the method is not for a control, but for all the controls participating in the data exchange. Also, for a new Win32 control, you cannot create a data member variable with ClassWizard. Therefore, this method has a great limitation.

    2. Controls are accessed through the control object. The control object encapsulates the control, and it has a fully functional member function that queries and sets various properties of the control. Accessing a control through a control object is undoubtedly one of the best ways to use the functionality of the control, but it requires that the program must create a control object and connect the object to a control. For automatically created controls, you can easily create control objects that correspond to controls with ClassWizard. For manually created controls, this problem does not exist because the control itself is created from the control object.

    3. Access controls using some of the CWnd class's member functions for managing controls. These functions are listed in table 5.5. This control can be accessed whenever the control's ID is provided to these functions. The advantage of using these functions is that you can query and set some of the common properties of a control without creating a control object. This method applies to both automatic and hand-created controls.

    4. Access the control with Cwnd::getdlgitem. The function returns a CWnd pointer to the specified control, based on the control ID of the parameter description, which the program can cast to the corresponding control class pointer and then access the control through the pointer. This method applies to both automatic and hand-created controls. This method has been used in the previous chapter, and the reader can refer to 5.3.6. In fact, the method is essentially the same as accessing the control through a control object, including the GetDlgItem function in table 5.5, but in order to emphasize its importance, it is listed separately as a method.


Several ways to access controls by 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.