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.
- Create a new MFC Document/View project, or use an existing project.
- Copy the two files SVMainFrame.cpp and SVMainFrame.h into the project directory and add them to the project.
- Open CMainFrm.h and replace
CFrameWnd
with CSFMainFrame
.
class CMainFrame : public CSVMainFrame
{
{
- In CMainFrm.h DELETE the
CCeCommandBar m_wndCommandBar
object because it is declared in CSVMainFrame.h.
- In CMainFrm.cpp, replace both occurrences of
CMainWnd
with CSVMainFrame
. That class occurs twice in the file.
- 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.
- 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);
}
- 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);
}