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
696 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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:sternocera
Comment Utility
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 30

Accepted Solution

by:
Zoppo earned 500 total points
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
No problem, you're welcome ...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 103
fix34  challenge 9 95
matchUp  challenge 9 71
Problem to event 3 48
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

771 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