Solved

MFC/C++: a hwnd related assertion failure is caused when I copy an existing dialog resource for another CDialog class

Posted on 2007-11-21
7
700 Views
Last Modified: 2013-12-14
Hello,

I've created a new CDialog derived class, which is similar to an existing one. I copied the existing Dialog resource for my new CDialog derived class, and added new objects for the dialog's widgets, which don't necessarily have the same name as the old objects.

The dialog executes, until I attempt to call any of the object's member functions, which causes various assertion/ensure failures:

This occurs when I attempt to call a CEdit's CWnd::SetWindowTextA(), for example:

void CWnd::SetWindowText(LPCTSTR lpszString)
{
      ENSURE(this);
      ENSURE(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL)); // this is the offending line

      if (m_pCtrlSite == NULL)
            ::SetWindowText(m_hWnd, lpszString);
      else
            m_pCtrlSite->SetWindowText(lpszString);
}

I'm unsure what has gone wrong. Please help!

Regards,
Sternocera
0
Comment
Question by:sternocera
  • 3
  • 3
7 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 20326880
Hi sternocera,

hard to say from that code fragment ...

You should first ensure that your code doesn't use any control-ID which isn't present in the copies resource.

Is there a call to SetWindowText in your dialog's class? Or is this called from another MFC function?

Maybe you could post some more code, especially the functions which call this above given code (from call-stack)?


regards,

ZOPPO
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20326886
Appears to be you have instantiated your dialog, but have not created, could you show the lines where you first use the object?
0
 

Author Comment

by:sternocera
ID: 20326910
Zoppo,

Here is the offending code:
void CEditExistingProduct::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      DDX_Control(pDX, IDC_SKU, SKUEdit); // IDC_SKU definitely exists in my dialog resource
...
      
}
...
BOOL CEditExistingProduct::OnInitDialog()
{
      CString sku_is; sku_is.Format("%i", Sku);
      //SKUEdit.SetWindowTextA(sku_is); // I have these commented out, so there is no assertion failure now
      //SKUEdit.EnableWindow(FALSE);
      
      return TRUE;
}

Incidentally, I'm sorry I didn't give you a fair share of the points that time, Zoppo. It was a stupid oversight on my part.

Thanks,
Sternocera


0
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.

 

Author Comment

by:sternocera
ID: 20326917
jaime_olivares,

This is how the CDialog derived object gets instantiated:

void CProductSearch::OnDoubleClickedRow(NMHDR* pNMHDR, LRESULT* pResult)
{
      int current = ProductReport.GetFirstSelectedItem();
      CString sku = ProductReport.GetItemText(current,1);
      int SkuInt = atoi(sku.GetBuffer(0));
      sku.ReleaseBuffer();
      
      CEditExistingProduct MyEdit;
      MyEdit.ChangeSku(SkuInt);
      MyEdit.DoModal();

}

Thanks,
Sternocera
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 20326923
Hi again,

no problem ...

Seems there's no exiting edit-box found with resource-ID 'IDC_SKU' in this dialog ...

Further you should call CDialog::OnInitDialog() within your CEditExistingProduct::OnInitDialog(), somehow like this:

BOOL CEditExistingProduct::OnInitDialog()
{
      CDialog::OnInitDialog();

      CString sku_is; sku_is.Format("%i", Sku);
      //SKUEdit.SetWindowTextA(sku_is); // I have these commented out, so there is no assertion failure now
      //SKUEdit.EnableWindow(FALSE);

      UpdateData( FALSE );      
      return TRUE;
}


Hope that helps,

ZOPPO
0
 

Author Comment

by:sternocera
ID: 20326938
Zoppo,

Including CDialog::OnInitDialog() in my function overload is something that I know I should have done, but forgot to.

Now that I have, no more assertion failures. Silly me.

Thanks a lot for your time,
Sternocera


0
 
LVL 31

Expert Comment

by:Zoppo
ID: 20326941
No problem, you're welcome ...
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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

929 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

8 Experts available now in Live!

Get 1:1 Help Now