Compartilhar via


CWnd::Attach

Attaches a Windows window to a CWnd object.

BOOL Attach( 
   HWND hWndNew  
);

Parameters

  • hWndNew
    Specifies a handle to a Windows window.

Return Value

Nonzero if successful; otherwise 0.

Example

This example shows how to use Attach and Detach to map to the MDI client window.

// Declare a CWnd member of CMainFrame
public:
   CWnd m_wndMDIClient;
// detach MDI client window in CMainFrame destructor
m_wndMDIClient.Detach();
// In CMainFrame::OnCreate, attach MDI client window 

    if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

   // attach MDI client window 
   if (m_wndMDIClient.Attach(m_hWndMDIClient) == 0)
   {
      TRACE(_T("Failed to attach MDIClient.\n"));
      return -1;      // fail to create
   }

Requirements

Header: afxwin.h

See Also

Reference

CWnd Class

Hierarchy Chart

CWnd::Detach

CWnd::m_hWnd

CWnd::SubclassWindow