Solved

Creating child windows with forms

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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