Solved

Creating child windows with forms

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

20 Experts available now in Live!

Get 1:1 Help Now