Solved

Creating child windows with forms

Posted on 1999-01-09
2
160 Views
Last Modified: 2013-11-20
Hello,
I am a very new VC++6/MFC programmer.  I have just been using AppWizard to create a standard application, based on CFormView, which when run shows a form in a window which also has a menu etc..  Entirely standard document/view stuff.

What I am really looking to do is to create a main window which displays a form, and then to create via menu options several child windows which all have their own unique forms, all based on the document/view architecture.  The App Wizard doesn't really show you how to manage forms in this way;  it forces you to use MDI, or it allows you to create just one form in one window.

I would be very grateful if someone could give me the code to use for creating a child window, with a form (view and document) in it.  I am actually looking for code to create an unlimited number of different types of child forms.

Thanks,
TrimTrom
0
Comment
Question by:trimtrom
2 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 100 total points
ID: 1327430
You can have multiple views in a SDI application. However, each view will become part of the main frame window when called. They will not be seperate child windows. Try his:
Create the other views separately by inserting a new class. Make sure that this class is
derived from the appropriate view class. Assume that this view is called
CMyNewView.

Add the following protected instance variable and member function
in the CMainFrame class.

protected:
      enum show {MYVIEW=1, DEFVIEW=2};
      void SwitchView(show nView);

Add the following menu option : MyView  (mapped to OnMyView) and
DefaultView (mapped to OnDefView)

Write the following code for OnMyView
void CMainFrame::OnMyView()
{
      // TODO: Add your command handler code here
            SwitchView(MYVIEW);            
}

Similarly this code goes for OnDefView
void CMainFrame::OnDefView()
{
      // TODO: Add your command handler code here
      SwitchView(DEFVIEW);      
}

Here is the code for SwitchView
void CMainFrame::SwitchView(show nView){
      CView * poldview=GetActiveView();
      CView * pnewview=(CView *)GetDlgItem(nView);
      if(pnewview==NULL){
            switch(nView){
            case MYVIEW:
                  pnewview=(CView *)new CMyNewView;
                  break;
            case DEFVIEW:
                  pnewview=(CView *)new CMyAppView;
                  break;
            }
            CCreateContext context;
            context.m_pCurrentDoc=poldview->GetDocument();
            pnewview->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nView,&context);
            pnewview->OnInitialUpdate();
      }
      SetActiveView(pnewview);
      pnewview->ShowWindow(SW_SHOW);
      poldview->ShowWindow(SW_HIDE);
      poldview->SetDlgCtrlID(poldview->GetRuntimeClass()==
            RUNTIME_CLASS(CMyAppView)?DEFVIEW:MYVIEW);
      pnewview->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
      RecalcLayout();
}

Also add these handlers:
void CMainFrame::OnUpdateViewDefView(CCmdUI* pCmdUI)
{
      // TODO: Add your command update UI handler code here
      pCmdUI->Enable(!GetActiveView()->IsKindOf(RUNTIME_CLASS(CMyAppView)));      
}

void CMainFrame::OnUpdateViewSummary(CCmdUI* pCmdUI)
{
      // TODO: Add your command update UI handler code here
      pCmdUI->Enable(!GetActiveView()->IsKindOf(RUNTIME_CLASS(CMyNewView)));      
}


0
 

Author Comment

by:trimtrom
ID: 1327431
Thanks very much for the detailed answer.  I will now study it and respond quickly.

Trimtrom
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 162
Add content to output file 4 62
Expand to include initial dialog with two choices. 9 67
FizzBuzz challenge 9 76
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now