Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SubclassDlgItem on Property Page: ASSERT fails

Status
Not open for further replies.

Bork

Programmer
Apr 18, 2001
7
CA
I'm trying to dynamically subclass a field on a property page. The code looks like this:

BOOL CMyPropertyPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
m_myedithandler.SubclassDlgItem(IDC_TEXT,this);
return TRUE;
}

The SubclassDlgItem fails on an ASSERT in

BOOL CWnd::Attach(HWND hWndNew)
{
ASSERT(m_hWnd == NULL); //OK
ASSERT(FromHandlePermanent(hWndNew) == NULL); //fails
...

I used the same override logic on an edit field in a regular dialog without any problem. Is there something special about subclassing on a property page? Or can someone point me to something else I am doing wrong?
 
Try to "step in" in the line with FromHandlePermanent.
This usually works fine on a CWnd derived class. CProperty Page is also a derived one(or are you using some other kind of property page)

s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
Thanks for the quick reply. I'm not certain what is meant by

>>&quot;step in&quot; in the line with FromHandlePermanent.<<

If it refers to the debugger, I have stepped through the FromHandlePermanent function, and it runs fine. The problem is that it returns a non-NULL pWnd, presumably because the control window in question is already in the permanent map.

If I'm misinterpreting, can you elaborate?
 
It turns out this isn't an issue any more. When I didn't have any luck here I posted the issue on Experts-Exchange and got a usable reply within hours.
 
Could you share your findings please? There seems to be a
bit of a void when it comes to propertysheet and property
page message subclassing.

Thanks,
Lee
 
For the benefit of others here is the answer to the issue:

PRB: Assertion Failed, WINCORE.CPP--Line 129, 133, 182, or 307
----------------------------------
----------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, l.5, 1.51, 1.52
Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 4.0

SYMPTOMS
Opening a dialog box in an application that subclasses a control of the dialog box using CWnd::SubclassDlgItem() or CWnd::SubclassWindow() causes an &quot;Assertion Failed!&quot; error in WINCORE.CPP. The line number reported depends on the version of the Microsoft Foundation Classes (MFC) being used:

Version 2.0 for Windows - Line 133
Version 2.5 for Windows - Line 182
Version 2.0 32-bit Edition - Line 129
Version 3.0 32-bit Edition - Line 283
Version 3.1 32-bit Edition - Line 315
Version 4.0 32-bit Edition - Line 307



CAUSE
The second ASSERT (below) in WINCORE.CPP is the one being hit:

BOOL CWnd::Attach(HWND hWndNew)
{
ASSERT(m_hWnd == NULL); // Only attach once, detach on destroy
ASSERT(FromHandlePermanent(hWndNew) == NULL);
// Must not be already in permanent map
...
This implies that the control that we are attempting to subclass has already been subclassed.

With MFC dialog boxes, you can specify DDX/DDV member variables to associate with the controls of an MFC dialog class. These member variables can be real values (for example, int, CString) or control variables (for example, CEdit, CListBox). If the member variables are control variables, then the DDX/DDV handlers actually do subclass the dialog box controls using the control member variables. If you try to subclass those controls yourself, the above error can result.



RESOLUTION
If you want to subclass controls yourself, then do not associate DDX/DDV variables with those controls.

Alternatively, if you want to subclass controls but avoid the work, you can let the DDX/DDV routines work for you. To do this, use the following steps.



Create a dialog box template in App Studio.


Use ClassWizard to associate a C++ CDialog derived class with the template.


In ClassWizard, with the dialog class selected, choose Edit Variables and add a member variable of the appropriate control type, associating it with the control you want to subclass. With Visual C++ 1.5, choose the Member Variables tab and select Add Variable to accomplish this.


Edit the CDialog derived class definition to change the &quot;// Dialog Data&quot; section slightly. Change the class type for the member variable from the default (for example CEdit), to your own class derived from that control class (for example, CMyEdit), as follows:
// Dialog Data
//{{AFX_DATA(CTestDlg)
enum { IDD = IDD_TEST_DLG };
CMyEdit m_EditControl;
//}}AFX_DATA
This will cause the control to be automatically subclassed with your own type of window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top