Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / MFC

The Win32 Foundation Classes (WFC) - Version 45

Rate me:
Please Sign up or sign in to vote.
4.93/5 (40 votes)
16 May 2000 468.1K   12.7K   280  
The Win32 Foundation Classes (WFC) are a library of C++ classes that extend Microsoft Foundation Classes (MFC) beyond mere GUI applications, and provide extensive support for system and NT specific applications
#include "my_xml.h"
#pragma hdrstop

/*
** Author: Samuel R. Blackburn
** Internet: wfc@pobox.com
**
** You can use it any way you like as long as you don't try to sell it.
**
** Any attempt to sell WFC in source code form must have the permission
** of the original author. You can produce commercial executables with
** WFC but you can't sell WFC.
**
** Copyright, 1998, Samuel R. Blackburn
**
** $Workfile: main.cpp $
** $Revision: 3 $
** $Modtime: 4/18/98 9:24a $
*/

void stanza_callback( void *, CExtensibleMarkupLanguageElement * element_p )
{
   WFCTRACEINIT( TEXT( "stanza_callback()" ) );
   WFCTRACEVAL( TEXT( "Got a stanza, number of children is " ), element_p->GetNumberOfChildren() );

   _tprintf( TEXT( "Got a stanza with %lu children\n" ), (DWORD) element_p->GetNumberOfChildren() );
}

#if defined( UNICODE )
extern "C"
#endif

int _tmain( int /* number_of_command_line_arguments */, LPCTSTR /* command_line_arguments */ [] )
{
   WFCTRACELEVELOFF( 31 ); // Turn WFC debugging statements off
   WFCTRACEINIT( TEXT( "_tmain()" ) );

   CExtensibleMarkupLanguageDocument document;

   CExtensibleMarkupLanguageElement * element_p = NULL;

   WFCTRACELEVELON( 31 ); // Turn WFC debugging statements on

   if ( parse_document( TEXT( "/wfc/sample/xml/hell.xml" ), document ) == TRUE )
   {
      WFCTRACELEVELOFF( 31 ); // Turn WFC debugging statements off
      // OK, we parsed the document, let's get the offending element

      element_p = document.GetElement( TEXT( "PERSON" ) );

      if ( element_p != NULL )
      {
         CString attribute_value;

         if ( element_p->GetAttributeByName( TEXT( "Attribute" ), attribute_value ) != FALSE )
         {
            attribute_value += TEXT( "<--" );
            WFCTRACEVAL( TEXT( "Attribute value is " ), attribute_value );
         }
      }
      else
      {
         WFCTRACE( TEXT( "Can't find element PERSON" ) );
      }

      element_p = document.GetElement( TEXT( "PERSON(1)" ) );

      if ( element_p != NULL )
      {
         CString attribute_value;

         if ( element_p->GetAttributeByName( TEXT( "A1" ), attribute_value ) != FALSE )
         {
            attribute_value += TEXT( "<--" );
            WFCTRACEVAL( TEXT( "Attribute value is " ), attribute_value );
         }
         else
         {
            WFCTRACE( TEXT( "Can't get attribute A1" ) );
         }

         if ( element_p->GetAttributeByName( TEXT( "A2" ), attribute_value ) != FALSE )
         {
            attribute_value += TEXT( "<--" );
            WFCTRACEVAL( TEXT( "Attribute value is " ), attribute_value );
         }
         else
         {
            WFCTRACE( TEXT( "Can't get attribute A2" ) );
         }
      }
      else
      {
         WFCTRACE( TEXT( "Can't find element PERSON" ) );
      }
   }

   WFCTRACELEVELOFF( 31 ); // Turn WFC debugging statements off

   return( EXIT_SUCCESS );

   document.AddCallback( TEXT( "stanza" ), stanza_callback, NULL );

   //CString element_name( TEXT( "poem.body.stanza(1).line(1)" ) );
   CString element_name( TEXT( "poem.front.[cdata[" ) );

   DWORD number_of_elements = 0;

   // if ( parse_document( TEXT( "/wfc/sample/xml/poem.original" ), document ) == TRUE )
   if ( parse_document( TEXT( "/wfc/sample/xml/test.xml" ), document ) == TRUE )
   {
   WFCTRACELEVELON( 31 );
      number_of_elements = document.CountElements( TEXT( "poem.body.stanza(  1  ).line" ) );
   WFCTRACELEVELOFF( 31 );

      WFCTRACEVAL( TEXT( "Number of elements is " ), number_of_elements );

      element_p = document.GetElement( element_name );

      if ( element_p != NULL )
      {
         WFCTRACE( TEXT( "Element FOUND!" ) );

         CString element_text;

         element_p->GetText( element_text );

         WFCTRACEVAL( TEXT( "Text is " ), element_text );
         _tprintf( TEXT( "%s" ), (LPCTSTR) element_text );

         if ( element_text.Compare( TEXT( "Behind, before, above, between, below." ) ) == 0 )
         {
            WFCTRACE( TEXT( "YES! IT WORKS!!!!" ) );
         }
         else
         {
            WFCTRACE( TEXT( "You screwed up again." ) );
         }
      }
      else
      {
         WFCTRACEVAL( TEXT( "Can't find that there element " ), element_name );
      }

      CByteArray xml;

      document.WriteTo( xml );

      WFCTRACEVAL( TEXT( "Number of bytes written is " ), xml.GetSize() );
      _tprintf( TEXT( "Wrote %d bytes\n" ), xml.GetSize() );

      CFile file;

      if ( file.Open( TEXT( "xml.out" ), CFile::modeCreate | CFile::modeWrite ) != FALSE )
      {
         file.Write( xml.GetData(), xml.GetSize() );
         file.Close();
      }
   }

   return( EXIT_SUCCESS );
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
I'm just a simple little NT programmer. Most of the work I do is remote controlling equipment in real time. I started out using Windows 3.0. Then came 3.1 and then NT. I started using NT but unfortunately, Microsoft didn't. I started using MFC but unfortunately, Microsoft didn't (and still doesn't) put any real support for NT into MFC so I wrote a bunch of C++ classes to make my life easier. Like all class libraries, mine grew. Now I'm giving it away, I call it Win32 Foundation Classes.

Check out Sam's homepage at www.SamBlackburn.com/wfc/.

Comments and Discussions