Identifying Controls: CWnd Pointers and Control IDs

When you lay out a dialog resource in the dialog editor, you identify each control by an ID such as IDC_SSN. In your program code, however, you often need access to a control's underlying window object. The MFC library provides the CWnd::GetDlgItem function for converting an ID to a CWnd pointer. You've seen this already in the OnInitDialog member function of class CEx06aDialog. The application framework "manufactured" this returned CWnd pointer because there never was a constructor call for the control objects. This pointer is temporary and should not be stored for later use.

If you need to convert a CWnd pointer to a control ID, use the MFC library GetDlgCtrlID member function of classCWnd.