Share via


CWnd::SubclassDlgItem

BOOLSubclassDlgItem(UINTnID**,CWnd*pParent);**

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

nID

The control’s ID.

pParent

The control’s parent (usually a dialog box).

Remarks

Call this member function to “dynamically subclass” a control created from a dialog template and attach it to this CWnd object. When a control is dynamically subclassed, windows messages will route through the CWnd’s message map and call message handlers in the CWnd’s class first. Messages that are passed to the base class will be passed to the default message handler in the control.

This member function attaches the Windows control to a CWnd object and replaces the control’s WndProc and AfxWndProc functions. The function stores the old WndProc in the location returned by the GetSuperWndProcAddr member function.

Example

class CMyButton : public CButton {...};
// m_myButton is a CMyButton object member of CAboutDlg

BOOL CAboutDlg::OnInitDialog()
{
   CDialog::OnInitDialog();
   // IDC_BUTTON1 is the ID for a button on the
   // dialog template used for CAboutDlg.
   m_myButton.SubclassDlgItem(IDC_BUTTON1, this);

   return TRUE;   // Return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

CWnd OverviewClass MembersHierarchy Chart

See Also   CWnd::GetSuperWndProcAddr, CWnd::DefWindowProc, CWnd::SubclassWindow, CWnd::Attach