How to associate an MFC control with its corresponding object

Source: Internet
Author: User

 

 

 

 

The control of the dialog box is associated with the object of the corresponding class :(Two methods)

(1) associate data using the cwnd: dodataexchange function;

Use the Add variable on the member variables page in the MFC classwizard of VC ++ 6.0 to associate a variable.

ThenDodataexchangeThe function containsDdx_xxxxxFunction association. This method is very common. For example, a cedit control can be associated with either a cedit object or a variable of the Int or cstring type;

(2) associate with a function (associate with the object of the corresponding class)

The main applications are as follows:

Cwnd * getdlgitem (int Nid ) Const;

NidIs the resource ID. Of course, the control must be a control derived from cwnd;

1. For example, a progress bar Control

Cprogressctrl * g_ptrprogress1 = NULL;

G_ptrprogress1 =(Cprogressctrl *)Getdlgitem (idc_progress1 );

// Pay attention to forced conversion.Cwnd *Forced conversionCprogressctrl *

2. For example, an editing box

Cedit * pboxone;

Pboxone = (cedit *) getdlgitem (idc_edit1 );

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.