Multiple Windows for one MFC program?

I currently have a SDI MFC program (no doc/view support).  I would like to know how (and if its possible) to use more than window for my application.  For example, if the user clicks within a certain rectangle then I want it to bring up a second window (totally different than the first) while hiding the main window.  Then if the user hits the main menu option on the second menu, it will take you back to the main window and hide the second window.
I am sorry if this is confusing but its the only way I know to describe it.  I dont necessarily need the entire code for this, I just want to know the basic method for doing this.  And can i do this using a SDI program with no doc/view support or do I have to use another approach?  Thanks for your help...
TeABaG_Asked:
Who is Participating?
 
moduloConnect With a Mentor Commented:
PAQed - no points refunded (of 50)

modulo
Community Support Moderator
0
 
Answers2000Commented:
Yes you can, including your way, and another way

Quicker way:

The quickest hack would be to do it as a dialog application. Dialogs can be resizable have menus etc. Override OnOK and OnCancel to do nothing, and make your own exit commands that call EndDialog with an ID.

The ID being say ID_EXIT and ID_SWITCHWIN etc

In the code that calls DoModal detect and loop something like:

CMyDialog1 dlg1 ;
CMyDialog2 dlg2 ;
int nButton ;
do
{
 nButton = dlg1.DoModal() ;
 if ( nButton == ID_SWITCHWIN )
 {
   nButton = dlg2.DoModal() ;
 }
} while (nButton != ID_EXIT ) ;


Your way:

You can do it, but you will probably be swimming against the tide and the class wizard.  

In Windows API this would be a trivial problem - just do it. With MFC it is likely to be a bit harder.

Probably the easiest thing to do is to make 2 empty apps with ALL different file + class names for the sources (except CWinApp and CAboutDlg stuff), then try and combine them to come into one project

When original MainFrame gets switch message it hides itself using ShowWindow, and creates your other top level window. Watch out - the parent of the new window needs to be the desktop, so careful of functions which assume parent window as a default (note: Windows API HWND = NULL means child of desktop, MFC CWnd * = NULL generally means child of current top level window and MFC might get it wrong in this scenario as AfxGetMainWnd() is going to return the original window) - in other words you will have to start worrying about which window is parent for dialogs, message boxes, etc.
0
All Courses

From novice to tech pro — start learning today.