⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 markupdlg.cpp

📁 最有名的一个VC++外部类,Cmarkup,现在已经出了最新版8.2了,现在网上的都是6.1以下的版,希望这个新版对你们有所帮助,一些相用VC开发VML的朋友千万不要错过
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// MarkupDlg.cpp : implementation file
//
// Markup Release 8.2
// Copyright (C) 1999-2006 First Objective Software, Inc. All rights reserved
// Go to www.firstobject.com for the latest CMarkup and EDOM documentation
// Use in commercial applications requires written permission
// This software is provided "as is", with no warranty.

#include "stdafx.h"
#include <locale.h>
#include "MarkupApp.h"
#include "MarkupDlg.h"

#ifdef MARKUP_MSXML
#include "MarkupMSXML.h"
#define _CSTR(s) (LPCTSTR)s
#elif defined( MARKUP_STL )
#include "MarkupSTL.h"
#define _CSTR(s) (s).c_str()
#else
#include "Markup.h"
#define _CSTR(s) (LPCTSTR)s
#endif

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

/////////////////////////////////////////////////////////////////////////////
// CMarkupDlg dialog

CMarkupDlg::CMarkupDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMarkupDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMarkupDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMarkupDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMarkupDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMarkupDlg, CDialog)
	//{{AFX_MSG_MAP(CMarkupDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
	ON_BN_CLICKED(IDC_BUTTON_PARSE, OnButtonParse)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CMarkupDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CMarkupDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
/////////////////////////////////////////////////////////////////////////////
// CMarkupDlg message handlers

BOOL CMarkupDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	m_nErrorCount = 0;
	m_nTotalZones = 0;
	m_nTotalChecks = 0;

	// Load settings
	CString csFilename = AfxGetApp()->GetProfileString( _T("Settings"), _T("Filename"), _T("") );
	if ( ! csFilename.IsEmpty() )
		GetDlgItem( IDC_EDIT_FILE )->SetWindowText( csFilename );
	CString csPos = AfxGetApp()->GetProfileString( _T("Settings"), _T("Position"), _T("") );
	CPoint ptDlg;
	if ( _stscanf( csPos, _T("%d,%d"), &ptDlg.x, &ptDlg.y ) == 2 )
	{
		CRect rect;
		GetWindowRect( &rect );
		if ( rect.Width() > 10 )
		{
			rect.OffsetRect( ptDlg.x - rect.left, ptDlg.y - rect.top ); 
			MoveWindow( &rect );
		}
	}

	SetWindowText( _T("CMarkup Evaluation Test Dialog") );

	// Determine version
	CString csVersion, csV0, csV1;
	CString csTitle;
	csVersion.LoadString( ID_APP_VERSION );
	AfxExtractSubString( csV0, csVersion, 0, ',' );
	AfxExtractSubString( csV1, csVersion, 1, ',' );
	CString csClass = _T("CMarkup");
	CString csBuild;
	#if defined( MARKUP_MSXML )
	csClass += _T("MSXML");
	#if defined( MARKUP_MSXML3 )
	csClass += _T(" MSXML3");
	#elif defined( MARKUP_MSXML4 )
	csClass += _T(" MSXML4");
	#endif
	#elif defined( MARKUP_STL )
	csClass += _T("STL");
	#endif
	#if defined( _DEBUG )
	csBuild += _T(" Debug");
	#endif
	#if defined( _UNICODE )
	csBuild += _T(" Unicode");
	#endif
	#if defined( _MBCS )
	csBuild += _T(" MBCS");
	#endif
	csTitle.Format( _T("%s %s.%s%s\r\n"), csClass, csV0, csV1, csBuild );
	OutputTestResults( csTitle );
	OutputParseResults( _T("") );

	RunTest();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMarkupDlg::OnDestroy() 
{
	// Save settings
	CString csFilename;
	GetDlgItem( IDC_EDIT_FILE )->GetWindowText( csFilename );
	AfxGetApp()->WriteProfileString( _T("Settings"), _T("Filename"), csFilename );
	CRect rect;
	GetWindowRect( &rect );
	CString csPos;
	csPos.Format( _T("%d,%d"), rect.left, rect.top );
	AfxGetApp()->WriteProfileString( _T("Settings"), _T("Position"), csPos );

	CDialog::OnDestroy();
}

void CMarkupDlg::OutputTestResults( CString csMsg )
{
	m_csTestResults += csMsg;
	GetDlgItem( IDC_ST_TEST_RESULTS )->SetWindowText( m_csTestResults );
}

int CMarkupDlg::Alert( CString csMsg )
{
	m_csChecks += csMsg + _T("\r\n");
	++m_nErrorCount;
	return -1;
}

void CMarkupDlg::StartCheckZone( CString csCheckZone )
{
	m_nCheckCount = 0;
	++m_nTotalZones;
	m_csCheckZone = csCheckZone;
}

int CMarkupDlg::Check( BOOL bCorrect )
{
	++m_nCheckCount;
	++m_nTotalChecks;
	if ( ! bCorrect )
	{
		if ( m_csCheckZone.IsEmpty() )
			m_csCheckZone = _T("Unknown Check Zone");
		CString csMsg;
		csMsg.Format( _T("Error: %s, check %d"), m_csCheckZone, m_nCheckCount );
		return Alert( csMsg );
	}
	return 0;
}

#ifdef MARKUP_MSXML
void SetEntry( CMarkupMSXML& xml, CString csSection, CString csEntry, CString csValue )
#elif defined( MARKUP_STL )
void SetEntry( CMarkupSTL& xml, CString csSection, CString csEntry, CString csValue )
#else
void SetEntry( CMarkup& xml, CString csSection, CString csEntry, CString csValue )
#endif
{
	// Find/Create root element of xml document
	xml.ResetPos();
	if ( ! xml.FindElem() )
		xml.AddElem( _T("Settings") ); // or whatever root element name is

	// Find/Create section
	BOOL bFoundSection = FALSE;
	while ( xml.FindChildElem(_T("Section")) )
	{
		// Is this the right section?
		if ( _CSTR(xml.GetChildAttrib(_T("name"))) == csSection )
		{
			bFoundSection = TRUE;
			break;
		}
	}
	if ( ! bFoundSection )
	{
		xml.AddChildElem( _T("Section") );
		xml.SetChildAttrib( _T("name"), csSection );
	}

	// Find/Create entry
	xml.IntoElem();
	BOOL bFoundEntry = FALSE;
	while ( xml.FindChildElem(_T("Entry")) )
	{
		// Is this the right entry?
		if ( _CSTR(xml.GetChildAttrib(_T("name"))) == csEntry )
		{
			bFoundEntry = TRUE;
			break;
		}
	}
	if ( ! bFoundEntry )
	{
		xml.AddChildElem( _T("Entry") );
		xml.SetChildAttrib( _T("name"), csEntry );
	}

	// Set value
	xml.SetChildData( csValue );
}

#ifdef MARKUP_MSXML
bool FindEntry( CMarkupMSXML& xml, CString csSection, CString csEntry, CString& csValue )
#elif defined( MARKUP_STL )
bool FindEntry( CMarkupSTL& xml, CString csSection, CString csEntry, CString& csValue )
#else
bool FindEntry( CMarkup& xml, CString csSection, CString csEntry, CString& csValue )
#endif
{
	// Loop through sections
	xml.ResetPos();
	while ( xml.FindChildElem(_T("Section")) )
	{
		// Is this the right section?
		if ( _CSTR(xml.GetChildAttrib(_T("name"))) == csSection )
		{
			// Check entries in this section
			xml.IntoElem();
			while ( xml.FindChildElem(_T("Entry")) )
			{
				// Is this the right entry?
				if ( _CSTR(xml.GetChildAttrib(_T("name"))) == csEntry )
				{
					csValue = _CSTR(xml.GetChildData());
					return TRUE;
				}
			}
			break; // don't check any other sections
		}
	}
	return FALSE;
}

#ifdef MARKUP_MSXML
void SimpleMerge( CMarkupMSXML& xmlMaster, CMarkupMSXML& xmlUpdate )
#elif defined( MARKUP_STL )
void SimpleMerge( CMarkupSTL& xmlMaster, CMarkupSTL& xmlUpdate )
#else
void SimpleMerge( CMarkup& xmlMaster, CMarkup& xmlUpdate )
#endif
{
	// Generic merge xmlUpdate into xmlMaster when element names are unique among siblings
	// removing elements from xmlUpdate as added to or overrided in xmlMaster
	//
	CString csMergeName;
	xmlMaster.ResetPos();
	xmlUpdate.ResetPos();
	BOOL bMergeFinished = FALSE;
	if ( ! xmlMaster.FindChildElem() )
	{
		xmlMaster = xmlUpdate;
		bMergeFinished = TRUE;
	}
	xmlUpdate.FindChildElem();
	while ( ! bMergeFinished )
	{
		// Process Element
		xmlMaster.IntoElem();
		xmlUpdate.IntoElem();
		csMergeName = _CSTR(xmlMaster.GetTagName());

		// Did this one match?
		xmlUpdate.ResetMainPos();
		BOOL bMatched = xmlUpdate.FindElem( csMergeName );
		if ( bMatched )
		{
			// Merge attributes
			for ( int nAttrib=0; !(csMergeName=_CSTR(xmlUpdate.GetAttribName(nAttrib))).IsEmpty(); ++nAttrib )
				xmlMaster.SetAttrib( csMergeName, _CSTR(xmlUpdate.GetAttrib(csMergeName)) );
		}

		// Next element (depth first)
		BOOL bChildFound = xmlMaster.FindChildElem();
		while ( ! bChildFound && ! bMergeFinished )
		{
			if ( bMatched )
			{
				while ( xmlUpdate.FindChildElem() )
				{
					xmlMaster.AddChildSubDoc( _CSTR(xmlUpdate.GetChildSubDoc()) );
					xmlUpdate.RemoveChildElem();
				}
				xmlUpdate.RemoveElem();
			}
			if ( xmlMaster.OutOfElem() )
			{
				xmlUpdate.OutOfElem();
				bChildFound = xmlMaster.FindChildElem();
				if ( ! bChildFound )
				{
					bMatched = TRUE;
					xmlUpdate.ResetChildPos();
				}
			}
			else
				bMergeFinished = TRUE;
		}
	}
}

CString TruncToLastEOL( CString csVal )
{
	// locate and truncate from final EOL
	// also cuts any trailing indentation
	int nLength = csVal.GetLength();
	const _TCHAR* pszVal = (const _TCHAR*)csVal;
	int nLastEOL = nLength;
	int nChar = 0;
	while ( nChar < nLength )
	{
		// Go to next EOL
		nLastEOL = nLength;
		while ( nChar < nLength && pszVal[nChar] != _T('\r')
				&& pszVal[nChar] != _T('\n') )
			nChar += (int)_tclen(&pszVal[nChar]);
		nLastEOL = nChar;
		while ( nChar < nLength
				&& _tcschr(_T(" \t\n\r"),pszVal[nChar]) )
			++nChar;
	}
	if ( nLastEOL < nLength )
		csVal = csVal.Left( nLastEOL );
	return csVal;
}

int CMarkupDlg::RunTest()
{
	// Instantiate XML objects for use in tests
	// Mostly the same code can be used to test the different versions of CMarkup
	// However, to convert both CString and std::string to const char *, use _CSTR()
#ifdef MARKUP_MSXML
	CMarkupMSXML xml, xml2, xml3;
#elif defined( MARKUP_STL )
	CMarkupSTL xml, xml2, xml3;
#else
	CMarkup xml, xml2, xml3;
#endif

	// Integer Method Test
	StartCheckZone( _T("Integer Method Test") );
	xml.SetDoc( NULL );
	xml.AddElem( _T("R"), 5 );
	Check( _ttoi(_CSTR(xml.GetData())) == 5 );
	xml.SetData( _T("") );
	Check( xml.InsertChildElem( _T("C"), 1 ) );
	Check( xml.AddChildElem( _T("C"), 3 ) );
	Check( xml.IntoElem() );
	Check( xml.InsertElem( _T("C"), 2 ) );
	xml.ResetMainPos();
	Check( xml.FindElem() );
	Check( _ttoi(_CSTR(xml.GetData())) == 1 );
	Check( xml.FindElem() );
	Check( _ttoi(_CSTR(xml.GetData())) == 2 );
	Check( xml.FindElem() );
	Check( _ttoi(_CSTR(xml.GetData())) == 3 );

	// Quote and special chars in attrib value test
	StartCheckZone( _T("Attrib Value Test") );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -