0

I have a MFC application that have a class who inherits from CTabCtrl, on my Main Dialog::OnInit() Method I do.

tabCtrl.InsertItem(0, _T("Tab 1"));
tabCtrl.InsertItem(1, _T("Tab 2"));
tabCtrl.InitDialogs();

tabCtrl.ActivateTabDialogs();
tabCtrl.ShowWindow(SW_SHOW);

tabCtrl is a variable from a class that inherits from CTabCtrl, the method InitDialogs is:

m_Dialog[0]->Create(m_DialogID[0], this);
m_Dialog[1]->Create(m_DialogID[1], this);
m_Dialog[0]->ShowWindow(SW_SHOW);

m_Dialog* is contains both dialog class that I drawn from the resource class.

I see both tabs as I drawn it when I run the program, but when I do something like

UpdateData(TRUE);
valueTest = "tEST";
UpdateData(FALSE);

I get an assertion fail error. My DoDataExchange is being called and it looks like:

 void ConfigDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT1, valueTest);
}

I've been strugling with this for days, and I only been able to found examples with dummy tabs who doesn't have any controls inside them. Is there any step that I'm missing?

Update: The assertion error show this

Microsoft Visual C++ Runtime Library --------------------------- Debug Assertion Failed! Program: C:\Windows\SYSTEM32\mfc140d.dll File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp Line: 4355 For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts

And it fails to UpdateData(TRUE) sentence

  • What's your actual problem? That you're seeing an assert fail? – Lynn Crumbling Sep 07 '16 at 19:04
  • My problem is that I can't change the properties of the controls, when I try to do it I get an assert fail. – Pablo Iocco Sep 07 '16 at 19:06
  • 2
    Please post the **exact** error message of the assertion dialog. You can copy the text using [Ctrl]+C. A screenshot can help, but that's not strictly required. – IInspectable Sep 07 '16 at 19:21
  • @LynnCrumbling: `UpdateData` is an MFC implementation, that stores data from controls to attached instance variables, or restores the control contents back (depending on the argument). – IInspectable Sep 07 '16 at 19:22
  • --------------------------- Microsoft Visual C++ Runtime Library --------------------------- Debug Assertion Failed! Program: C:\Windows\SYSTEM32\mfc140d.dll File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp Line: 4355 For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. – Pablo Iocco Sep 07 '16 at 19:29
  • 1
    The line of code that fails is `ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?` (the comment is interesting). Unless I'm using a different version of MFC than you are. You should [update](http://stackoverflow.com/posts/39377360/edit) your question and include both the assertion dialog text as well as the code with the failed assertion (press *Debug* to get there), including a few more lines. – IInspectable Sep 07 '16 at 19:35
  • I updated the post, but I don't understand what you are saying about calling UpdateData before doModal – Pablo Iocco Sep 07 '16 at 20:02

1 Answers1

0

I assume it's an edit control because it has the ID of IDC_EDIT1. The ASSERT is being given because you do no have a window with the ID of IDC_EDIT1 as a child window of ConfigDialog. Is it a child of one of the tab controls? The DDX_* macros will only work for child windows of your dialog class.

If you have a child window of some tab, try something like:

tabCtrl.SetDlgItemText(IDC_EDIT1, valueTest);

To retrieve it,

tabCtrl.GetDlgItemTText(IDC_EDIT1, valueTest);
Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
  • I tried this, ConfigDialog is one of the childDialog of the mainDialog, But I'm no sure if I understand what you are saying – Pablo Iocco Sep 07 '16 at 20:04
  • You are trying to get text from and edit control. Is the control a child of the dialog or is it a child of the tab? In addition, are you calling UpdateData() before you call DoModal? You have to call DoModal before you can call UpdateData. – Joseph Willcoxson Sep 07 '16 at 20:21
  • The edit control is a child of the tab, Do I have to call DoModal in the main dialog o in the tab dialog? – Pablo Iocco Sep 07 '16 at 20:26
  • I don't know. There is not enough intormation. If the edit control is a child of the tab, then you have to call SetDlgItemText and GetDlgItemText with it. – Joseph Willcoxson Sep 07 '16 at 20:36