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. Communications between dialogs

Communications between dialogs

Scheduled Pinned Locked Moved C / C++ / MFC
announcement
9 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.
  • T Offline
    T Offline
    Trupti Mehta
    wrote on last edited by
    #1

    I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as

    enum
    {
    BASE /* not used */ = WM_USER,
    CHANGED_DS, SHOW_NEXT_VIEW,
    };

    void CPage1Dlg::TellParent()
    {
    // Update deptStock obj with the parent
    this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
    this->ShowWindow(false);
    CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
    }

    In parent: Childs are created as below in OnInitDialog():

    CRect rect(4, 2, 5,2);
    CPoint point(0, 10);
    
    childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL);
    childPage1.SetDeptStock(deptStock);
    
    rect += point;
    childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL);
    childPage2.ShowWindow(false);
    
    
    childVisible = 1;
    

    afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
    // handles message sent up from child dialog
    {
    deptStock = (DeptStock&)lparam;
    AfxMessageBox(_T("Dept Stock Updated"));
    return 0;
    }

    afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {

    int childView = (int)lparam;
    AfxMessageBox(childView);
    
    if (childView ==2) {
    	childPage2.SetDeptStock(deptStock);
    	childPage2.ShowWindow(true);
    	childVisible = 2;
    }
    
    return 0;
    

    }

    Any guidance on the above is highly appreciated.

    Thanks Terry

    K D J 3 Replies Last reply
    0
    • T Trupti Mehta

      I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as

      enum
      {
      BASE /* not used */ = WM_USER,
      CHANGED_DS, SHOW_NEXT_VIEW,
      };

      void CPage1Dlg::TellParent()
      {
      // Update deptStock obj with the parent
      this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
      this->ShowWindow(false);
      CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
      }

      In parent: Childs are created as below in OnInitDialog():

      CRect rect(4, 2, 5,2);
      CPoint point(0, 10);
      
      childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL);
      childPage1.SetDeptStock(deptStock);
      
      rect += point;
      childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL);
      childPage2.ShowWindow(false);
      
      
      childVisible = 1;
      

      afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
      // handles message sent up from child dialog
      {
      deptStock = (DeptStock&)lparam;
      AfxMessageBox(_T("Dept Stock Updated"));
      return 0;
      }

      afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {

      int childView = (int)lparam;
      AfxMessageBox(childView);
      
      if (childView ==2) {
      	childPage2.SetDeptStock(deptStock);
      	childPage2.ShowWindow(true);
      	childVisible = 2;
      }
      
      return 0;
      

      }

      Any guidance on the above is highly appreciated.

      Thanks Terry

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      A lot of dialogs opened in one program is bad style and is confusing the programer and user so you should avoid it. :-O For communication is messaging between windows and dialogs suitable. Do it via PostMessage to avoid blocking. For the data you better use one global object so everywhere is the same data. Then you only need to post the message to every open window/dialog that data is changed. Please believe me: make a array of HWND!!!

      Greetings from Germany

      T 1 Reply Last reply
      0
      • K KarstenK

        A lot of dialogs opened in one program is bad style and is confusing the programer and user so you should avoid it. :-O For communication is messaging between windows and dialogs suitable. Do it via PostMessage to avoid blocking. For the data you better use one global object so everywhere is the same data. Then you only need to post the message to every open window/dialog that data is changed. Please believe me: make a array of HWND!!!

        Greetings from Germany

        T Offline
        T Offline
        Trupti Mehta
        wrote on last edited by
        #3

        Thanks KarstenK,

        KarstenK wrote:

        Please believe me: make a array of HWND!!!

        I am gonna make an array of CDialog & place each child dialog in it. Currectly, I am just checking it with 2 dialogs. Can you give some helpline of how to do with PostMessage. The

        this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);

        in return calls PostMessage by passing the childDialogId as WPAram

        void CRHGenericChildDialog::CRHPostMessageToParent(UINT message, LPARAM lParam)
        {
        CRHpParent->PostMessage(message, CRHId, lParam);
        }

        Thanks Terry

        1 Reply Last reply
        0
        • T Trupti Mehta

          I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as

          enum
          {
          BASE /* not used */ = WM_USER,
          CHANGED_DS, SHOW_NEXT_VIEW,
          };

          void CPage1Dlg::TellParent()
          {
          // Update deptStock obj with the parent
          this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
          this->ShowWindow(false);
          CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
          }

          In parent: Childs are created as below in OnInitDialog():

          CRect rect(4, 2, 5,2);
          CPoint point(0, 10);
          
          childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL);
          childPage1.SetDeptStock(deptStock);
          
          rect += point;
          childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL);
          childPage2.ShowWindow(false);
          
          
          childVisible = 1;
          

          afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
          // handles message sent up from child dialog
          {
          deptStock = (DeptStock&)lparam;
          AfxMessageBox(_T("Dept Stock Updated"));
          return 0;
          }

          afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {

          int childView = (int)lparam;
          AfxMessageBox(childView);
          
          if (childView ==2) {
          	childPage2.SetDeptStock(deptStock);
          	childPage2.ShowWindow(true);
          	childVisible = 2;
          }
          
          return 0;
          

          }

          Any guidance on the above is highly appreciated.

          Thanks Terry

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

          Trupti Mehta wrote:

          I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog.

          Sounds like you need a property sheet wizard.

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          1 Reply Last reply
          0
          • T Trupti Mehta

            I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as

            enum
            {
            BASE /* not used */ = WM_USER,
            CHANGED_DS, SHOW_NEXT_VIEW,
            };

            void CPage1Dlg::TellParent()
            {
            // Update deptStock obj with the parent
            this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
            this->ShowWindow(false);
            CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
            }

            In parent: Childs are created as below in OnInitDialog():

            CRect rect(4, 2, 5,2);
            CPoint point(0, 10);
            
            childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL);
            childPage1.SetDeptStock(deptStock);
            
            rect += point;
            childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL);
            childPage2.ShowWindow(false);
            
            
            childVisible = 1;
            

            afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
            // handles message sent up from child dialog
            {
            deptStock = (DeptStock&)lparam;
            AfxMessageBox(_T("Dept Stock Updated"));
            return 0;
            }

            afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {

            int childView = (int)lparam;
            AfxMessageBox(childView);
            
            if (childView ==2) {
            	childPage2.SetDeptStock(deptStock);
            	childPage2.ShowWindow(true);
            	childVisible = 2;
            }
            
            return 0;
            

            }

            Any guidance on the above is highly appreciated.

            Thanks Terry

            J Offline
            J Offline
            Jijo Raj
            wrote on last edited by
            #5

            Terry, So you have one parent dialog and 7 child dialogs. At first one of your child dialog will be displayed and if you click one button in child dialog, that child should be closed and next child dialog should be shown until all child dialog finishes. Is that your requirement? Regards, Jijo.

            _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

            T 1 Reply Last reply
            0
            • J Jijo Raj

              Terry, So you have one parent dialog and 7 child dialogs. At first one of your child dialog will be displayed and if you click one button in child dialog, that child should be closed and next child dialog should be shown until all child dialog finishes. Is that your requirement? Regards, Jijo.

              _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

              T Offline
              T Offline
              Trupti Mehta
              wrote on last edited by
              #6

              Yes, want to hide 1 child and show other child. But I want this to be controlled programmatically as the child dialogs need not be in series. I mean after child3, on some basis child5, or child7 or child3 should come respectively. I work on WinCE5 for a specific device and it doesn't support Property Sheets. WinCe supports, but that device's SDK doesn't support. So, I got to work out manually only.

              Thanks Terry

              J 1 Reply Last reply
              0
              • T Trupti Mehta

                Yes, want to hide 1 child and show other child. But I want this to be controlled programmatically as the child dialogs need not be in series. I mean after child3, on some basis child5, or child7 or child3 should come respectively. I work on WinCE5 for a specific device and it doesn't support Property Sheets. WinCe supports, but that device's SDK doesn't support. So, I got to work out manually only.

                Thanks Terry

                J Offline
                J Offline
                Jijo Raj
                wrote on last edited by
                #7

                Terry, I hope in your parent dialog, you're creating instance of child dialog and shows it by calling DoModel(). Instead of child dialog sending message to parent, just close the child dialog by calling EndDialog() function. In the EndDialog() you can give a parameter which will be returned by the DoModel() function. So by checking the return code of ChildDialog.DoModel(), you can show next dialog. For instance,

                void CParentDialog::ShowChildDialog()
                {
                CDialogDlg ChildDialog;
                if( SHOW_NEXT_DIALOG == ChildDialog.DoModal())
                {
                // Show your next child dialog.
                }
                }

                // In child dialog
                void ChildDialog::OnNextDialog()
                {
                // The SHOW_NEXT_DIALOG will be returned by the DoModel() call.
                EndDialog( SHOW_NEXT_DIALOG );
                }

                Here in the e.g. if the DoModel() returns SHOW_NEXT_DIALOG, then its the request to show next dialog. Just try this. Just let me know if you've more issues. Regards, Jijo.

                _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                T 1 Reply Last reply
                0
                • J Jijo Raj

                  Terry, I hope in your parent dialog, you're creating instance of child dialog and shows it by calling DoModel(). Instead of child dialog sending message to parent, just close the child dialog by calling EndDialog() function. In the EndDialog() you can give a parameter which will be returned by the DoModel() function. So by checking the return code of ChildDialog.DoModel(), you can show next dialog. For instance,

                  void CParentDialog::ShowChildDialog()
                  {
                  CDialogDlg ChildDialog;
                  if( SHOW_NEXT_DIALOG == ChildDialog.DoModal())
                  {
                  // Show your next child dialog.
                  }
                  }

                  // In child dialog
                  void ChildDialog::OnNextDialog()
                  {
                  // The SHOW_NEXT_DIALOG will be returned by the DoModel() call.
                  EndDialog( SHOW_NEXT_DIALOG );
                  }

                  Here in the e.g. if the DoModel() returns SHOW_NEXT_DIALOG, then its the request to show next dialog. Just try this. Just let me know if you've more issues. Regards, Jijo.

                  _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                  T Offline
                  T Offline
                  Trupti Mehta
                  wrote on last edited by
                  #8

                  Thanks Jijo, As the dialogs are not in series & can call previous dialog also. So I call messages SHOW_NEXT_DIALOG with the child dialog # to be shown & it works perfectly. I figured out to work as expected. Thanks jijo for the efforts. Jijo, I can't add an int, float to CString. Like I want to add up "Name " + int + float in a CString. How do I achieve it. I tried many ways, but gives error or warnings only. Help me if you can.

                  Thanks Terry

                  J 1 Reply Last reply
                  0
                  • T Trupti Mehta

                    Thanks Jijo, As the dialogs are not in series & can call previous dialog also. So I call messages SHOW_NEXT_DIALOG with the child dialog # to be shown & it works perfectly. I figured out to work as expected. Thanks jijo for the efforts. Jijo, I can't add an int, float to CString. Like I want to add up "Name " + int + float in a CString. How do I achieve it. I tried many ways, but gives error or warnings only. Help me if you can.

                    Thanks Terry

                    J Offline
                    J Offline
                    Jijo Raj
                    wrote on last edited by
                    #9

                    Trupti Mehta wrote:

                    Jijo, I can't add an int, float to CString. Like I want to add up "Name " + int + float in a CString. How do I achieve it. I tried many ways, but gives error or warnings only. Help me if you can.

                    CString csMessage;
                    int nInteger = 10;
                    float fFloat = 20.0f;

                    // Format the message.
                    csMessage.Format( _T("%s %d %f"), // Format String.
                    _T("Name :"),
                    nInteger,
                    fFloat );
                    // if you want to format the float precision, just use %0.2f in format string.
                    // So only two decimal digits will be shown.

                    Hope the code snippet explains everything you asked. :) Regards, Jijo.

                    _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                    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