Solved

SubclassDlgItem on Property Page: failing on ASSERT

Posted on 2001-08-02
2
961 Views
Last Modified: 2013-11-20
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_MYEDIT,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
    ...

FromHandlePermanent returns a non-NULL pWnd, presumbably because the control in question is already in the permanent map.

I've used the same override logic on an edit field in a regular dialog (derived from CDialog rather than CPropertyPage) 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?
0
Comment
Question by:hansenk
  • 2
2 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 6347355
The ClassWizard has created a variable (presumeably named m_myedithandler and presumably of a class derived from CEdit).  

CPropertyPage::OnInitDialog() during its DDX phase has already subclassed that control.

What you need to do is use the ClassWizard to remove that variable (that will remove the DDX_Control() call), then add it back manually in the CMyPropertyPage .h file.

public:
   CMyPropertyPage();   // standard constructor
   ~CMyPropertyPage();

   // added here, subclassed in OnInitDialog
   CMyEditHandler m_myedithandler;

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6352350
yore welcum
-- Dan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
mixString challenge 36 111
MaxSpan challenge 9 80
fix34  challenge 9 104
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now