BOOL CWnd::Attach(HWND hWndNew)
{
ASSERT(m_hWnd == NULL); // only attach once, detach on destroy
ASSERT(FromHandlePermanent(hWndNew) == NULL);//跟踪指向这里???
// must not already be in permanent map if (hWndNew == NULL)
return FALSE; CHandleMap* pMap = afxMapHWND(TRUE); // create map if not exist
ASSERT(pMap != NULL); pMap->SetPermanent(m_hWnd = hWndNew, this);#ifndef _AFX_NO_OCC_SUPPORT
AttachControlSite(pMap);
#endif return TRUE;
}
{
ASSERT(m_hWnd == NULL); // only attach once, detach on destroy
ASSERT(FromHandlePermanent(hWndNew) == NULL);//跟踪指向这里???
// must not already be in permanent map if (hWndNew == NULL)
return FALSE; CHandleMap* pMap = afxMapHWND(TRUE); // create map if not exist
ASSERT(pMap != NULL); pMap->SetPermanent(m_hWnd = hWndNew, this);#ifndef _AFX_NO_OCC_SUPPORT
AttachControlSite(pMap);
#endif return TRUE;
}
---------------------------------------------------
说明你的hWndNew已经附着了一个CWnd类实例,不能再Attach了
使用FromHandle可不可以呢?
Detach就是接触绑定
Attach是将一个源生的HWND句柄(比如WindowsAPI创建的窗口句柄)永久关联到一个CWnd实例。
FromHandle则是将一个源生的HWND句柄临时关联到一个CWnd实例。
临时关联有一个限制是在Idle处理中有可能取消这个关联,所以尽量不要将FromHandle返回的CWnd*指针保存使用