
Problems subclassing a window
Using SubclassWindow is rarely if ever appropriate. Certainly it makes no sense if you
have alreaday subclassed the window by binding it to the member variable. Just get rid of
that line; it isn't doing anything of value, and, as you observe, it actually causes a
failure. Use the ClassWizard to set up the association; there is no reason to call
SubclassWindow yourself.
Likewise, if you create it dynamically, you have the same problem. You have already
associated the control with the member variable, and trying to do it a second time simply
generates an assertion fault.
So in neither case is it appropriate.
joe
Quote:
>Hi all...
>If I have a CListCtrl placed at design time on a dialog
>resource and this member variable:
>CSheetListCtrl m_sheet;
>Where CSheetListCtrl is derived from CListCtrl, I can call
>m_sheet.SubclassWindow(GetDlgItem(IDC_LIST_EX)->m_hWnd);
>But if I create that CListCtrl dynamically by using its
>Create method, subclassing doesn't work. It asserts in the
>call to FromHandlePermanent(hWndNew) in the following
>method:
>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;
>}
>How can I do it then?
>Thanks
>Jaime
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm