Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC - Passing data between dialogs in Tab Control

MFC - Passing data between dialogs in Tab Control

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionc++
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    melinda_mel
    wrote on last edited by
    #1

    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

    F C 2 Replies Last reply
    0
    • M melinda_mel

      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

      F Offline
      F Offline
      Franck Paquier
      wrote on last edited by
      #2

      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

      M 2 Replies Last reply
      0
      • F Franck Paquier

        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

        M Offline
        M Offline
        melinda_mel
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • M melinda_mel

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • F Franck Paquier

            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

            M Offline
            M Offline
            melinda_mel
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • M melinda_mel

              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

              C Offline
              C Offline
              Chuck OToole
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • C Chuck OToole

                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

                M Offline
                M Offline
                melinda_mel
                wrote on last edited by
                #7

                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

                C 1 Reply Last reply
                0
                • M melinda_mel

                  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

                  C Offline
                  C Offline
                  Chuck OToole
                  wrote on last edited by
                  #8

                  0xcdcd...is indicitive of an unitialized variable. You declared p_MainDialog but did you put anything into it?

                  M 1 Reply Last reply
                  0
                  • C Chuck OToole

                    0xcdcd...is indicitive of an unitialized variable. You declared p_MainDialog but did you put anything into it?

                    M Offline
                    M Offline
                    melinda_mel
                    wrote on last edited by
                    #9

                    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

                    C 1 Reply Last reply
                    0
                    • M melinda_mel

                      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

                      C Offline
                      C Offline
                      Chuck OToole
                      wrote on last edited by
                      #10

                      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.

                      M 1 Reply Last reply
                      0
                      • C Chuck OToole

                        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.

                        M Offline
                        M Offline
                        melinda_mel
                        wrote on last edited by
                        #11

                        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

                        C 1 Reply Last reply
                        0
                        • M melinda_mel

                          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

                          C Offline
                          C Offline
                          Chuck OToole
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups