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

📄 carray.txt

📁 MFC集合类使用说明,简单明了,通俗易懂
💻 TXT
字号:
Expand the Header Files folder, and open file StdAfx.h.
At the end of the file, type:
#include <afxtempl.h>    // MFC templates

///////////////////////////////////////////////////////////////////////////////
CArray < class TYPE, class ARG_TYPE >

    TYPE        Template parameter specifying the type of objects stored in the array.
                TYPE is a parameter that is returned by CArray.

    ARG_TYPE    Template parameter specifying the argument type used to access
                objects stored in the array. Often a reference to TYPE.
                ARG_TYPE is a parameter that is passed to CArray.

    The CArray class supports arrays that are are similar to C arrays, but can
    dynamically shrink and grow as necessary


    ==================================================
    Class Members
    ==================================================
    Add
        int Add( ARG_TYPE newElement );
            throw( CMemoryException );
    Append
        int Append( const CArray& src );
    Copy
        void Copy( const CArray& src );
    ElementAt
        TYPE& ElementAt( int nIndex );
    FreeExtra
        void FreeExtra( );
    GetAt
        TYPE GetAt( int nIndex ) const;
    GetData
        const TYPE* GetData( ) const;
    GetSize
        int GetSize( ) const;
    GetUpperBound
        int GetUpperBound( ) const;
    InsertAt
        void InsertAt( int nIndex, ARG_TYPE newElement, int nCount = 1 );
            throw( CMemoryException );
        void InsertAt( int nStartIndex, CArray* pNewArray );
            throw( CMemoryException );
                [pNewArray - Another array that contains elements
                 to be added to this array.]
    RemoveAll
        void RemoveAll( );
    RemoveAt
        void RemoveAt( int nIndex, int nCount = 1 );
    SetAt
        void SetAt( int nIndex, ARG_TYPE newElement );
    SetAtGrow
        void SetAtGrow( int nIndex, ARG_TYPE newElement );
            throw( CMemoryException );
    SetSize
        void SetSize( int nNewSize, int nGrowBy = -1 );
            throw( CMemoryException );
    operator[]
        TYPE& operator []( int nIndex );
        TYPE operator []( int nIndex ) const;

    ==================================================
    Create
    ==================================================
    CArray<CPoint,CPoint> m_ObjectArray;
    m_ObjectArray.SetSize(number_of_elements, elements_to_allocate_if_increased);

    CArray<CPerson*, CPerson*> m_PointerArray;
    //Constructs an empty array. The array grows one element at a time


    ==================================================
    Insert
    ==================================================
    CPoint pt(10,10);
    m_ObjectArray.Add(pt);

    ==================================================
    Iterate
    ==================================================
    CArray<CPoint,CPoint>&ptArray = m_ObjectArray;
	for (int nIndex = 0; nIndex < ptArray.GetSize(); nIndex++)
	{
		CPoint pt = ptArray[nIndex];
    }

    ==================================================
    Find
    ==================================================

    ==================================================
    Update
    ==================================================
    CPoint pt(m_x, m_y);
    m_ObjectArray[nSel] = pt;

    ==================================================
    Delete
    ==================================================
    m_ObjectArray.RemoveAt(nSel);
    m_ObjectArray.RemoveAll();

    int i = 0;
    while (i < m_PointerArray.GetSize() )
    {
        delete m_PointerArray.GetAt( i++ );
    }
    m_PointerArray.RemoveAll();

    ==================================================
    Serialize
    ==================================================
    m_ObjectArray.Serialize( ar );







⌨️ 快捷键说明

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