Click here to Skip to main content
Click here to Skip to main content

CAtomT - An ATOM wrapper for WTL

, 26 Dec 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple Win32 ATOM type wrapper.

Introduction

Here is a very simple ATOM type wrapper, which supports the simplest ATOMs API. The class interface is very simple, and doesn't need any description. The class source is really small, so I posted it here:

///////////////////////////////////////////////////////////////////////////////
// CAtomT - ATOM type wrapper

template[bool t_bGlobal]
class CAtomT
{
public:
    ATOM m_Atom;

public:
    enum AtomType
    {
        ATOM_INTEGER = 0,
        ATOM_STRING
    };

public:
    CAtomT(ATOM Atom = 0) : m_Atom(Atom)
    { }

    CAtomT& operator=(const CAtomT& Atom)
    {
        if (this != &Atom)
            m_Atom = Atom;

        return (*this);
    }

    operator ATOM() const
    {
        return m_Atom;
    }

    bool IsValid() const
    {
        return (m_Atom != 0);
    }

    AtomType GetType() const
    {
        ATLASSERT(IsValid());
        return (m_Atom < MAXINTATOM) ? ATOM_INTEGER : ATOM_STRING;
    }

    bool GetName(LPTSTR lpNameBuffer, int nBufferSize) const
    {
        ATLASSERT(IsValid());
        ATLASSERT(lpNameBuffer != NULL);
        if (t_bGlobal)
            return (::GlobalGetAtomName(m_Atom, lpNameBuffer, nBufferSize) != 0);
        else
            return (::GetAtomName(m_Atom, lpNameBuffer, nBufferSize) != 0);
    }

#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
    bool GetName(_CSTRING_NS::CString& strName) const
    {
        ATLASSERT(IsValid());
        const size_t MAX_ATOM_NAME_SIZE = 255;
        LPTSTR lpNameBuffer = strName.GetBufferSetLength(MAX_ATOM_NAME_SIZE);
        if (lpNameBuffer != NULL)
        {
            bool bRes = GetName(lpNameBuffer, MAX_ATOM_NAME_SIZE);
            strName.ReleaseBuffer();
            return bRes;
        }
        else
            return false;
    }
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)

    bool Delete()
    {
        ATLASSERT(IsValid());
        if (t_bGlobal)
            m_Atom = ::GlobalDeleteAtom(m_Atom);
        else
            m_Atom = ::DeleteAtom(m_Atom);
        return (!IsValid());
    }

public:
    static CAtomT Add(ATL::_U_STRINGorID AtomName)
    {
        if (t_bGlobal)
            return CAtomT(::GlobalAddAtom(AtomName.m_lpstr));
        else
            return CAtomT(::AddAtom(AtomName.m_lpstr));
    }

    static CAtomT Find(ATL::_U_STRINGorID AtomName)
    {
        if (t_bGlobal)
            return CAtomT(::GlobalFindAtom(AtomName.m_lpstr));
        else
            return CAtomT(::FindAtom(AtomName.m_lpstr));
    }
};

#ifndef _WIN32_WCE
typedef CAtomT<false> CAtom;
#endif // _WIN32_WCE
typedef CAtomT<true> CGlobalAtom;

License

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

Share

About the Author

isemenov

Russian Federation Russian Federation
No Biography provided

Comments and Discussions

 
GeneralAbout ATOM and more... PinmemberRemon29-Dec-06 13:48 
GeneralRe: About ATOM and more... PinmemberRemon29-Dec-06 14:31 
QuestionWhat is this ATOM? Pinmemberarmentage28-Dec-06 8:44 
AnswerRe: What is this ATOM? Pinmemberisemenov28-Dec-06 23:13 
Question? PinmemberShawn Poulson27-Dec-06 9:29 
AnswerRe: ? Pinmemberisemenov28-Dec-06 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 26 Dec 2006
Article Copyright 2006 by isemenov
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid