sternocera
asked on
MFC/C++: a hwnd related assertion failure is caused when I copy an existing dialog resource for another CDialog class
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(LPCTST R 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 (lpszStrin g);
}
I'm unsure what has gone wrong. Please help!
Regards,
Sternocera
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(LPCTST
{
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
}
I'm unsure what has gone wrong. Please help!
Regards,
Sternocera
Appears to be you have instantiated your dialog, but have not created, could you show the lines where you first use the object?
ASKER
Zoppo,
Here is the offending code:
void CEditExistingProduct::DoDa taExchange (CDataExch ange* pDX)
{
CDialog::DoDataExchange(pD X);
DDX_Control(pDX, IDC_SKU, SKUEdit); // IDC_SKU definitely exists in my dialog resource
...
}
...
BOOL CEditExistingProduct::OnIn itDialog()
{
CString sku_is; sku_is.Format("%i", Sku);
//SKUEdit.SetWindowTextA(s ku_is); // I have these commented out, so there is no assertion failure now
//SKUEdit.EnableWindow(FAL SE);
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
Here is the offending code:
void CEditExistingProduct::DoDa
{
CDialog::DoDataExchange(pD
DDX_Control(pDX, IDC_SKU, SKUEdit); // IDC_SKU definitely exists in my dialog resource
...
}
...
BOOL CEditExistingProduct::OnIn
{
CString sku_is; sku_is.Format("%i", Sku);
//SKUEdit.SetWindowTextA(s
//SKUEdit.EnableWindow(FAL
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
ASKER
jaime_olivares,
This is how the CDialog derived object gets instantiated:
void CProductSearch::OnDoubleCl ickedRow(N MHDR* pNMHDR, LRESULT* pResult)
{
int current = ProductReport.GetFirstSele ctedItem() ;
CString sku = ProductReport.GetItemText( current,1) ;
int SkuInt = atoi(sku.GetBuffer(0));
sku.ReleaseBuffer();
CEditExistingProduct MyEdit;
MyEdit.ChangeSku(SkuInt);
MyEdit.DoModal();
}
Thanks,
Sternocera
This is how the CDialog derived object gets instantiated:
void CProductSearch::OnDoubleCl
{
int current = ProductReport.GetFirstSele
CString sku = ProductReport.GetItemText(
int SkuInt = atoi(sku.GetBuffer(0));
sku.ReleaseBuffer();
CEditExistingProduct MyEdit;
MyEdit.ChangeSku(SkuInt);
MyEdit.DoModal();
}
Thanks,
Sternocera
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
No problem, you're welcome ...
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