?
Solved

Creating child windows with forms

Posted on 1999-01-09
2
Medium Priority
?
181 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 400 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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