我是在某CPropertyPage中,为其中一个ListBox控件添加了一个成员变量,类型为CMyListBox.
实际上增加的代码为
CMyListBox m_myListBox;
DDX_Control(pDX, IDC_LIST, m_myListBox);是子类化失败了?提示在dlgdata中,下面第8行ASSERT(!pDX->m_bSaveAndValidate);
/////////////////////////////////////////////////////////////////////////////
// Special DDX_ proc for subclassing controlsvoid AFXAPI DDX_Control(CDataExchange* pDX, int nIDC, CWnd& rControl)
{
if ((rControl.m_hWnd == NULL) && (rControl.GetControlUnknown() == NULL)) // not subclassed yet
{
ASSERT(!pDX->m_bSaveAndValidate); ///////////////提示在这一行////////////// pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if ((hWndCtrl != NULL) && !rControl.SubclassWindow(hWndCtrl))
{
ASSERT(FALSE); // possibly trying to subclass twice?
AfxThrowNotSupportedException();
}
#ifndef _AFX_NO_OCC_SUPPORT
else
{
if (hWndCtrl == NULL)
{
if (pDX->m_pDlgWnd->GetOleControlSite(nIDC) != NULL)
{
rControl.AttachControlSite(pDX->m_pDlgWnd, nIDC);
}
}
else
{
// If the control has reparented itself (e.g., invisible control),
// make sure that the CWnd gets properly wired to its control site.
if (pDX->m_pDlgWnd->m_hWnd != ::GetParent(rControl.m_hWnd))
rControl.AttachControlSite(pDX->m_pDlgWnd);
}
}
#endif //!_AFX_NO_OCC_SUPPORT }
}
实际上增加的代码为
CMyListBox m_myListBox;
DDX_Control(pDX, IDC_LIST, m_myListBox);是子类化失败了?提示在dlgdata中,下面第8行ASSERT(!pDX->m_bSaveAndValidate);
/////////////////////////////////////////////////////////////////////////////
// Special DDX_ proc for subclassing controlsvoid AFXAPI DDX_Control(CDataExchange* pDX, int nIDC, CWnd& rControl)
{
if ((rControl.m_hWnd == NULL) && (rControl.GetControlUnknown() == NULL)) // not subclassed yet
{
ASSERT(!pDX->m_bSaveAndValidate); ///////////////提示在这一行////////////// pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if ((hWndCtrl != NULL) && !rControl.SubclassWindow(hWndCtrl))
{
ASSERT(FALSE); // possibly trying to subclass twice?
AfxThrowNotSupportedException();
}
#ifndef _AFX_NO_OCC_SUPPORT
else
{
if (hWndCtrl == NULL)
{
if (pDX->m_pDlgWnd->GetOleControlSite(nIDC) != NULL)
{
rControl.AttachControlSite(pDX->m_pDlgWnd, nIDC);
}
}
else
{
// If the control has reparented itself (e.g., invisible control),
// make sure that the CWnd gets properly wired to its control site.
if (pDX->m_pDlgWnd->m_hWnd != ::GetParent(rControl.m_hWnd))
rControl.AttachControlSite(pDX->m_pDlgWnd);
}
}
#endif //!_AFX_NO_OCC_SUPPORT }
}
顺便再问,假如要m_myListBox.SubclassWindow()的话,应该扔哪?
假如我想将IDC_LIST与自己写的类CMyListBox绑定,不需要子类化么?
恩恩,CMyListBox继承于CListBox.
下面的意思是不是还没子类化,因此DDX_Control开始帮俺子类化了?它说not subclassed yet.
if ((rControl.m_hWnd == NULL) && (rControl.GetControlUnknown() == NULL)) // not subclassed yet
{
ASSERT(!pDX->m_bSaveAndValidate); ///////////////提示在这一行////////////// pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if ((hWndCtrl != NULL) && !rControl.SubclassWindow(hWndCtrl))
{
ASSERT(FALSE); // possibly trying to subclass twice?
AfxThrowNotSupportedException();
}
比如:
http://topic.csdn.net/u/20090724/11/6e4ea566-f091-48f7-8772-3d83c4cbbbad.html?409不要跟一些菜鸟们抢分吧^&^to:2L
2008貌似找不到ClassWizard?
从vc7(也就是.net开始)就取消了ClassWizard
把功能都集成为,右窗口的类视图一层一层的点击,慢慢会看到底下窗口有很多属性
比如,映射,基类型,派生类型等,,,还有这一句:CMyListBox m_myListBox;
我觉得你的CMyListBox 应该是类,从CListBox派生出来的,然后才能,关联控件IDC_LIST
假如要m_myListBox.SubclassWindow()的话,应该扔哪?
SubclassWindow这是CWnd成员,子类化窗体,只要在m_myListBox有效范围内都可以用吧
在CMyPropertyPage中用CMyListBox声明了一个成员变量CMyListBox m_myListBox
之后将m_myListBox与IDC_LIST关联.
之后就出现上面那个问题了.
在CMyPropertyPage的OnInitDialog()开头加了句m_myListBox.SubclassWindow()貌似就可以了.
就是不大清楚为什么..