Dynamic addition of VC controls

Source: Internet
Author: User

Dynamic addition of VC controls


Sometimes, for some purpose, we hope that the system controls can be automatically added based on our needs instead of being drawn in the dialog box in advance. At this time, we need to dynamically generate the controls.

For details, we can use CEdit (text box Control) as an example.

Step 1:

You must add a CEdit pointer and then open up the corresponding space for the pointer. it should be noted that we must define pointers instead of directly defining this class. The specific reason is not explained here. Here we write this statement;

CEdit * Text = new CEdit ();

Step 2:

Create a control. I use create to read and initialize text and display it on the desktop. The Code is as follows:

RECT rect;

Rect. top = 0;

Rect. left = 0;

Rect. Rights = 100;

Rect. top = 100;

Text-> Create (WS_CHILD | WS_VISIBLE, rect, (CWnd *) this, FID_ADDRESS );

The first parameter indicates the style of the control, which can be obtained from MSDN. The second parameter indicates the position of the control displayed in the window, the third control is the control window, and the fourth parameter is the Control ID. Its definition must be in resource. h and String table are defined in the resource. If the test is used, it can be defined as an undefined constant, for example: 2008.

The subsequent TEXT can be controlled like a common DDX_Control function. For example, to get a value, you only need

CString xxx;

Text-> GetWindowText (xxx );

In this way, the value in the control is read into the xxx string.

If this article needs to be reproduced, please enter the author's name. Thank you for your cooperation.


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.