Visual Studio Notes Lists

From Minor Miracle Software
Jump to: navigation, search

Visual Studio Notes Lists

CList Class[1] is a single list with the object stored being both the name and value.

CMap Class[2] is a double list where the name and value can be different objects.
This code populates a CMap with a CString name and CWinThread pointer value then iterates through the whole list.

CMap<CString, LPCTSTR, CWinThread*, CWinThread*> encodermap;

encodermap["Thread 1" ] = (CWinThread*) 14;
encodermap["Thread 2" ] = (CWinThread*) 15;
encodermap["Thread 3" ] = (CWinThread*) 16;
encodermap["Thread 4" ] = (CWinThread*) 17;
encodermap["Thread 5" ] = (CWinThread*) 18;

POSITION pos = encodermap.GetStartPosition();
while(pos != NULL)
{
   CWinThread* pPerson;
   CString string;
   // Get key (string) and value (pPerson)
   encodermap.GetNextAssoc(pos, string, pPerson);
   // Use string and pPerson
	 printf(" Thread Name %s Thread Pointer %d \n", string.GetBuffer(), pPerson );
}
Output:
 Thread Name Thread 5 Thread Pointer 18
 Thread Name Thread 4 Thread Pointer 17
 Thread Name Thread 1 Thread Pointer 14
 Thread Name Thread 3 Thread Pointer 16
 Thread Name Thread 2 Thread Pointer 15

Internal Links

Parent Article: Visual Studio Notes