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

📄 ctypedptrmap

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

///////////////////////////////////////////////////////////////////////////////
CTypedPtrMap
    GetNextAssoc
    Lookup
    RemoveKey
    SetAt
    operator[]

    ==================================================
    CTypedPtrMap<CMapPtrToPtr, CString, MY_STRUCT*> myPtrMap;
    ==================================================
    CTypedPtrMap<CMapStringToOb, CString, CMyObject*> myObjectMap;
    ==================================================
    typedef CTypedPtrMap<CMapStringToOb,CString,CMyObject*> CMapStringToMyObject;
    CMapStringToMyObject m_mapStringToMyObject;

    CString strKey, strValue;
	strKey.LoadString(IDS_INITIAL_KEY);

    CMyObject* pMyObject2 = new CMyObject();
	pMyObject2->m_int = 1357;
	pMyObject2->m_float = 13.57f;
	pMyObject2->m_str.LoadString(IDS_INITIAL_STRING);
	m_mapStringToMyObject[strKey] = pMyObject2;

    pos = m_mapStringToMyObject.GetStartPosition();
	while (pos != NULL)
	{
		CString str;
		CMyObject* pMyObject;
		m_mapStringToMyObject.GetNextAssoc(pos, str, pMyObject);
		delete pMyObject;
	}
	m_mapStringToMyObject.RemoveAll();

    m_mapStringToMyObject.Serialize(ar);

    // Copy all of the assocations from the document's CTypedPtrMap
	// to the listbox.
	CString strKey;
	CMyObject* pMyObject;
	m_ctlList.ResetContent();
	CMapStringToMyObject& map = GetDocument()->m_mapStringToMyObject;
	POSITION pos = map.GetStartPosition();
	while (pos != NULL)
	{
		map.GetNextAssoc(pos, strKey, pMyObject);
		AddMapEntryToListBox(strKey, pMyObject);
	}

    CMyObject* pMyObject;
	if (GetDocument()->m_mapStringToMyObject.Lookup(strKey, pMyObject) != TRUE)
		return LB_ERR;

    // Add or update association in the CTypedPtrMap
	CMyObject* pTemp = GetDocument()->m_mapStringToMyObject[m_strKey];
	delete pTemp; // delete old value
	GetDocument()->m_mapStringToMyObject[m_strKey] = pMyObject;

    CMyObject* pMyObject;
	if (GetDocument()->m_mapStringToMyObject.Lookup(m_strKey, pMyObject) != TRUE)
	{
		AfxMessageBox(IDS_KEY_NOT_FOUND);
		return;
	}


⌨️ 快捷键说明

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