Solved

Creating child windows with forms

Posted on 1999-01-09
2
163 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

828 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