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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Passing data between tabs in a tab control [modified]

Passing data between tabs in a tab control [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiontutorialannouncement
7 Posts 3 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.
  • C Offline
    C Offline
    cppcook
    wrote on last edited by
    #1

    Hi all, I have a tab control in a dialog. There are 5 tabs in total, with each tab associated with a child dialog. I wanna exchange information between these tabs. I store and update all information in a global structure. When I switch between these tabs, I want to update data in these tabs. How can I do that? Currently I am using: CMyTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult) { int nSel = GetCurSel(); if(m_Dialog[nSel]->m_hWnd) m_Dialog[nSel]->ShowWindow(SW_HIDE); //hide window ............ //hide all tabs and show the selected tab for(int nCount=0; nCount < m_nPageCount; nCount++){ m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_HIDEWINDOW); } m_Dialog[nSel]->SetWindowPos(&wndTop,l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_SHOWWINDOW); m_Dialog[nSel]->ShowWindow(SW_SHOW); //show selected tab **m_Dialog[nSel]->OnInitDialog();** //update information for each dialog } I placed all updating code in each child dialog's OnInitDialog() function. The problem is this function will be called twice so some controls like ListView have double items. How to fix this problem? Do I need to use SendMessage(), PostMessage()? thanks, Gavin

    E H 2 Replies Last reply
    0
    • C cppcook

      Hi all, I have a tab control in a dialog. There are 5 tabs in total, with each tab associated with a child dialog. I wanna exchange information between these tabs. I store and update all information in a global structure. When I switch between these tabs, I want to update data in these tabs. How can I do that? Currently I am using: CMyTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult) { int nSel = GetCurSel(); if(m_Dialog[nSel]->m_hWnd) m_Dialog[nSel]->ShowWindow(SW_HIDE); //hide window ............ //hide all tabs and show the selected tab for(int nCount=0; nCount < m_nPageCount; nCount++){ m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_HIDEWINDOW); } m_Dialog[nSel]->SetWindowPos(&wndTop,l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_SHOWWINDOW); m_Dialog[nSel]->ShowWindow(SW_SHOW); //show selected tab **m_Dialog[nSel]->OnInitDialog();** //update information for each dialog } I placed all updating code in each child dialog's OnInitDialog() function. The problem is this function will be called twice so some controls like ListView have double items. How to fix this problem? Do I need to use SendMessage(), PostMessage()? thanks, Gavin

      E Offline
      E Offline
      eusto
      wrote on last edited by
      #2

      Don't call OnInitDialog to init your data(i guess you used Create to create the dialogs...right?). Write some other methods for handling the OnDisplay Event.

      C 1 Reply Last reply
      0
      • C cppcook

        Hi all, I have a tab control in a dialog. There are 5 tabs in total, with each tab associated with a child dialog. I wanna exchange information between these tabs. I store and update all information in a global structure. When I switch between these tabs, I want to update data in these tabs. How can I do that? Currently I am using: CMyTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult) { int nSel = GetCurSel(); if(m_Dialog[nSel]->m_hWnd) m_Dialog[nSel]->ShowWindow(SW_HIDE); //hide window ............ //hide all tabs and show the selected tab for(int nCount=0; nCount < m_nPageCount; nCount++){ m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_HIDEWINDOW); } m_Dialog[nSel]->SetWindowPos(&wndTop,l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_SHOWWINDOW); m_Dialog[nSel]->ShowWindow(SW_SHOW); //show selected tab **m_Dialog[nSel]->OnInitDialog();** //update information for each dialog } I placed all updating code in each child dialog's OnInitDialog() function. The problem is this function will be called twice so some controls like ListView have double items. How to fix this problem? Do I need to use SendMessage(), PostMessage()? thanks, Gavin

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Can you explain why you use OnInitDialog for update,please.Do you have specific statements in this function_**


        **_

        whitesky


        C 1 Reply Last reply
        0
        • E eusto

          Don't call OnInitDialog to init your data(i guess you used Create to create the dialogs...right?). Write some other methods for handling the OnDisplay Event.

          C Offline
          C Offline
          cppcook
          wrote on last edited by
          #4

          thanks eusto, Yes. I know I shouldn't use OnInitDialog(). I am just wondering which message or function of CDialog Class should I use. I couldn't find the OnDisplay event in Class Wizard. which one of the following should I use? WM_PAINT WM_DRAWITEM WM_COPYDATA WM_CAPTURECHANGE thanks, Gavin

          E 1 Reply Last reply
          0
          • H Hamid Taebi

            Can you explain why you use OnInitDialog for update,please.Do you have specific statements in this function_**


            **_

            whitesky


            C Offline
            C Offline
            cppcook
            wrote on last edited by
            #5

            Thanks WhiteSky, No special reason. I just want to use an overrided function of CDialog class because I don't know which child dialog class is run at run time.

            H 1 Reply Last reply
            0
            • C cppcook

              thanks eusto, Yes. I know I shouldn't use OnInitDialog(). I am just wondering which message or function of CDialog Class should I use. I couldn't find the OnDisplay event in Class Wizard. which one of the following should I use? WM_PAINT WM_DRAWITEM WM_COPYDATA WM_CAPTURECHANGE thanks, Gavin

              E Offline
              E Offline
              eusto
              wrote on last edited by
              #6

              OnDisplay was just a name i came up with. Implement a method called LoadData for example and do everything that needs to be done there. For example for the first CEmbeddedDialog do something like this. Call CEmbededDialog.Create(...) then Call CEmbededDialog.LoadData(); In your LoadData method you should put the code that loads your comboboxes and so forth. You don't need to handle the actual selection of the dialog afterwards...all tabs from the CMyTabCtrl have been initialised when displaying the actual CMyTabCtrl. What your selection should do is hide all other CDialogs except for the one placed in the current selected tab. Think of your dialogs as actual C++ Objects (wich they are...). Sorry if this is a bit unclear... i'm not an english speaker

              1 Reply Last reply
              0
              • C cppcook

                Thanks WhiteSky, No special reason. I just want to use an overrided function of CDialog class because I don't know which child dialog class is run at run time.

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                if you need to update you can write your function and use from it_**


                **_

                whitesky


                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