Re: insert dialog



frank wrote:

A question regarding MS Visual C++ 6.0 and inserting a second dialog:
Could someone tell me what additional steps to take in order to be
able to add in a second dialog box after you have let the MFC Wizard create
a working dialog project of lets say name of: FIRST?
So far I have taken these steps and am getting error messages.
steps:
1 In resources of FIRST clicked on insert dialog
2 New dialog gets ID of ID_Dialog1
3 Use wizard to Create new class CSecondDialog, with base class set to
Cdialog
4 In the command button's code section that I want to have open the second
  dialog box I add the following lines:
  //create the second dialog window
  m_dlg.Second.Create(ID_Dialog1, this);

  //show the second dialog window
  m_dlg.Second.ShowWindow(SW_SHOW);
5 Include the header for this Second dialog at the top of the original
dialog
  source code in the #include area with others, sidenote of what order here?
  #include "SecondDialog.h"
6 Include the header for the main FIRST dialog in the Seconddlg.cpp source
code file
  for the second dialog
  #include "FIRSTDialog.h"
7 then in FIRST's message map area, after the public and protected area I
add:
  private:
  CSecondDlg m_dlgSecond;
/***************************************************************************
******************/
Ok what else needs to be done because the compiler complains of missing
a semicolon before the member variable?



frank:

This is not useful. Show us REAL code. How do we know

What is m_dlg ?
What is Second ?

Do you mean

m_dlgSecond.Create(ID_Dialog1, this); ??

If you paste your ACTUAL code, you will not post things like
m_dlg.Second.Create(ID_Dialog1, this) (unless that is really what you have in your code, in which case it certainly won't compile).


A couple of points about include's

1. You should not have to include Dlg1.h in Dlg2.cpp. The parent should know about the child, but having the child know about the parent is usually bad design.

2. The order of include's should not matter. If it does, it means that one header depends on another. In fact in your case you have a member variable of type CSecondDlg in your first dialog class; therefore Dlg1.h should include Dlg2.h, and you do not need to include Dlg2.h in Dlg1.cpp.

HTH,

David Wilkinson
.