• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Need some help with open a dialog

Hello,
I have 2 dialogs.
1.dialog you can display the order (CAuftragHistory.cpp)
2.dialog you can change the order  (CAuftragAendern_Dialog)




 I do call from my 1.dialog (CAuftragsHistory.cpp) the 2.dialog (like this)

         //-------------- Auftrag Ändern Dialog ------------------
          CAuftragAendern_Dialog *pMeinDialog;
          pMeinDialog = new CAuftragAendern_Dialog;
          pMeinDialog->m_bKennzahl_komme_von_AuftragHistory=true;
          pMeinDialog->str_ABNr=str_ABNr
          pMeinDialog->ShowWindow(SW_SHOW);
          //--------------------------------------------------------





Then I do the changes in the 2.dialog (CAuftragAendern_Dialog.cpp)
and save the order.
Then I close the 2.dialog, and the 1.dialog is there.
Now I would like to reload the order to see the changes in the 2.dialog

         //-------------- Auftrag Ändern Dialog ------------------
          CAuftragAendern_Dialog *pMeinDialog;
          pMeinDialog = new CAuftragAendern_Dialog;
          pMeinDialog->m_bKennzahl_komme_von_AuftragHistory=true;
          pMeinDialog->str_ABNr=str_ABNr
          pMeinDialog->ShowWindow(SW_SHOW);


          Reload_my_oder();
          anything I do here (behind the call) will done before the
          2.dialog is closed, and I do not see any changes.

          //--------------------------------------------------------
I hope you understand my problem.
How can I change this?
500 points with a solution.

Best regards,
Thomas
0
Thomas Stockbruegger
Asked:
Thomas Stockbruegger
  • 2
  • 2
2 Solutions
 
ZoppoCommented:
Hi tsp2002,

I'm not really sure if I understand the problem, so I first like to undestand how you want your program to work.

You create and show the second dialog as a modeless dialog and I'm not sure if it's really intended, because with a modeless dialog you can switch back to the first dialog without even closing the second one, so they can be used parallel and I'm not sure if you need/want this.

I guess for your case modal dialogs are the better choice because you have one single place where the second dialog is opened, shown and closed.

To do this you can use the second dialog somehow like this i.e. from button click message handler:
CAuftragAendern_Dialog meinDialog;
// read data and set it in 'meinDialog'
if ( IDOK == meinDialog.DoModal() )
{
 // read data from the dialog and store them
}

Open in new window

If this doesn't help you should declare more detailed what the real problem is, i.e. retrieving/saving/loading/setting data in the second dialog ...

ZOPPO
0
 
Thomas StockbrueggerAuthor Commented:
Hi Zoppo,
thank you for your answer. I did not mentioned that both dialogs are modeless and they should be left that way.
// cannot call DoModal on a dialog already constructed as modeless
 
In CAuftragAendern_Dialog.cpp (the dialog that I call to change the order) I did the following:

   OnInitDialog
   ============
  SetTimer(1,1000,NULL);



  OnTimer
  =======  

     if(m_bKennzahl_komme_von_AuftragHistory==true)
      {
            //Membervariable CString str_ABNr;
             m_Edit_AuftragsNr.SetWindowText(str_ABNr);
             m_bKennzahl_komme_von_AuftragHistory=false;

            //==============================
            OnBnClickedButton_AuftragSuchen();             <----- call function to show the order
            //==============================
            
      }
 




It is possible to do the same backwards?
When I close the  CAuftragAendern_Dialog.cpp to go to a function in CAuftragsHistory.cpp
Or it is impossible because of 2 modeless dialogs? If so I do a messagebox the that user have to reload the order
in CAuftragsHistory.cpp to see any changes that was done in  CAuftragAendern_Dialog.cpp

Please let me know, thank you.
0
 
ZoppoCommented:
ok, so the main problem is simply you need to get noticed in dialog 1 when dialog 2 is closed, right?

IMO the easiest to do so is to add a pointer to dialog 1 in dialog 2 and call a function in dialog 1 from an overridden 'OnOK' in dialog 2.

But this is not very generic because thus dialog 2 can't be used with other dialogs than dialog 1.

To keep it more generic a common way is to define and handle your own message and send it to the parent window of dialog 2 (a sample for this can be found i.e. at https://msdn.microsoft.com/en-us/library/k35k2bfs.aspx) - this way the dialog can be used as modeless child with different parent dialogs, each of them can handle the message as needed.

Another possiility would be to use some kinf of callback functions ...

ZOPPO
0
 
sarabandeCommented:
from a design point of view: modeless dialogs don't have an ok button and rarely can't be closed. instead they would close with their parent frame or parent window.

if you have two modeless dialogs the user can click to either of the dialogs or even outside of both what makes it difficult for you to keep control. because of that modeless dialogs always should be controlled by a parent window for example by a property sheet with tabs for each dialog or a frame window which offers a menu and toolbar buttons. for the latter you might consider to creating an sdi project and have form views instead of dialogs.

so the main problem is simply you need to get noticed in dialog 1 when dialog 2 is closed, right?
you may call GetParent()->SendMessage(WM_MY_MSG_DLG2_WAS_CLOSED, (WPARAM)IDOK, 0) to send a message from dialog 2 to dialog 1. WM_MY_MSG_DLG2_WAS_CLOSED could be defined as WM_USER + 1234 in a header which was included by both dialogs. in dialog 1 class you would catch the message by adding

ON_MESSAGE(WM_MY_MSG_DLG2_WAS_CLOSED, OnCloseDialog2)

Open in new window


into the message map (between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP) of the dialog class. OnCloseDialog2 is a member function of dialog1 class which is declared as

afx_msg LRESULT OnCloseDialog2 (WPARAM, LPARAM);

Open in new window


to make all that working, you would need a pointer of dialog2 'm_pMeinDialog2' as member in dialog 1 and create the dialog 2 by

   
m_pMeinDialog2 = new CAuftragAendern_Dialog(this);   // pass 'this' as parent to dialog 2 

Open in new window


that way dialog 1 has a pointer of dialog2 and dialog 2 can get a pointer of dialog 1 by

CAuftragHistory * pMeinDialog1 = (CAuftragHistory *)GetParent();

Open in new window


in OnCloseDialog2 you could get data from dialog2 by using the member pointer. that is possible because the dialog2 is still alive when it calls SendMessage and therefore you can retrieve all data from dialog2.

note, in the sample call I passed IDOK as WPARAM to dialog1. if you also have a cancel button in dialog2, you could pass IDCANCEL in that case. that way dialog1 would know whether dialog2 was closed by ok or by cancel.

Sara
0
 
Thomas StockbrueggerAuthor Commented:
Hello Zoppo and Sara,
thank you for your answers. I think I found a simple solution.
I just close the first dialog AuftragHistory if the user clicks the
button to change the order and go to AuftragAendern_Dialog.
I build both dialog modeless because the can act on its own, but do to my
program stuctur the 1.dialog do not need to be open if the user is on the
2.dialog.

1.dialog = AuftragHistory
2.dialog = AuftragAendern_Dialog





in AuftragHistory.cpp

     //========== Wenn ich von AuftragAendern komme ========
     SetTimer(1,1000,NULL);
    //=====================================================


void CAuftragsHistory::OnTimer(UINT nIDEvent)
{
      
      if(m_bKennzahl_komme_von_AuftragAendern_Dialog==true)
      {
            //Membervariable CString str_ABNr;
            m_Edit_AuftragsNr.SetWindowText(str_ABNr);
            m_bKennzahl_komme_von_AuftragAendern_Dialog=false;

            //==============================
            OnBnClickedButtonAuftragSuchen();
            //==============================
      }


      CDialog::OnTimer(nIDEvent);
}


if the user clicks on the button to change the order
//-------------- Auftrag Ändern Dialog ------------------
          CAuftragAendern_Dialog *pMeinDialog;
          pMeinDialog = new CAuftragAendern_Dialog;
          pMeinDialog->m_bKennzahl_komme_von_AuftragHistory=true;
          pMeinDialog->str_ABNr=str_ABNr;//setzte AuftragsNr auf die          AufragsNr in Auftrag Ändern
          pMeinDialog->ShowWindow(SW_SHOW);
            //==============================
            OnBnClickedButtonExit();//close dialog
            //==============================
          //--------------------------------------------------------












in AuftragAendern_Dialog.cpp


     //========== Wenn ich von AuftragHistory komme ========
     SetTimer(1,1000,NULL);
    //=====================================================


void CAuftragAendern_Dialog::OnTimer(UINT nIDEvent)
 {
      if(m_bKennzahl_komme_von_AuftragHistory==true)
      {
            //Membervariable CString str_ABNr;
             m_Edit_AuftragsNr.SetWindowText(str_ABNr);
             m_bKennzahl_komme_von_AuftragHistory=false;

             m_bKennzahl_gehe_nach_AuftragHistory_zurueck=true;

            //==============================
            OnBnClickedButton_AuftragSuchen();
            //==============================
            
      }

       CDialog::OnTimer(nIDEvent);
 }



void CAuftragAendern_Dialog::OnBnClickedButtonExit()
{
      CDialog::OnCancel();
      

       //=========== wenn ich von AuftragsHistory komme gehe ich dort zurück ==============
       if(m_bKennzahl_gehe_nach_AuftragHistory_zurueck==true)
       {
         CAuftragsHistory *pMeinDialog;
           pMeinDialog = new CAuftragsHistory;
           pMeinDialog->m_bKennzahl_komme_von_AuftragAendern_Dialog=true;
         pMeinDialog->str_ABNr=str_ABNr;//setzte AuftragsNr auf die AufragsNr in AuftragsHistory
           pMeinDialog->ShowWindow(SW_SHOW);
             m_bKennzahl_gehe_nach_AuftragHistory_zurueck=false;
       }
       //==========================================================================


}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now