Click here to Skip to main content
14,031,046 members
Click here to Skip to main content

Stats

298.1K views
79K downloads
226 bookmarked
Posted 30 Dec 2005
Licenced CPOL

Form Designer

, 1 Aug 2009
Component for adding scriptable forms capabilities to an application.
MFCDemo.exe
CSDemo
App.ico
Bmp
ABottom.bmp
About.bmp
ALeft.bmp
ARight.bmp
ATop.bmp
AX.bmp
BringFront.bmp
Button.bmp
Center.bmp
Check.bmp
Combo.bmp
Copy.bmp
Cut.bmp
Delete.bmp
Down.bmp
Edit.bmp
Frame.bmp
Grid.bmp
GridSettings.bmp
HCenter.bmp
HScroll.bmp
HSL.bmp
HSpace.bmp
HSS.bmp
Left.bmp
List.bmp
New.bmp
Open.bmp
Paste.bmp
Picture.bmp
Preview.bmp
Progress.bmp
Props.bmp
Radio.bmp
Rectangle.bmp
Redo.bmp
Right.bmp
Save.bmp
SelAll.bmp
SelNone.bmp
SendBack.bmp
SL.bmp
Slider.bmp
Spin.bmp
SS.bmp
Tab.bmp
Text.bmp
Undo.bmp
Up.bmp
Validate.bmp
VCenter.bmp
VScroll.bmp
VSL.bmp
VSpace.bmp
VSS.bmp
Wand.bmp
CSDemo.suo
DaeDoe.bmp
MFCDemo
MFCDemo.dsp
MFCDemo.odl
MFCDemo.reg
res
DaeDoe.bmp
MFCDemo.ico
MFCDemoDoc.ico
Toolbar1.bmp
Toolbar2.bmp
Toolbar3.bmp
Wand.bmp
VBDemo
Bmp
ABottom.bmp
About.bmp
ALeft.bmp
ARight.bmp
ATop.bmp
AX.bmp
BringFront.bmp
Button.bmp
Center.bmp
Check.bmp
Combo.bmp
Copy.bmp
Cut.bmp
Delete.bmp
Down.bmp
Edit.bmp
Frame.bmp
Grid.bmp
GridSettings.bmp
HCenter.bmp
HScroll.bmp
HSL.bmp
HSpace.bmp
HSS.bmp
Left.bmp
List.bmp
New.bmp
Open.bmp
Paste.bmp
Picture.bmp
Preview.bmp
Progress.bmp
Props.bmp
Radio.bmp
Rectangle.bmp
Redo.bmp
Right.bmp
Save.bmp
SelAll.bmp
SelNone.bmp
SendBack.bmp
SL.bmp
Slider.bmp
Spin.bmp
SS.bmp
Tab.bmp
Text.bmp
Undo.bmp
Up.bmp
Validate.bmp
VCenter.bmp
VScroll.bmp
VSL.bmp
VSpace.bmp
VSS.bmp
Wand.bmp
DaeDoe.bmp
VBDemo.vbp
DDForms.chm
DDForms
Archive
FormEditorItems.rgs
vssver.scc
Constants.scr
DaeDoe.bmp
DDForms.def
DDForms.vcproj
DDForms.vcproj.vspscc
EventSinkPassThrough.rgs
FormEditor.bmp
FormEditor.rgs
FormEditorItemCollection.rgs
FormEditorItemDetails.rgs
FormViewer.bmp
FormViewer.rgs
FormViewerItemCollection.rgs
FormViewerItemDetails.rgs
mssccprj.scc
PropPageExtended.rgs
PropPageFormEditor.rgs
PropPageFormViewer.rgs
PropPageSimpleScriptEditor.rgs
SimpleScriptEditor.bmp
SimpleScriptEditor.rgs
vssver.scc
DDFormsTools
CodeMaxDriver
CodeMaxDriver.rgs
CodeMaxDriver.vcproj
CodeMaxDriver.vcproj.vspscc
CodeMaxDriverps.def
CodeMaxDriverPS.vcproj
CodeMaxDriverPS.vcproj.vspscc
mssccprj.scc
vssver.scc
CodeSenseDriver
CodeSenseDriver.rgs
CodeSenseDriver.vcproj
CodeSenseDriver.vcproj.vspscc
CodeSenseDriverps.def
CodeSenseDriverPS.vcproj
CodeSenseDriverPS.vcproj.vspscc
mssccprj.scc
vssver.scc
DDPropPageAll
DDPropPageAll.def
DDPropPageAll.vcproj
DDPropPageAll.vcproj.vspscc
mssccprj.scc
PropPageAll.rgs
vssver.scc
DDUnlock
DDUnlock.vcproj
DDUnlock.vcproj.vspscc
mssccprj.scc
vssver.scc
DDControlPack
DDButton.bmp
DDCheckBox.bmp
DDComboBox.bmp
DDControlPack.rgs
DDControlPack.vcproj
DDControlPack.vcproj.vspscc
DDHorzScrollBar.bmp
DDLabel.bmp
DDListBox.bmp
DDPicture.bmp
DDRadioButton.bmp
DDTextBox.bmp
DDVertScrollBar.bmp
mssccprj.scc
vssver.scc
Redistributables
Ansi
CodeMaxDriver.dll
CodeSenseDriver.dll
DDControlPack.dll
DDForms.dll
DDPropPageAll.dll
Unicode
CodeMaxDriver.dll
CodeSenseDriver.dll
DDControlPack.dll
DDForms.dll
DDPropPageAll.dll
// MFCDemoView.cpp : implementation of the CMFCDemoView class
//
// Author : David Shepherd
//			Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MFCDemo.h"

#include "MFCDemoDoc.h"
#include "MFCDemoView.h"

#include "Class1.h"
#include "Class2.h"

#include "GridSettingsDlg.h"
#include "InsertErrorDlg.h"
#include "PreviewDlg.h"
#include "ScriptErrorDlg.h"

#include "FormEditorItemCollection.h"
#include "Script.h"
#include "ViewableForm.h"

// define this if FM20 is available on the system
//#define FM20_AVAILABLE

#ifdef FM20_AVAILABLE
#pragma warning (disable : 4192)
#import "FM20.dll" raw_interfaces_only
#pragma warning (default : 4192)
#endif

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// displays the insert error dialog on error
#define SHOW_INSERT_ERROR(progid)	\
	if(Caught)						\
	{								\
		CInsertErrorDlg Dlg;		\
		Dlg.m_ProgId=(progid);		\
		(void)Dlg.DoModal();		\
	}

/////////////////////////////////////////////////////////////////////////////
// CMFCDemoView

IMPLEMENT_DYNCREATE(CMFCDemoView, CView)

BEGIN_MESSAGE_MAP(CMFCDemoView, CView)
	//{{AFX_MSG_MAP(CMFCDemoView)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
	ON_COMMAND(ID_NEW, OnNew)
	ON_UPDATE_COMMAND_UI(ID_NEW, OnUpdateNew)
	ON_COMMAND(ID_OPEN, OnOpen)
	ON_UPDATE_COMMAND_UI(ID_OPEN, OnUpdateOpen)
	ON_COMMAND(ID_SAVE, OnSave)
	ON_UPDATE_COMMAND_UI(ID_SAVE, OnUpdateSave)
	ON_COMMAND(ID_SAVE_AS, OnSaveAs)
	ON_UPDATE_COMMAND_UI(ID_SAVE_AS, OnUpdateSaveAs)
	ON_COMMAND(ID_CUT, OnCut)
	ON_UPDATE_COMMAND_UI(ID_CUT, OnUpdateCut)
	ON_COMMAND(ID_COPY, OnCopy)
	ON_UPDATE_COMMAND_UI(ID_COPY, OnUpdateCopy)
	ON_COMMAND(ID_PASTE, OnPaste)
	ON_UPDATE_COMMAND_UI(ID_PASTE, OnUpdatePaste)
	ON_COMMAND(ID_UNDO, OnUndo)
	ON_UPDATE_COMMAND_UI(ID_UNDO, OnUpdateUndo)
	ON_COMMAND(ID_REDO, OnRedo)
	ON_UPDATE_COMMAND_UI(ID_REDO, OnUpdateRedo)
	ON_COMMAND(ID_ABOUT, OnAbout)
	ON_UPDATE_COMMAND_UI(ID_ABOUT, OnUpdateAbout)
	ON_COMMAND(ID_FRAME, OnFrame)
	ON_UPDATE_COMMAND_UI(ID_FRAME, OnUpdateFrame)
	ON_COMMAND(ID_RECTANGLE, OnRectangle)
	ON_UPDATE_COMMAND_UI(ID_RECTANGLE, OnUpdateRectangle)
	ON_COMMAND(ID_PICTURE, OnPicture)
	ON_UPDATE_COMMAND_UI(ID_PICTURE, OnUpdatePicture)
	ON_COMMAND(ID_LABEL, OnLabel)
	ON_UPDATE_COMMAND_UI(ID_LABEL, OnUpdateLabel)
	ON_COMMAND(ID_BUTTON, OnButton)
	ON_UPDATE_COMMAND_UI(ID_BUTTON, OnUpdateButton)
	ON_COMMAND(ID_CHECK, OnCheck)
	ON_UPDATE_COMMAND_UI(ID_CHECK, OnUpdateCheck)
	ON_COMMAND(ID_RADIO, OnRadio)
	ON_UPDATE_COMMAND_UI(ID_RADIO, OnUpdateRadio)
	ON_COMMAND(ID_TEXT, OnText)
	ON_UPDATE_COMMAND_UI(ID_TEXT, OnUpdateText)
	ON_COMMAND(ID_COMBO, OnCombo)
	ON_UPDATE_COMMAND_UI(ID_COMBO, OnUpdateCombo)
	ON_COMMAND(ID_LIST, OnList)
	ON_UPDATE_COMMAND_UI(ID_LIST, OnUpdateList)
	ON_COMMAND(ID_HSCROLL, OnHScroll)
	ON_UPDATE_COMMAND_UI(ID_HSCROLL, OnUpdateHScroll)
	ON_COMMAND(ID_VSCROLL, OnVScroll)
	ON_UPDATE_COMMAND_UI(ID_VSCROLL, OnUpdateVScroll)
	ON_COMMAND(ID_SPIN, OnSpin)
	ON_UPDATE_COMMAND_UI(ID_SPIN, OnUpdateSpin)
	ON_COMMAND(ID_SLIDER, OnSlider)
	ON_UPDATE_COMMAND_UI(ID_SLIDER, OnUpdateSlider)
	ON_COMMAND(ID_PROGRESS, OnProgress)
	ON_UPDATE_COMMAND_UI(ID_PROGRESS, OnUpdateProgress)
	ON_COMMAND(ID_ACTIVEX, OnActivex)
	ON_UPDATE_COMMAND_UI(ID_ACTIVEX, OnUpdateActivex)
	ON_COMMAND(ID_DELETE, OnDelete)
	ON_UPDATE_COMMAND_UI(ID_DELETE, OnUpdateDelete)
	ON_COMMAND(ID_GRID, OnGrid)
	ON_UPDATE_COMMAND_UI(ID_GRID, OnUpdateGrid)
	ON_COMMAND(ID_GRID_SETTINGS, OnGridSettings)
	ON_UPDATE_COMMAND_UI(ID_GRID_SETTINGS, OnUpdateGridSettings)
	ON_COMMAND(ID_TAB, OnTab)
	ON_UPDATE_COMMAND_UI(ID_TAB, OnUpdateTab)
	ON_COMMAND(ID_SELECT_ALL, OnSelectAll)
	ON_UPDATE_COMMAND_UI(ID_SELECT_ALL, OnUpdateSelectAll)
	ON_COMMAND(ID_UNSELECT_ALL, OnUnselectAll)
	ON_UPDATE_COMMAND_UI(ID_UNSELECT_ALL, OnUpdateUnselectAll)
	ON_COMMAND(ID_PROPERTIES, OnProperties)
	ON_UPDATE_COMMAND_UI(ID_PROPERTIES, OnUpdateProperties)
	ON_COMMAND(ID_LEFT, OnLeft)
	ON_UPDATE_COMMAND_UI(ID_LEFT, OnUpdateLeft)
	ON_COMMAND(ID_RIGHT, OnRight)
	ON_UPDATE_COMMAND_UI(ID_RIGHT, OnUpdateRight)
	ON_COMMAND(ID_UP, OnUp)
	ON_UPDATE_COMMAND_UI(ID_UP, OnUpdateUp)
	ON_COMMAND(ID_DOWN, OnDown)
	ON_UPDATE_COMMAND_UI(ID_DOWN, OnUpdateDown)
	ON_COMMAND(ID_LAYOUT_SENDTOBACK, OnLayoutSendtoback)
	ON_UPDATE_COMMAND_UI(ID_LAYOUT_SENDTOBACK, OnUpdateLayoutSendtoback)
	ON_COMMAND(ID_LAYOUT_BRINGTOFRONT, OnLayoutBringtofront)
	ON_UPDATE_COMMAND_UI(ID_LAYOUT_BRINGTOFRONT, OnUpdateLayoutBringtofront)
	ON_COMMAND(ID_ALIGN_LEFT, OnAlignLeft)
	ON_UPDATE_COMMAND_UI(ID_ALIGN_LEFT, OnUpdateAlignLeft)
	ON_COMMAND(ID_ALIGN_RIGHT, OnAlignRight)
	ON_UPDATE_COMMAND_UI(ID_ALIGN_RIGHT, OnUpdateAlignRight)
	ON_COMMAND(ID_ALIGN_TOP, OnAlignTop)
	ON_UPDATE_COMMAND_UI(ID_ALIGN_TOP, OnUpdateAlignTop)
	ON_COMMAND(ID_ALIGN_BOTTOM, OnAlignBottom)
	ON_UPDATE_COMMAND_UI(ID_ALIGN_BOTTOM, OnUpdateAlignBottom)
	ON_COMMAND(ID_SPACE_HORZ, OnSpaceHorz)
	ON_UPDATE_COMMAND_UI(ID_SPACE_HORZ, OnUpdateSpaceHorz)
	ON_COMMAND(ID_SPACE_VERT, OnSpaceVert)
	ON_UPDATE_COMMAND_UI(ID_SPACE_VERT, OnUpdateSpaceVert)
	ON_COMMAND(ID_SIZE_LARGEST_WIDTH, OnSizeLargestWidth)
	ON_UPDATE_COMMAND_UI(ID_SIZE_LARGEST_WIDTH, OnUpdateSizeLargestWidth)
	ON_COMMAND(ID_SIZE_LARGEST_HEIGHT, OnSizeLargestHeight)
	ON_UPDATE_COMMAND_UI(ID_SIZE_LARGEST_HEIGHT, OnUpdateSizeLargestHeight)
	ON_COMMAND(ID_SIZE_LARGEST, OnSizeLargest)
	ON_UPDATE_COMMAND_UI(ID_SIZE_LARGEST, OnUpdateSizeLargest)
	ON_COMMAND(ID_SIZE_SMALLEST_WIDTH, OnSizeSmallestWidth)
	ON_UPDATE_COMMAND_UI(ID_SIZE_SMALLEST_WIDTH, OnUpdateSizeSmallestWidth)
	ON_COMMAND(ID_SIZE_SMALLEST_HEIGHT, OnSizeSmallestHeight)
	ON_UPDATE_COMMAND_UI(ID_SIZE_SMALLEST_HEIGHT, OnUpdateSizeSmallestHeight)
	ON_COMMAND(ID_SIZE_SMALLEST, OnSizeSmallest)
	ON_UPDATE_COMMAND_UI(ID_SIZE_SMALLEST, OnUpdateSizeSmallest)
	ON_COMMAND(ID_CENTER_HORZ, OnCenterHorz)
	ON_UPDATE_COMMAND_UI(ID_CENTER_HORZ, OnUpdateCenterHorz)
	ON_COMMAND(ID_CENTER_VERT, OnCenterVert)
	ON_UPDATE_COMMAND_UI(ID_CENTER_VERT, OnUpdateCenterVert)
	ON_COMMAND(ID_CENTER, OnCenter)
	ON_UPDATE_COMMAND_UI(ID_CENTER, OnUpdateCenter)
	ON_COMMAND(ID_VALIDATE_SCRIPT, OnValidateScript)
	ON_UPDATE_COMMAND_UI(ID_VALIDATE_SCRIPT, OnUpdateValidateScript)
	ON_COMMAND(ID_PREVIEW_AUTO_SIZE, OnPreviewAutoSize)
	ON_UPDATE_COMMAND_UI(ID_PREVIEW_AUTO_SIZE, OnUpdatePreviewAutoSize)
	ON_COMMAND(ID_PREVIEW, OnPreview)
	ON_UPDATE_COMMAND_UI(ID_PREVIEW, OnUpdatePreview)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCDemoView construction/destruction

CMFCDemoView::CMFCDemoView() :
	m_hAccel(NULL),
	m_FES_Busy(FALSE),
	m_FES_Modified(FALSE),
	m_FES_CanPaste(FALSE),
	m_FES_CanUndo(FALSE),
	m_FES_CanRedo(FALSE),
	m_FES_ItemCount(0),
	m_FES_SelectedItemCount(0)
{
	//{{AFX_DATA_INIT(CMFCDemoView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here
}

CMFCDemoView::~CMFCDemoView()
{
}

CString CMFCDemoView::GetTempFileName()
{
	// create the temporary file name
	const DWORD BufLen=2048;
	TCHAR Buf[BufLen]=_T("");
	DWORD Count=GetTempPath(BufLen,Buf);
	if(Count==0 || Count > BufLen)
	{
		throw CError();
	}
	CString TempFileName=Buf;
	TempFileName+=_T("MFCDemo.tmp");

	return TempFileName;
}

BOOL CMFCDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDemoView drawing

void CMFCDemoView::OnDraw(CDC* pDC)
{
	CMFCDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDemoView printing

BOOL CMFCDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMFCDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMFCDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CMFCDemoView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CMFCDemoView diagnostics

#ifdef _DEBUG
void CMFCDemoView::AssertValid() const
{
	CView::AssertValid();
}

void CMFCDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCDemoDoc* CMFCDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCDemoDoc)));
	return (CMFCDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMFCDemoView message handlers

BEGIN_EVENTSINK_MAP(CMFCDemoView, CView)
    //{{AFX_EVENTSINK_MAP(CMFCDemoView)
	ON_EVENT(CMFCDemoView, IDC_FORMEDITOR, 1 /* StateChanged */, OnStateChangedFormeditor, VTS_BOOL VTS_BOOL VTS_BOOL VTS_BOOL VTS_BOOL VTS_I4 VTS_I4)
	ON_EVENT(CMFCDemoView, IDC_FORMEDITOR, 2 /* EditExistingEventHandler */, OnEditExistingEventHandlerFormeditor, VTS_NONE)
	ON_EVENT(CMFCDemoView, IDC_FORMEDITOR, 4 /* EditScriptError */, OnEditScriptErrorFormeditor, VTS_BSTR VTS_I4 VTS_BSTR)
	ON_EVENT(CMFCDemoView, IDC_SIMPLESCRIPTEDITOR, 1 /* ModifiedStateChanged */, OnModifiedStateChangedSimplescripteditor, VTS_BOOL)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CMFCDemoView::OnStateChangedFormeditor(BOOL Busy, BOOL Modified, BOOL CanPaste, BOOL CanUndo, BOOL CanRedo, long ItemCount, long SelectedItemCount) 
{
BLOCK_BEGIN
	// save the form editor state
	m_FES_Busy=Busy;
	m_FES_Modified=Modified;
	m_FES_CanPaste=CanPaste;
	m_FES_CanUndo=CanUndo;
	m_FES_CanRedo=CanRedo;
	m_FES_ItemCount=ItemCount;
	m_FES_SelectedItemCount=SelectedItemCount;

	// set the modified flag
	if(Modified)
	{
		CMFCDemoDoc *pDoc=GetDocument();
		ASSERT(pDoc!=NULL);
		pDoc->SetModifiedFlag();
	}
BLOCK_END
}

void CMFCDemoView::OnEditExistingEventHandlerFormeditor() 
{
BLOCK_BEGIN
	// select the script editor tab
	(void)m_Tab.SetCurSel(1);
	// simulate a tab change notification
	// todo : set the parameters correctly when required
	NMHDR Dummy1;
	LRESULT Dummy2;
	OnSelchangeTab(&Dummy1,&Dummy2);
BLOCK_END
}

void CMFCDemoView::OnEditScriptErrorFormeditor(LPCTSTR Source, long Number, LPCTSTR Description) 
{
BLOCK_BEGIN
	// select the script editor tab
	(void)m_Tab.SetCurSel(1);
	// simulate a tab change notification
	// todo : set the parameters correctly when required
	NMHDR Dummy1;
	LRESULT Dummy2;
	OnSelchangeTab(&Dummy1,&Dummy2);

	// show the error details
	CWnd *pFocusWnd=GetFocus();
	CScriptErrorDlg Dlg;
	Dlg.m_ErrorDetails.Format(
		_T("Error Details\r\n\r\n")
		_T("Source : %s\r\n")
		_T("Number : %d - %08X Hex\r\n")
		_T("Description : %s"),Source,Number,Number,Description);
	(void)Dlg.DoModal();
	if(pFocusWnd!=NULL)
	{
		(void)pFocusWnd->SetFocus();
	}
BLOCK_END
}

void CMFCDemoView::OnModifiedStateChangedSimplescripteditor(BOOL Modified) 
{
BLOCK_BEGIN
	// set the modified flag
	if(Modified)
	{
		CMFCDemoDoc *pDoc=GetDocument();
		ASSERT(pDoc!=NULL);
		pDoc->SetModifiedFlag();
	}
BLOCK_END
}

void CMFCDemoView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) 
{
BLOCK_BEGIN
	// show the relevant tab component
	switch(m_Tab.GetCurSel())
	{
	// form editor
	case 0:
		(void)m_FormEditor.SetWindowPos(
			&wndTop,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		(void)m_FormEditor.SetFocus();
		break;
	// script editor
	case 1:
		(void)m_SimpleScriptEditor.SetWindowPos(
			&wndTop,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		(void)m_SimpleScriptEditor.SetFocus();
		break;
	// form viewer
	case 2:
		(void)m_FormViewer.SetWindowPos(
			&wndTop,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		(void)m_FormViewer.SetFocus();
		// validate the script
		if(m_FormEditor.ValidateScript()==FALSE)
		{
			throw CError();
		}
		// save the form
		m_FormEditor.SaveToFile(GetTempFileName());
		// load the form into the viewer
		m_FormViewer.LoadFromFile(GetTempFileName());
		// set the viewer background color (opional but looks better)
		m_FormViewer.SetBackColor(m_FormViewer.GetForm().GetBackColor());
		break;
	// unknown
	default:
		ASSERT(FALSE);
		break;
	}
	*pResult=0;
BLOCK_END
}

void CMFCDemoView::OnNew() 
{
BLOCK_BEGIN
	// delegate to the document
	CWnd *pMainWnd=AfxGetMainWnd();
	ASSERT(pMainWnd!=NULL);
	(void)pMainWnd->SendMessage(WM_COMMAND,ID_FILE_NEW);
BLOCK_END
}

void CMFCDemoView::OnUpdateNew(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnOpen() 
{
BLOCK_BEGIN
	// delegate to the document
	CWnd *pMainWnd=AfxGetMainWnd();
	ASSERT(pMainWnd!=NULL);
	(void)pMainWnd->SendMessage(WM_COMMAND,ID_FILE_OPEN);
BLOCK_END
}

void CMFCDemoView::OnUpdateOpen(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnSave() 
{
BLOCK_BEGIN
	// delegate to the document
	CWnd *pMainWnd=AfxGetMainWnd();
	ASSERT(pMainWnd!=NULL);
	(void)pMainWnd->SendMessage(WM_COMMAND,ID_FILE_SAVE);
BLOCK_END
}

void CMFCDemoView::OnUpdateSave(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnSaveAs() 
{
BLOCK_BEGIN
	// delegate to the document
	CWnd *pMainWnd=AfxGetMainWnd();
	ASSERT(pMainWnd!=NULL);
	(void)pMainWnd->SendMessage(WM_COMMAND,ID_FILE_SAVE_AS);
BLOCK_END
}

void CMFCDemoView::OnUpdateSaveAs(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnCut() 
{
BLOCK_BEGIN
	// cut selected items to the clipboard
	m_FormEditor.Cut();
BLOCK_END
}

void CMFCDemoView::OnUpdateCut(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnCopy() 
{
BLOCK_BEGIN
	// copy selected items to the clipboard
	m_FormEditor.Copy();
BLOCK_END
}

void CMFCDemoView::OnUpdateCopy(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnPaste() 
{
BLOCK_BEGIN
	// paste items from the clipboard into the form
	m_FormEditor.Paste();
BLOCK_END
}

void CMFCDemoView::OnUpdatePaste(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable(m_FES_CanPaste);
BLOCK_END
}

void CMFCDemoView::OnUndo() 
{
BLOCK_BEGIN
	// undo the last operation
	m_FormEditor.Undo();
BLOCK_END
}

void CMFCDemoView::OnUpdateUndo(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable(m_FES_CanUndo);
BLOCK_END
}

void CMFCDemoView::OnRedo() 
{
BLOCK_BEGIN
	// redo the last undo
	m_FormEditor.Redo();
BLOCK_END
}

void CMFCDemoView::OnUpdateRedo(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable(m_FES_CanRedo);
BLOCK_END
}

void CMFCDemoView::OnAbout() 
{
BLOCK_BEGIN
	// delegate to the app
	CWnd *pMainWnd=AfxGetMainWnd();
	ASSERT(pMainWnd!=NULL);
	(void)pMainWnd->SendMessage(WM_COMMAND,ID_APP_ABOUT);
BLOCK_END
}

void CMFCDemoView::OnUpdateAbout(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnFrame() 
{
BLOCK_BEGIN
	// insert a frame
	CComPtr<IDispatch> spDispatch;
	spDispatch.Attach(m_FormEditor.Insert(_T("DDControlPack.DDLabel")));
	// manipulate the new item
	COleDispatchDriver DispatchDriver(spDispatch,FALSE);
	DispatchDriver.SetProperty(
		DISPID_BORDERSTYLE,VT_I4,3/*ddcpBorderStyleEtched*/);
	DispatchDriver.SetProperty(
		DISPID_FORECOLOR,VT_I4,m_FormEditor.GetFormForeColor());
	DispatchDriver.SetProperty(
		DISPID_BACKCOLOR,VT_I4,m_FormEditor.GetFormBackColor());
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDLabel"));
}

void CMFCDemoView::OnUpdateFrame(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnRectangle() 
{
BLOCK_BEGIN
	// insert a rectangle
	CComPtr<IDispatch> spDispatch;
	spDispatch.Attach(m_FormEditor.Insert(_T("DDControlPack.DDLabel")));
	// manipulate the new item
	COleDispatchDriver DispatchDriver(spDispatch,FALSE);
	DispatchDriver.SetProperty(
		DISPID_BORDERSTYLE,VT_I4,0/*ddcpBorderStyleNone*/);
	DispatchDriver.SetProperty(
		DISPID_FORECOLOR,VT_I4,m_FormEditor.GetFormForeColor());
	DispatchDriver.SetProperty(
		DISPID_BACKCOLOR,VT_I4,m_FormEditor.GetFormForeColor());
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDLabel"));
}

void CMFCDemoView::OnUpdateRectangle(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnPicture() 
{
BLOCK_BEGIN
	// insert a picture
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDPicture")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDPicture"));
}

void CMFCDemoView::OnUpdatePicture(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnLabel() 
{
BLOCK_BEGIN
	// insert a label
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDLabel")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDLabel"));
}

void CMFCDemoView::OnUpdateLabel(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnButton() 
{
BLOCK_BEGIN
	// insert a command button
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDButton")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDButton"));
}

void CMFCDemoView::OnUpdateButton(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnCheck() 
{
BLOCK_BEGIN
	// inset a check box
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDCheckBox")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDCheckBox"));
}

void CMFCDemoView::OnUpdateCheck(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnRadio() 
{
BLOCK_BEGIN
	// insert a radio button
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDRadioButton")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDRadioButton"));
}

void CMFCDemoView::OnUpdateRadio(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnText() 
{
BLOCK_BEGIN
	// inset a text box
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDTextBox")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDTextBox"));
}

void CMFCDemoView::OnUpdateText(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnCombo() 
{
BLOCK_BEGIN
	// insert a combo box
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDComboBox")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDComboBox"));
}

void CMFCDemoView::OnUpdateCombo(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnList() 
{
BLOCK_BEGIN
	// insert a list box
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDListBox")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDListBox"));
}

void CMFCDemoView::OnUpdateList(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnHScroll() 
{
BLOCK_BEGIN
	// insert a horizontal scroll bar
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDHorzScrollBar")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDHorzScrollBar"));
}

void CMFCDemoView::OnUpdateHScroll(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnVScroll() 
{
BLOCK_BEGIN
	// insert a vertical scroll bar
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("DDControlPack.DDVertScrollBar")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : DDControlPack.DDVertScrollBar"));
}

void CMFCDemoView::OnUpdateVScroll(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnSpin() 
{
BLOCK_BEGIN
	// insert a spin control
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("MSComCtl2.UpDown")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : MSComCtl2.UpDown"));
}

void CMFCDemoView::OnUpdateSpin(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnSlider() 
{
BLOCK_BEGIN
	// insert a slider
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("MSComCtlLib.Slider")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : MSComCtlLib.Slider"));
}

void CMFCDemoView::OnUpdateSlider(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnProgress() 
{
BLOCK_BEGIN
	// insert a progress bar
	CComPtr<IDispatch>().Attach(m_FormEditor.Insert(_T("MSComCtlLib.ProgCtrl")));
BLOCK_END
	SHOW_INSERT_ERROR(_T("ProgID : MSComCtlLib.ProgCtrl"));
}

void CMFCDemoView::OnUpdateProgress(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnActivex() 
{
	CString ProgId;
BLOCK_BEGIN
	// insert an activex control from a list of controls installed on the system
	ProgId=m_FormEditor.ShowInsertDialog();
	if(ProgId.GetLength())
	{
		CComPtr<IDispatch>().Attach(m_FormEditor.Insert(ProgId));
	}
BLOCK_END
	SHOW_INSERT_ERROR(CString(_T("ProgID : ")+ProgId));
}

void CMFCDemoView::OnUpdateActivex(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnDelete() 
{
BLOCK_BEGIN
	// delete selected items
	m_FormEditor.Delete();
BLOCK_END
}

void CMFCDemoView::OnUpdateDelete(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnGrid() 
{
BLOCK_BEGIN
	// toggle the grid
	m_FormEditor.SetGridVisible(
		m_FormEditor.GetGridVisible() ? FALSE : TRUE);
BLOCK_END
}

void CMFCDemoView::OnUpdateGrid(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnGridSettings() 
{
BLOCK_BEGIN
	// show the grid settings dialog
	CGridSettingsDlg Dlg;
	Dlg.m_Width=m_FormEditor.GetGridWidth();
	Dlg.m_Height=m_FormEditor.GetGridHeight();
	if(Dlg.DoModal()==IDOK)
	{
		m_FormEditor.SetGridWidth(Dlg.m_Width);
		m_FormEditor.SetGridHeight(Dlg.m_Height);
	}
BLOCK_END
}

void CMFCDemoView::OnUpdateGridSettings(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnTab() 
{
BLOCK_BEGIN
	// switch the form editor into tab ordering mode
	m_FormEditor.SetTabOrder();
BLOCK_END
}

void CMFCDemoView::OnUpdateTab(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnSelectAll() 
{
BLOCK_BEGIN
	// select all items
	m_FormEditor.SelectAll();
BLOCK_END
}

void CMFCDemoView::OnUpdateSelectAll(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnUnselectAll() 
{
BLOCK_BEGIN
	// unselect all items
	m_FormEditor.SelectNone();
BLOCK_END
}

void CMFCDemoView::OnUpdateUnselectAll(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnProperties() 
{
BLOCK_BEGIN
	// show property pages for the current selection
	m_FormEditor.Properties();
BLOCK_END
}

void CMFCDemoView::OnUpdateProperties(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount <= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnLeft() 
{
BLOCK_BEGIN
	// move selected items left by a single pixel
	m_FormEditor.MoveLeft();
BLOCK_END
}

void CMFCDemoView::OnUpdateLeft(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnRight() 
{
BLOCK_BEGIN
	// move selected items right by a single pixel
	m_FormEditor.MoveRight();
BLOCK_END
}

void CMFCDemoView::OnUpdateRight(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnUp() 
{
BLOCK_BEGIN
	// move selected items up by a single pixel
	m_FormEditor.MoveUp();
BLOCK_END
}

void CMFCDemoView::OnUpdateUp(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnDown() 
{
BLOCK_BEGIN
	// move selected items down by a single pixel
	m_FormEditor.MoveDown();
BLOCK_END
}

void CMFCDemoView::OnUpdateDown(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnLayoutSendtoback() 
{
BLOCK_BEGIN
	// move selected items to the back of all other items
	m_FormEditor.SendToBack();
BLOCK_END
}

void CMFCDemoView::OnUpdateLayoutSendtoback(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	// at least 1 item must be selected but not all of them
	if(m_FES_SelectedItemCount > 0 && m_FES_SelectedItemCount!=m_FES_ItemCount)
	{
		pCmdUI->Enable(TRUE);
	}
	else
	{
		pCmdUI->Enable(FALSE);
	}
BLOCK_END
}

void CMFCDemoView::OnLayoutBringtofront() 
{
BLOCK_BEGIN
	// bring selected items to the front of all other items
	m_FormEditor.BringToFront();
BLOCK_END
}

void CMFCDemoView::OnUpdateLayoutBringtofront(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	// at least 1 item must be selected but not all of them
	if(m_FES_SelectedItemCount > 0 && m_FES_SelectedItemCount!=m_FES_ItemCount)
	{
		pCmdUI->Enable(TRUE);
	}
	else
	{
		pCmdUI->Enable(FALSE);
	}
BLOCK_END
}

void CMFCDemoView::OnAlignLeft() 
{
BLOCK_BEGIN
	// align selected items to the left most
	m_FormEditor.AlignLeft();
BLOCK_END
}

void CMFCDemoView::OnUpdateAlignLeft(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnAlignRight() 
{
BLOCK_BEGIN
	// align selected items to the right most
	m_FormEditor.AlignRight();
BLOCK_END
}

void CMFCDemoView::OnUpdateAlignRight(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnAlignTop() 
{
BLOCK_BEGIN
	// align selected items to the top most
	m_FormEditor.AlignTop();
BLOCK_END
}

void CMFCDemoView::OnUpdateAlignTop(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnAlignBottom() 
{
BLOCK_BEGIN
	// align selected items to the bottom most
	m_FormEditor.AlignBottom();
BLOCK_END
}

void CMFCDemoView::OnUpdateAlignBottom(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSpaceHorz() 
{
BLOCK_BEGIN
	// space selected items horizontally
	m_FormEditor.SpaceHorizontally();
BLOCK_END
}

void CMFCDemoView::OnUpdateSpaceHorz(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 3) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSpaceVert() 
{
BLOCK_BEGIN
	// space selected items vertically
	m_FormEditor.SpaceVertically();
BLOCK_END
}

void CMFCDemoView::OnUpdateSpaceVert(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 3) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSizeLargestWidth() 
{
BLOCK_BEGIN
	// size the width of selected items to match the largest
	m_FormEditor.SizeWidthToLargest();
BLOCK_END
}

void CMFCDemoView::OnUpdateSizeLargestWidth(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSizeLargestHeight() 
{
BLOCK_BEGIN
	// size the height of selected items to match the largest
	m_FormEditor.SizeHeightToLargest();
BLOCK_END
}

void CMFCDemoView::OnUpdateSizeLargestHeight(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSizeLargest() 
{
BLOCK_BEGIN
	// size the width and height of selected items to match the largest
	m_FormEditor.SizeToLargest();
BLOCK_END
}

void CMFCDemoView::OnUpdateSizeLargest(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSizeSmallestWidth() 
{
BLOCK_BEGIN
	// size the width of selected items to match the smallest
	m_FormEditor.SizeWidthToSmallest();
BLOCK_END
}

void CMFCDemoView::OnUpdateSizeSmallestWidth(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSizeSmallestHeight() 
{
BLOCK_BEGIN
	// size the height of selected items to match the smallest
	m_FormEditor.SizeHeightToSmallest();
BLOCK_END
}

void CMFCDemoView::OnUpdateSizeSmallestHeight(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnSizeSmallest() 
{
BLOCK_BEGIN
	// size the width and height of selected items to match the smallest
	m_FormEditor.SizeToSmallest();
BLOCK_END
}

void CMFCDemoView::OnUpdateSizeSmallest(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 2) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnCenterHorz() 
{
BLOCK_BEGIN
	// align selected items to the form horizontal center
	m_FormEditor.FormAlignHCenter();
BLOCK_END
}

void CMFCDemoView::OnUpdateCenterHorz(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnCenterVert() 
{
BLOCK_BEGIN
	// align selected items to the form vertical center
	m_FormEditor.FormAlignVCenter();
BLOCK_END
}

void CMFCDemoView::OnUpdateCenterVert(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnCenter() 
{
BLOCK_BEGIN
	// align selected items to the form horizontal and vertical center
	m_FormEditor.FormAlignBoth();
BLOCK_END
}

void CMFCDemoView::OnUpdateCenter(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
	pCmdUI->Enable((m_FES_SelectedItemCount >= 1) ? TRUE : FALSE);
BLOCK_END
}

void CMFCDemoView::OnValidateScript() 
{
BLOCK_BEGIN
	// check the script for errors
	if(m_FormEditor.ValidateScript())
	{
		(void)AfxMessageBox(
			_T("The script does not contain any errors."),MB_ICONINFORMATION);
	}
BLOCK_END
}

void CMFCDemoView::OnUpdateValidateScript(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnPreviewAutoSize() 
{
BLOCK_BEGIN
	// validate the script
	if(m_FormEditor.ValidateScript()==FALSE)
	{
		throw CError();
	}
	// create the preview dialog
	CPreviewDlg Dlg;
	Dlg.m_AutoSizing=TRUE;
	Dlg.m_FileName=GetTempFileName();
	// expose objects - see OnInitialUpdate() for more details
	// class1
	CExposedObjectInfo ExposedObjectInfo;
	ExposedObjectInfo.m_Name=_T("Message");
	ExposedObjectInfo.m_spDispatch=m_spClass1;
	(void)Dlg.m_ExposedObjectInfoArray.Add(ExposedObjectInfo);
	// class2
	ExposedObjectInfo.m_Name=_T("YetAnotherObject");
	ExposedObjectInfo.m_spDispatch=m_spClass2;
	(void)Dlg.m_ExposedObjectInfoArray.Add(ExposedObjectInfo);
	// save the form
	m_FormEditor.SaveToFile(GetTempFileName());
	// show the preview
	(void)Dlg.DoModal();
BLOCK_END
}

void CMFCDemoView::OnUpdatePreviewAutoSize(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

void CMFCDemoView::OnPreview() 
{
BLOCK_BEGIN
	// validate the script
	if(m_FormEditor.ValidateScript()==FALSE)
	{
		throw CError();
	}
	// create the preview dialog
	CPreviewDlg Dlg;
	Dlg.m_AutoSizing=FALSE;
	Dlg.m_FileName=GetTempFileName();
	// expose objects - see OnInitialUpdate() for more details
	// class1
	CExposedObjectInfo ExposedObjectInfo;
	ExposedObjectInfo.m_Name=_T("Message");
	ExposedObjectInfo.m_spDispatch=m_spClass1;
	(void)Dlg.m_ExposedObjectInfoArray.Add(ExposedObjectInfo);
	// class2
	ExposedObjectInfo.m_Name=_T("YetAnotherObject");
	ExposedObjectInfo.m_spDispatch=m_spClass2;
	(void)Dlg.m_ExposedObjectInfoArray.Add(ExposedObjectInfo);
	// save the form
	m_FormEditor.SaveToFile(GetTempFileName());
	// show the preview
	(void)Dlg.DoModal();
BLOCK_END
}

void CMFCDemoView::OnUpdatePreview(CCmdUI* pCmdUI) 
{
BLOCK_BEGIN
BLOCK_END
}

int CMFCDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
BLOCK_BEGIN
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// create the tab control
	if(m_Tab.Create(
		WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,IDC_TAB)==FALSE)
	{
		throw CError();
	}
	// set the font
	CFont *pFont=CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
	if(pFont==NULL)
	{
		throw CError();
	}
	m_Tab.SetFont(pFont);
	// create the tabs
	if(m_Tab.InsertItem(0,_T("Form Editor"))==-1)
	{
		throw CError();
	}
	if(m_Tab.InsertItem(1,_T("Script Editor"))==-1)
	{
		throw CError();
	}
	if(m_Tab.InsertItem(2,_T("Form Viewer"))==-1)
	{
		throw CError();
	}
	// create the form editor
	if(m_FormEditor.Create(_T(""),
		WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,IDC_FORMEDITOR)==FALSE)
	{
		throw CError();
	}
	// create the form viewer
	if(m_FormViewer.Create(_T(""),
		WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,IDC_FORMVIEWER)==FALSE)
	{
		throw CError();
	}
	// create the script editor
	if(m_SimpleScriptEditor.Create(_T(""),
		WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,IDC_SIMPLESCRIPTEDITOR)==FALSE)
	{
		throw CError();
	}
	// set the font
	FONTDESC FontDesc;
	FontDesc.cbSizeofstruct=sizeof(FONTDESC);
	FontDesc.lpstrName=L"Courier";
	CURRENCY cy;
	cy.int64=10*10000;
	FontDesc.cySize=cy;
	FontDesc.sWeight=FW_NORMAL;
	FontDesc.sCharset=DEFAULT_CHARSET;
	FontDesc.fItalic=FALSE;
	FontDesc.fUnderline=FALSE;
	FontDesc.fStrikethrough=FALSE;
	CComPtr<IFontDisp> spFontDisp;
	if(!SUCCEEDED(OleCreateFontIndirect(
		&FontDesc,IID_IFontDisp,(void**)&spFontDisp)))
	{
		throw CError();
	}
	m_SimpleScriptEditor.SetFont(spFontDisp);

	// connect the script editor to the script
	CScript Script=m_FormEditor.GetScript();
	Script.SetEditor(m_SimpleScriptEditor.GetControlUnknown());

	// load the application accelerators
	m_hAccel=LoadAccelerators(AfxGetResourceHandle(),
		MAKEINTRESOURCE(IDR_MAINFRAME));
	if(m_hAccel==NULL)
	{
		throw CError();
	}

	// create an instance of "Class1"
	CRuntimeClass *pRuntimeClass=RUNTIME_CLASS(CClass1);
	ASSERT(pRuntimeClass!=NULL);
	CClass1 *pClass1=DYNAMIC_DOWNCAST(CClass1,pRuntimeClass->CreateObject());
	ASSERT(pClass1!=NULL);
	m_spClass1.Attach(pClass1->GetIDispatch(FALSE));
	ASSERT(m_spClass1!=NULL);

	// create an instance of "Class2"
	pRuntimeClass=RUNTIME_CLASS(CClass2);
	ASSERT(pRuntimeClass!=NULL);
	CClass2 *pClass2=DYNAMIC_DOWNCAST(CClass2,pRuntimeClass->CreateObject());
	ASSERT(pClass2!=NULL);
	m_spClass2.Attach(pClass2->GetIDispatch(FALSE));
	ASSERT(m_spClass2!=NULL);

	// expose an instance of "Class1"
    // "Message" is the name by which the form editor will reference the object
	m_FormEditor.Expose(_T("Message"),m_spClass1);
	// expose an instance of "Class2"
	// "YetAnotherObject" is the name by which the form editor will reference the object
	m_FormEditor.Expose(_T("YetAnotherObject"),m_spClass2);

	// the same is required for the form viewer
    m_FormViewer.Expose(_T("Message"),m_spClass1);
    m_FormViewer.Expose(_T("YetAnotherObject"),m_spClass2);

	// the form editor is initially active
	if(m_FormEditor.SetWindowPos(&wndTop,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE)==FALSE)
	{
		throw CError();
	}

	// refresh the state
    // this forces a "StateChanged" event to be fired
	m_FormEditor.RefreshState();
    // this forces a "ModifiedStateChanged" event to be fired
    m_SimpleScriptEditor.RefreshModifiedState();
BLOCK_END
	return Caught ? -1 : 0;
}

void CMFCDemoView::OnSize(UINT nType, int cx, int cy) 
{
BLOCK_BEGIN
	CView::OnSize(nType, cx, cy);

	// size the tab control
	(void)m_Tab.SetWindowPos(NULL,0,0,cx,cy,SWP_NOZORDER);
	// size all tab components
	CRect Rect(0,0,cx,cy);
	m_Tab.AdjustRect(FALSE,Rect);
	Rect.InflateRect(-4,-4);	// allow for a decent sized border
	// form editor
	(void)m_FormEditor.SetWindowPos(NULL,
		Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_NOZORDER);
	// form viewer
	(void)m_FormViewer.SetWindowPos(NULL,
		Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_NOZORDER);
	// script editor
	(void)m_SimpleScriptEditor.SetWindowPos(NULL,
		Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_NOZORDER);
BLOCK_END
}

BOOL CMFCDemoView::OnEraseBkgnd(CDC* pDC) 
{
	// to prevent flicker do not erase the background
	return TRUE;
}

BOOL CMFCDemoView::PreTranslateMessage(MSG* pMsg) 
{
BLOCK_BEGIN
	// this section of code is required to work around MFC problems
	// when hosting DaeDoe Forms

	// ignore none keyboard messages
	if(pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST)
	{
		return CView::PreTranslateMessage(pMsg);
	}
	// obtain a pointer to the message target window
	CWnd *pWndMsg=FromHandle(pMsg->hwnd);
	if(pWndMsg==NULL)
	{
		return CView::PreTranslateMessage(pMsg);
	}
	// determine which component the target window belongs to
	CComPtr<IUnknown> spUnknown;
	if(IsWindow(m_FormEditor))			// form editor
	{
		if(*pWndMsg==m_FormEditor || 
			m_FormEditor.IsChild(pWndMsg))
		{
			spUnknown=m_FormEditor.GetControlUnknown();
		}
	}
	if(IsWindow(m_SimpleScriptEditor))	// script editor
	{
		if(*pWndMsg==m_SimpleScriptEditor || 
			m_SimpleScriptEditor.IsChild(pWndMsg))
		{
			spUnknown=m_SimpleScriptEditor.GetControlUnknown();
		}
	}
	if(IsWindow(m_FormViewer))			// form viewer
	{
		if(*pWndMsg==m_FormViewer || 
			m_FormViewer.IsChild(pWndMsg))
		{
			spUnknown=m_FormViewer.GetControlUnknown();
		}
	}
	// if we need to handle the message
	if(spUnknown!=NULL)
	{
		// allow tooltip messages to be filtered
		if(CWnd::PreTranslateMessage(pMsg))
		{
			return TRUE;	// message handled
		}
		// give the component chance to translate accelerators
		CComQIPtr<IOleInPlaceActiveObject> spOleInPlaceActiveObject(spUnknown);
		if(spOleInPlaceActiveObject!=NULL &&
			spOleInPlaceActiveObject->TranslateAccelerator(pMsg)!=S_FALSE)
		{
			return TRUE;	// message handled
		}
		// give the host chance to translate accelerators
		if(TranslateAccelerator(*AfxGetMainWnd(),m_hAccel,pMsg)!=0)
		{
			return TRUE;	// message handled
		}
		// let the component consume all input
		(void)TranslateMessage(pMsg);
		(void)pWndMsg->SendMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
		return TRUE;		// message handled
	}
	return CView::PreTranslateMessage(pMsg);
BLOCK_END
	return FALSE;	// message not handled
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

DaveShep
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190419.4 | Last Updated 1 Aug 2009
Article Copyright 2005 by DaveShep
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid