MFC - Passing data between dialogs in Tab Control
-
Hello, What i usually do in that cases is to use a kind of data model at parent dialog box level. Each tab works only with the data model. You monitor Activation unactivation of each tab and update itself based of changes in the common data model. hope this will help. Regards Franck
Does it means that we can't pass data between dialogs in tab control in a simple way like I try to do it? Do you know simple way that works ? And do you know why that ASSERT IsWindow... is triggered? Regards
-
Does it means that we can't pass data between dialogs in tab control in a simple way like I try to do it? Do you know simple way that works ? And do you know why that ASSERT IsWindow... is triggered? Regards
I've never found a reason to fight with a tab control (i.e.,
CTabCtrl
). Use a property sheet in place of the dialog, and a property page for each tab and you'll be on your way in a matter of minutes. You can use the parent to pass data back and forth between tabs very easily."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Hello, What i usually do in that cases is to use a kind of data model at parent dialog box level. Each tab works only with the data model. You monitor Activation unactivation of each tab and update itself based of changes in the common data model. hope this will help. Regards Franck
Does it means that we can't pass data between dialogs in tab control in a simple way like I try to do it? Does anybody else knows simple way that works ? Regards
-
Hi, Question: how to pass data between two dialogs (which are in Tab Control)... For example if we have ListBox1 in Dialog1 and we want to add string to ListBox1 from Dialog2 how to do that? I try to include Dialog1 header file in Dialog2 and add object ( Dialog1 object_Dialog1;) in to Dialog2, and then in handler for some button in Dialog2, I wrote: object_Dialog1.m_ListBox1.AddString(_T("s")); //m_ListBox1 is control variable for ListBox1 in Dialog1 but that cause ASSERT in afxwin2.inl : _AFXWIN_INLINE int CListBox::AddString(LPCTSTR lpszItem) { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem); } Does anybody knows how to pass data between two dialogs in Tab Control? Best Regards
The real problem seems to be how you got a dialog 1 object in the dialog 2 class. Your comments seem to say to declared a variable and your reference (with .) seems to say that you instantiated a dialog 1 class inside dialog 2. So, how do you know this instantiation actually points to the dialog 1 that is being displayed. declaring the variable does *not create the dialog window*. Clearly, to have dialog 1 displayed, somebody has to instantiate it and create it. It was probably your main program (the same one that instantiated dialog 2). The error is saying that "the object you are referencing (dialog 1) is not a valid window" and that would be true if you never created. Now what you want to do it obtain the *pointer to dialog 1* created by your parent / main program and store it in a local pointer in dialog 2. Then you can access it with "object_dialog1->m_list......." Chuck
-
The real problem seems to be how you got a dialog 1 object in the dialog 2 class. Your comments seem to say to declared a variable and your reference (with .) seems to say that you instantiated a dialog 1 class inside dialog 2. So, how do you know this instantiation actually points to the dialog 1 that is being displayed. declaring the variable does *not create the dialog window*. Clearly, to have dialog 1 displayed, somebody has to instantiate it and create it. It was probably your main program (the same one that instantiated dialog 2). The error is saying that "the object you are referencing (dialog 1) is not a valid window" and that would be true if you never created. Now what you want to do it obtain the *pointer to dialog 1* created by your parent / main program and store it in a local pointer in dialog 2. Then you can access it with "object_dialog1->m_list......." Chuck
Hi Chuck, I got a class MyTabControl(:public CTabCtrl), in which I create dialog1 and dialog2 in constructor of that class, and in main dialog(called MainDialog) I instantiated those two with object(In main dialog .h I have a object MyTabControl objectMyTC;) So I try to do this (...on click some button in Dialog1 I wanna to access m_ListBox2 in Dialog2 from Dialog1 in TabControl): In Dialog1.h I declare: MainDialog* p_MainDialog; and in Dialog1.cpp I wrote: Cwnd* pWnd = (CWnd*) p_MainDialog->objectMyTC.m_Dialog2->GetDlgItem(m_ListBox2); but when I click button, that also didn't work, I get an exception (..acess violation reading location 0xcdcdeb1). When I try to debug this line i saw that all objects in MainDialog have hWnd=??? so I guess this has something with it. Can You please help me what I am doing wrong? Best Regards and thanks
-
Hi Chuck, I got a class MyTabControl(:public CTabCtrl), in which I create dialog1 and dialog2 in constructor of that class, and in main dialog(called MainDialog) I instantiated those two with object(In main dialog .h I have a object MyTabControl objectMyTC;) So I try to do this (...on click some button in Dialog1 I wanna to access m_ListBox2 in Dialog2 from Dialog1 in TabControl): In Dialog1.h I declare: MainDialog* p_MainDialog; and in Dialog1.cpp I wrote: Cwnd* pWnd = (CWnd*) p_MainDialog->objectMyTC.m_Dialog2->GetDlgItem(m_ListBox2); but when I click button, that also didn't work, I get an exception (..acess violation reading location 0xcdcdeb1). When I try to debug this line i saw that all objects in MainDialog have hWnd=??? so I guess this has something with it. Can You please help me what I am doing wrong? Best Regards and thanks
0xcdcd...is indicitive of an unitialized variable. You declared p_MainDialog but did you put anything into it?
-
0xcdcd...is indicitive of an unitialized variable. You declared p_MainDialog but did you put anything into it?
Hi Chuck, I just declare it like I wrote .. I guess I need pointer to parent(main) dialog window.... How You mean "...did you put anything into it? " ...I dont understand? Can You help me to solve this problem? Simple sample code (variation of what I wrote).... Regards
-
Hi Chuck, I just declare it like I wrote .. I guess I need pointer to parent(main) dialog window.... How You mean "...did you put anything into it? " ...I dont understand? Can You help me to solve this problem? Simple sample code (variation of what I wrote).... Regards
Where is the statement like:
p_MainDialog = ??????;
as far as I can see, you only declare p_MainDialog but do not initialize it. Since the error indicates an uninitialized variable, I bet they're related.
-
Where is the statement like:
p_MainDialog = ??????;
as far as I can see, you only declare p_MainDialog but do not initialize it. Since the error indicates an uninitialized variable, I bet they're related.
Hi, I put that statement in class Dialog1 in Dialog1.h . Now I try do declare it in onButton function like MainDialog* p_MainDialog = NULL; // Is this right I guess not ? but I also get unhandled exception at 0x0045ca30 ....Access violation reading location 0x000000e4. hWnd is still = ??? Do You know right way to do this? Regards
-
Hi, I put that statement in class Dialog1 in Dialog1.h . Now I try do declare it in onButton function like MainDialog* p_MainDialog = NULL; // Is this right I guess not ? but I also get unhandled exception at 0x0045ca30 ....Access violation reading location 0x000000e4. hWnd is still = ??? Do You know right way to do this? Regards
I do not want to sound cruel or anything but if you think that setting a pointer to NULL and then refernceing that pointer would do anything other than crash / throw an exception, you're going to need to take some classes or read a book on programming. I cannot debug your progam for you one message at a time and I'm not inclinded to write it for you. You will be better off finding someone at your work or in your class to help you with this.