Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Creating MDI programs with eVC++ 3.0

0.00/5 (No votes)
4 Jul 2003 1  
An article to illustrate how to create multiple views in WinCE using eVC++ 3.0 compiler for PocketPC 2002

Sample Image - MDIWinCE.jpg

Introduction

WinCE for PocketPC 2002 normally only supports SDI MFC applications. With a little trickery, you can convert it to an MDI application by swapping views when necessary. You still will not be able to see more than one view at a time due to limited real-estate. You have the choice of just hiding the current view, destroying the current view or hide some and destroy others. New views are created dynamically and there is no limit to the number of views that can be in memory at any one time -- except of course the limit will be the amount of memory in the hardware. The views can be any type supported by the eVC++ 3.0 compiler.

There can be as many different view classes as desired, but only one instance of any given view. So you can have one instance of each of these views: CMyFirstView, CMySecondView and CMyThirdView, but you can not have two instances of CMyFirstView. The reason is because OnSelectNextView() searches its list of current views to see if a view of the desired class already exists. If it does exist, then it is activated. Otherwise, if it does not exist a new instance of the desired class type is created and added to the list.

Using the code

These are the steps needed to implement the class in your project.

  1. Create a new MFC Document/View project, or use an existing project.
  2. Copy the two files SVMainFrame.cpp and SVMainFrame.h into the project directory and add them to the project.
  3. Open CMainFrm.h and replace CFrameWnd with CSFMainFrame.
class CMainFrame : public CSVMainFrame
{
  // class definition here.
{
  1. In CMainFrm.h DELETE the CCeCommandBar m_wndCommandBar object because it is declared in CSVMainFrame.h.
  2. In CMainFrm.cpp, replace both occurrences of CMainWnd with CSVMainFrame. That class occurs twice in the file.
  3. Create as many views as necessary, adding navigational buttons or menu items to allow the user to move forward or backwards through the list of views. If you create CFormView classes, make sure the style to Child and Border to None.
  4. To move forward in a chain of views, call the OnSelectNextView() method as shown below. In this example, m_selection is a radio button where 0 means to hide the window and non-0 is destroy the current window:
void CSelViewDemoView::OnNextViewButton() 
{
    UpdateData();
    CMainFrame* pMFrame = (CMainFrame*)GetParentFrame();
    pMFrame->OnSelectNextView(RUNTIME_CLASS(CMySecondView), 
                m_selection == 0 ? AIT_HIDE_WINDOW : AIT_DESTROY_WINDOW);
}
  1. To navigate backward in the chain of view, call OnSelectPrevView(). In this example, m_selection means the same as in the previous example. If there is no previous view, then the current view does not change.
void CMySecondView::OnPreviousView() 
{
     UpdateData();
     CMainFrame* pMFrame = (CMainFrame*)GetParentFrame();
     pMFrame->OnSelectPrevView(m_selection == 0 ? AIT_HIDE_WINDOW : 
                                                  AIT_DESTROY_WINDOW);
    
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here