This documentation is archived and is not being maintained.

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

// Using Attach and Detach to map to the MDI client window
class CMainFrame : public CMDIFrameWnd
{
...
public:
   CWnd  m_wndMDIClient;
}

CMainFrame::~CMainFrame()
{
   // detach MDI client window
   m_wndMDIClient.Detach();
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
      return -1;

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

See Also

CWnd Overview | Class Members | Hierarchy Chart | CWnd::Detach | CWnd::m_hWnd | CWnd::SubclassWindow

Show: