MarkupApp.cpp
资源名称:CMarkup.rar [点击查看]
上传用户:hawkcdm
上传日期:2013-02-10
资源大小:411k
文件大小:9k
源码类别:
xml/soap/webservice
开发平台:
Visual C++
- // MarkupApp.cpp : Defines the class behaviors for the application.
- //
- // Markup Release 6.1 Lite
- // Copyright (C) 1999-2001 First Objective Software, Inc. All rights reserved
- // This entire notice must be retained in this source code
- // Redistributing this source code requires written permission
- // This software is provided "as is", with no warranty.
- // Latest fixes enhancements and documentation at www.firstobject.com
- #include "stdafx.h"
- #include "MarkupApp.h"
- #include "MainFrm.h"
- #include "ChildFrm.h"
- #include "MarkupDoc.h"
- #include "MarkupView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMarkupApp
- BEGIN_MESSAGE_MAP(CMarkupApp, CWinApp)
- //{{AFX_MSG_MAP(CMarkupApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_APP_TEST, OnAppTest)
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- // Standard print setup command
- ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMarkupApp construction
- CMarkupApp::CMarkupApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CMarkupApp object
- CMarkupApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CMarkupApp initialization
- BOOL CMarkupApp::InitInstance()
- {
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- // Change the registry key under which our settings are stored.
- // TODO: You should modify this string to be something appropriate
- // such as the name of your company or organization.
- SetRegistryKey(_T("Local AppWizard-Generated Applications"));
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- // Set app title
- CString csVersion, csV0, csV1;
- csVersion.LoadString( ID_APP_VERSION );
- AfxExtractSubString( csV0, csVersion, 0, ',' );
- AfxExtractSubString( csV1, csVersion, 1, ',' );
- CString csBuild;
- #if defined( _DEBUG )
- csBuild += _T(" Debug");
- #endif
- #if defined( _UNICODE )
- csBuild += _T(" Unicode");
- #endif
- m_csTitle.Format( _T("Markup %s.%s Lite%s"), csV0, csV1, csBuild );
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(
- IDR_MARKUPTYPE,
- RUNTIME_CLASS(CMarkupDoc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CMarkupView));
- AddDocTemplate(pDocTemplate);
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- return FALSE;
- m_pMainWnd = pMainFrame;
- // Parse command line for standard shell commands, DDE, file open
- CCommandLineInfo cmdInfo;
- ParseCommandLine(cmdInfo);
- // Dispatch commands specified on the command line
- if (!ProcessShellCommand(cmdInfo))
- return FALSE;
- // TestMarkup();
- // The main window has been initialized, so show and update it.
- pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->UpdateWindow();
- return TRUE;
- }
- void CMarkupApp::CreateNewDoc( CString csText, CString csTitle )
- {
- // This routine is used to open a document with the given text
- POSITION pos = m_pDocManager->GetFirstDocTemplatePosition();
- CDocTemplate* pTemplate = m_pDocManager->GetNextDocTemplate(pos);
- ASSERT(pTemplate != NULL);
- ASSERT_KINDOF(CDocTemplate, pTemplate);
- CMarkupDoc* pDoc = (CMarkupDoc*)pTemplate->OpenDocumentFile(NULL);
- pDoc->m_csText = csText;
- pDoc->m_doc.SetDoc( csText );
- pDoc->SetTitle( csTitle );
- pDoc->UpdateAllViews( NULL, 1 );
- pDoc->SetModifiedFlag( FALSE );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Display build in title bar of About Box
- CString csTitle = _T("About ") + ((CMarkupApp*)AfxGetApp())->m_csTitle;
- SetWindowText(csTitle);
- // Display full version
- CString csVersion;
- csVersion.LoadString( ID_APP_VERSION );
- GetDlgItem( IDC_STATIC_VERSION )->SetWindowText( csVersion );
- return TRUE;
- }
- // App command to run the dialog
- void CMarkupApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMarkup Test
- #include "Markup.h"
- void CMarkupApp::OnAppTest()
- {
- // Add tests in here, accessible from the File->Test menu item
- // Test documents are loaded into cascaded documents
- m_pMainWnd->SendMessage( WM_COMMAND, ID_WINDOW_CASCADE, 0 );
- // ORDER Test
- //
- // This creates a document like one in the documentation
- // This is also just for demonstrating simple use of CMarkup
- //
- CMarkup xml;
- xml.AddElem( _T("ORDER") );
- xml.AddChildElem( _T("ITEM") );
- xml.IntoElem();
- xml.AddChildElem( _T("NAME"), _T("carrots") );
- xml.AddChildElem( _T("QTY"), _T("1") );
- xml.AddChildElem( _T("PRICE"), _T(".98") );
- xml.AddChildAttrib( _T("unit"), _T("1 lb") );
- xml.AddElem( _T("ITEM") );
- xml.AddChildElem( _T("NAME"), _T("onions") );
- xml.AddChildElem( _T("QTY"), _T("1") );
- xml.AddChildElem( _T("PRICE"), _T("1.10") );
- xml.AddChildAttrib( _T("unit"), _T("3 lb bag") );
- xml.AddChildElem( _T("SUPPLIER"), _T("Hanover") );
- CreateNewDoc( xml.GetDoc(), _T("ORDER") );
- // Create List
- CString csList;
- xml.ResetPos();
- xml.FindElem( _T("ORDER") );
- while ( xml.FindChildElem( _T("ITEM") ) )
- {
- xml.IntoElem();
- xml.FindChildElem( _T("NAME") );
- csList += xml.GetChildData() + _T("n");
- xml.OutOfElem();
- }
- csList += _T("And repeat last itemn");
- csList += xml.GetChildData();
- // Car Test Lite
- //
- // This adds randomly chosen attributes
- //
- srand( (unsigned)time( NULL ) );
- struct CarTestData { _TCHAR* szLow; _TCHAR* szUp; _TCHAR* szMix; } ct[] =
- {
- _T("up"), _T("SKY"), _T("Light"),
- _T("down"), _T("FLOOR"), _T("Dust"),
- _T("left"), _T("DOOR"), _T("Handle"),
- _T("right"), _T("SEAT"), _T("Gear"),
- _T("back"), _T("TRUNK"), _T("Tread"),
- _T("forward"), _T("GRILL"), _T("Motor"),
- _T(""), _T(""), _T("")
- };
- #define RND(n) max(0,min(rand()*n/RAND_MAX,n-1))
- xml.SetDoc( _T("") );
- xml.AddElem( _T("CAR") );
- xml.AddAttrib( ct[RND(6)].szLow, ct[RND(6)].szMix );
- for ( int nPart=0; nPart<100; ++nPart )
- {
- xml.AddChildElem( ct[RND(6)].szUp );
- xml.AddChildAttrib( ct[RND(6)].szLow, ct[RND(6)].szMix );
- }
- CString csCarDoc = xml.GetDoc();
- if ( ! xml.SetDoc( csCarDoc ) )
- AfxMessageBox( _T("Unable to parse Car document") );
- CreateNewDoc( xml.GetDoc(), _T("Lite Car") );
- // Depth First Traversal
- //
- // The following should result in ABCCCDB
- xml.SetDoc( _T("<A><B><C/><C/><C><D/></C></B><B/></A>") );
- CString csListOfTagNames;
- BOOL bFinished = FALSE;
- if ( xml.FindElem() )
- csListOfTagNames = xml.GetTagName();
- if ( ! xml.FindChildElem() )
- bFinished = TRUE;
- while ( ! bFinished )
- {
- // Process Element
- xml.IntoElem();
- csListOfTagNames += xml.GetTagName();
- // Next element (depth first)
- BOOL bFound = xml.FindChildElem();
- while ( ! bFound && ! bFinished )
- {
- if ( xml.OutOfElem() )
- bFound = xml.FindChildElem();
- else
- bFinished = TRUE;
- }
- }
- // AfxMessageBox( csListOfTagNames );
- }