Click here to Skip to main content
15,880,796 members
Articles / Mobile Apps / Windows Mobile

A lightweight base class for MDI UI

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
22 Aug 2004CPOL2 min read 48.5K   428   20   6
The CMDIBase template provides multiple view UI support for WinCE WTL-based projects.

Sample Image - multiview.jpg Sample screenshot

Introduction

WTL is a very useful template library for Windows programming, especially for Pocket PC and SmartPhone (which do not even support MFC). But, when I implemented a multiview application on SmartPhone and Pocket PC, a block occurred. WTL cannot create a MDI project in WinCE. And, I tried to port a MDI project on the desktop; unfortunately, I failed. So, I decided to create a MDI support class myself, god bless me. It is not such difficult as what I thought initially.

I created a template class named CMDIBase. You can inherit it from your MainFrame class, like this:

#include "MDIBase.h"

class CMainFrame : public CFrameWindowImpl<CMainFrame>,
                   public CUpdateUI<CMainFrame>,
                   public CMessageFilter,
                   public CIdleHandler,
                   public CMDIBase<CMainFrame>

Then add a message chain in CMainFrame's message map:

CHAIN_MSG_MAP(CMDIBase<CMainFrame>)

and use functions in CMDIBase:

InitailToolBar
SwitchView
EnableUIItem

Use SwithView to change current view to next view you want to display, and change menu and toolbar. If you set the third parameter to TRUE, the OK button will show on the title bar, and you can handle the Command ID of IDOK of this button.

LRESULT OnView1(WORD /*wNotifyCode*/, WORD /*wID*/, 
     HWND /*hWndCtl*/, BOOL& /*bHandled*/)
 {
  //SwitchView(m_view,IDR_VIEW1);
  SwitchView(m_myview,IDR_VIEW1,TRUE);
  return 0;
 }

Use EnableUIItem to set menu item and toolbar item to Enable or Disable style. Like this:

LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, 
            HWND /*hWndCtl*/, BOOL& /*bHandled*/)
 {
  CAboutDlg dlg;
  dlg.DoModal();
  EnableUIItem(IDR_MAINFRAME,ID_APP_ABOUT);
  return 0;
 }

The first parameter of EnableUIItem is the resource ID of menubar, the second is the identity ID of both menu item and toolbar item.

Sample screenshot Sample screenshot

Description

This class is a WTL-based template class, and only for WinCE because it is not so useful if you can create a WTL MDI project on the desktop.

Note: CMDIBase must be used in a SDI WTL project.

The motivation of making this class is to add Multiple view UI support for WinCE WTL-based projects.

It provides some functions for changing the view and menubar or toolbar related to the view. You can update the status of a command item in the menubar or toolbar. The most important thing is that it provides a more reasonable way to handle messages in the right place. It's just like in a MFC MDI project, you can handle menu commands in the related view class; not like in a WTL MDI project, where you can hardly chain a message into a view and all command messages must be handled by the mainframe.

//#define _WINCE_SMARTPHONE

The define of _WINCE_SMARTPHONE in MDIBase.h is a key of changing CMDIBase for SmartPhone and will cut same function not supported on SmartPhone.

The following list shows the main functions in CMDIBase:

  • InitailToolBar: It just calls a create toolbar function and a move window function. If it does not call move window, the mainframe cannot be displayed correctly.
  • SwitchView: Switches to the view you want to show, and loads the related menu and toolbar. menuID and toolbarID must be uniform.
  • EnableUIItem: Sets the menu item and toolbar item to enable/disable.

CUIUpdate class does not work for these, but it can set the check state correctly. So, the setcheckstatus function is not added in CMDIBase.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
opening view with wild mind

Comments and Discussions

 
QuestionHow to dsiable to Menu item in Pocket PC application Pin
Y Mahi20-Sep-07 23:10
Y Mahi20-Sep-07 23:10 
GeneralSome remarks [modified] Pin
Vince Ricci2-May-07 4:20
Vince Ricci2-May-07 4:20 
GeneralRe: Some remarks Pin
fftz3-May-07 5:52
fftz3-May-07 5:52 
GeneralTHANK YOU!!! Pin
szurcher25-Jan-05 17:31
szurcher25-Jan-05 17:31 
Questionwhat about using on a smart phone? Pin
I_M_R23-Aug-04 9:14
I_M_R23-Aug-04 9:14 
AnswerRe: what about using on a smart phone? Pin
fftz23-Aug-04 15:21
fftz23-Aug-04 15:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.