Share via


Type-Safe Access to Controls Without ClassWizard

OverviewHow Do I

The first approach to creating type-safe access to controls uses an inline member function to cast the return type of class CWnd’s GetDlgItem member function to the appropriate C++ control type, as in this example:

// Declared inline in class CMyDialog
CButton* GetMyCheckbox()
{
    return (CButton*)GetDlgItem(ID_MYCHECKBOX);
}

You can then use this member function to access the control in a type-safe manner with code similar to the following:

GetMyCheckbox()->SetState(TRUE);

See Also   Type-Safe Access to Controls With ClassWizard