?
Solved

Multiple Windows for one MFC program?

Posted on 2003-02-25
4
Medium Priority
?
180 Views
Last Modified: 2013-11-20
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...
0
Comment
Question by:TeABaG_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 8023184
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11812222
PAQed - no points refunded (of 50)

modulo
Community Support Moderator
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question