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
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

729 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