Type-Safe Access to Controls Without Code Wizards
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:
CButton* CMyDialog::GetMyCheckbox()
{
return (CButton*)GetDlgItem(IDC_CHECKBOX);
}
You can then use this member function to access the control in a type-safe manner with code similar to the following:
GetMyCheckbox()->SetCheck(BST_CHECKED);
See also
Type-Safe Access to Controls in a Dialog Box
Type-Safe Access to Controls With Code Wizards
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for