Dynamically create a control in MFC

Source: Internet
Author: User

Dynamically create an edit control in the View class as follows:

Editt1.create (es_multiline
| Ws_child | ws_visible | ws_tabstop |
Ws_border, crect (0, 0, 50, 20), this, idc_editt1 );

Now you want to implement the data exchange function in a similar dialog box.

My method is:
Void cmatlab printview: dodataexchange (cdataexchange * PDX)
{
// Todo: add your specialized code here and/or call the base class
Cview: dodataexchange (PDX );
// {Afx_data_map (cmatlab printview)
Ddx_text (PDX, idc_editt1, m_dt1 );
//} Afx_data_map
}

When you run dodataexchange, your edit box is not generated yet. Of course, idc_editt1 and m_dt1 cannot be associated.
_____________________________________________________________________________
I agree, so my approach is:
Add:
Editt1 = new cedit (); // Add this statement
Editt1-> Create (es_multiline | ws_child | ws_visible
| Ws_tabstop | ws_border, crect (0, 0, 50, 20), this, idc_editt1 );
A global control variable named at the beginning of the function: cedit * editt1;
Use editt1 to process the edit in other parts of the function, for example, editt1-> setwindowtext ("edit ");

Idc_editt1 is the custom resource ID

 
 VCProgramResource definition. The following number is only used to indicate specific resources and avoid duplication. The specific value does not make sense.
#DefineIdd_aboutbox 100 indicates that there is a dialog box resource with ID idd_aboutbox.

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.