Click here to Skip to main content
15,891,136 members
Articles / Multimedia / DirectX

Rendering Text with Direct2D & DirectWrite

Rate me:
Please Sign up or sign in to vote.
4.94/5 (39 votes)
3 Jan 2015CPOL8 min read 106.4K   2.8K   76  
Direct2D, DirectWrite, Windows API, C++, std::shared_ptr and more
#pragma once
#ifndef __HWINGUID_H__
#define __HWINGUID_H__

#include "hwinDef.h"
#include "hwinString.h"

#ifdef _MANAGED
#pragma managed(push,off)
#endif

#pragma pack(push,8)

namespace harlinn
{
    namespace windows
    {

        class Guid : public GUID
        {
        public:
            static Guid Empty( )
            {
                GUID result = { 0, };
                return result;
            }

            Guid( )
            {
                memset( static_cast<GUID*>( this ), 0, sizeof( GUID ) );
            }

            explicit Guid( const WideString& theGuidAsAString )
            {
                *this = Parse( theGuidAsAString );
            }

            explicit Guid( const std::array<Byte, 16>& theBytes )
            {
                memcpy( static_cast<GUID*>( this ), theBytes.data( ), sizeof( GUID ) );
            }


            Guid( const GUID& theOther )
            {
                *( ( GUID* )this ) = theOther;
            }

            Guid& operator = ( const GUID& theOther )
            {
                *( ( GUID* )this ) = theOther;
                return *this;
            }

            int CompareTo( const GUID& theOther ) const
            {
                auto result = memcmp( static_cast<const GUID*>( this ), static_cast<const GUID*>( &theOther ), sizeof( GUID ) );
                return result;
            }

            bool operator == ( const GUID& theOther ) const
            {
                return CompareTo( theOther ) == 0;
            }
            bool operator != ( const GUID& theOther ) const
            {
                return CompareTo( theOther ) != 0;
            }
            bool operator <= ( const GUID& theOther ) const
            {
                return CompareTo( theOther ) <= 0;
            }
            bool operator <  ( const GUID& theOther ) const
            {
                return CompareTo( theOther ) <  0;
            }
            bool operator >= ( const GUID& theOther ) const
            {
                return CompareTo( theOther ) >= 0;
            }
            bool operator >  ( const GUID& theOther ) const
            {
                return CompareTo( theOther ) >  0;
            }


            bool IsEmpty( ) const
            {
                GUID empty = { 0, };
                auto emptyCompareResult = memcmp( static_cast<const GUID*>( this ), static_cast<const GUID*>( &empty ), sizeof( GUID ) );
                return emptyCompareResult == 0;
            }


            static HWIN_EXPORT Guid NewGuid( );
            static Guid New( )
            {
                return NewGuid( );
            }
            static HWIN_EXPORT bool TryParse( const WideString& theGuidAsAString, Guid& result );
            static HWIN_EXPORT Guid Parse( const WideString& theGuidAsAString );
            HWIN_EXPORT String ToString( ) const;
            HWIN_EXPORT WideString ToWideString( ) const;
            HWIN_EXPORT AnsiString ToAnsiString( ) const;
            std::array<Byte, 16> ToBytes( ) const
            {
                std::array<Byte, 16> result;

                result[0] = ( byte )( Data1 );
                result[1] = ( byte )( Data1 >> 8 );
                result[2] = ( byte )( Data1 >> 16 );
                result[3] = ( byte )( Data1 >> 24 );
                result[4] = ( byte )( Data2 );
                result[5] = ( byte )( Data2 >> 8 );
                result[6] = ( byte )( Data3 );
                result[7] = ( byte )( Data3 >> 8 );
                result[8] = Data4[0];
                result[9] = Data4[1];
                result[10] = Data4[2];
                result[11] = Data4[3];
                result[12] = Data4[4];
                result[13] = Data4[5];
                result[14] = Data4[6];
                result[15] = Data4[7];

                return result;
            }


            int GetHashCode( ) const
            {
                const char* ptr = reinterpret_cast<const char*>( static_cast<const GUID*>( this ) );
                return ptr[0] ^ ( ( *( ( int* )&ptr[4] ) << 16 ) | ( int )*( ( unsigned short* )&ptr[6] ) ) ^ ( ( ( int )ptr[10] << 24 ) | ptr[15] );
            }

        };

    }
}

namespace std
{
    template<>
    struct hash<harlinn::windows::Guid> : public std::unary_function<harlinn::windows::Guid, size_t>
    {
        size_t operator()( const harlinn::windows::Guid& theGuid ) const
        {
            return static_cast<size_t>( theGuid.GetHashCode( ) );
        }
    };

}
#pragma pack(pop)

#ifdef _MANAGED
#pragma managed(pop)
#endif

#endif //__COMMONGUID_H__

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)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions