Quote Originally Posted by D_Drmmr View Post
What's dreaded about GetDlgItem?
It's not that it's dreaded, it's just that using it results in extra code.

IMO, most folks use GetDlgItem because it's a carry over from coding in Win32 or they don't know how to create a Control variable in MFC.

The DDX mechanism hides the GetDlgItem implementation, when using data variables also handles the data transfer between the control and its associated variable.

Rather than having ugly GetDlgItem calls with casting everywhere, you can just use the dialog control variable.

Consider an edit box and say you want to hide it.

Create a control variable, and then...

Code:
m_EditBox.ShowWindow( SW_HIDE );
What about setting the edit box string?

Create a value variable (like CString), and then...

Code:
m_sEdit = _T("some text");
UpdateData( FALSE );
Compare that with:

Code:
 
CEdit* pBoxOne = (CEdit*) GetDlgItem(IDC_EDIT1);
pBoxOne->GetWindowText( _T("some text" );
Sure, you can argue that they're both 2 lines. But consider that UpdateData( ) only needs to be called once after setting any values - even for multiple controls.