Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

In MFC, I understand using updateData() function, which in turn calls DoDataExchange, controls variables of a dialog can be set or get.

We can also set or get values of control variables using SetDlgItemText() and GetDLGItemText() method.

What is the difference between above two??


I think in using SetDlgItemText() and GetDLGItemText() method, we can set ot get value at runtime. we do not need member string variable.



Below is the small example.

suppose I have a check box control.

a) using DDX, I would write code like this to get or set data.Based on the argument of update data, it would decide whether value had to be set ot get.


C++
void CMyDlg::DoDataExchange(CDataExchange* pDX)

{

    DDX_Text(pDX, IDC_MINEVENTLENGTH, m_iMinEventLength);

}


b)I can also set or get value of control like below.
C++
GetDlgItemText(hWnd, IDC_MINEVENTLENGTH, MinEventLength, _countof(MinEventLength));
SetDlgItemText(hWndDlg, IDC_MINEVENTLENGTH, MinEventLength);



Please help.

Regards,
Joy
Posted
Updated 24-Apr-14 1:53am
v2

1 solution

In your a) version, you do not need a member variable to handle the control, and set or retrieve the text : this is handled automagically by MFC, the drawback being that you cannot really control it but from reading or updating the value.

Your b) version is plain Win32 code, so this also works without MFC support, using a handle on the control. ( The a) version is simply a wrapper around the Set/GetDlg functions. )

As a third option, name it "c) version", you handle the MFC controls via a member variable -> In the create variable wizard, you can choose to handle certain control by value - your a) version - or by control - this c) version). This offers a load more options, including event handlers.

Honestly, I have seldom used MFC "by value".
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900