Advertisement
andruhovski

MFC CList demo

Mar 11th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. // SP-0402.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "SP-0402.h"
  6.  
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10.  
  11.  
  12. // The one and only application object
  13.  
  14. CWinApp theApp;
  15.  
  16. using namespace std;
  17.  
  18. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  19. {
  20.     int nRetCode = 0;
  21.  
  22.     HMODULE hModule = ::GetModuleHandle(NULL);
  23.  
  24.     if (hModule != NULL)
  25.     {
  26.         // initialize MFC and print and error on failure
  27.         if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
  28.         {
  29.             // TODO: change error code to suit your needs
  30.             _tprintf(_T("Fatal Error: MFC initialization failed\n"));
  31.             nRetCode = 1;
  32.         }
  33.         else
  34.         {
  35.             // TODO: code your application's behavior here.
  36.             CList <int> list1;
  37.             list1.AddTail(1);
  38.             list1.AddTail(2);
  39.             list1.AddTail(3);
  40.             list1.AddTail(5);
  41.             list1.AddTail(4);
  42.             POSITION pos = list1.GetHeadPosition();
  43.             for (int i = 0; i < list1.GetCount(); i++)
  44.             {
  45.                 _tprintf_s(_T("%d\r\n"), (int)list1.GetNext(pos));
  46.             }
  47.             CPtrList list2;
  48.             list2.AddTail(new CPoint(1, 1));
  49.             list2.AddTail(new CPoint(1, 2));
  50.             list2.AddTail(new CPoint(1, 1));
  51.             for (pos = list2.GetHeadPosition(); pos != NULL;)
  52.             {
  53.                 CPoint * p = (CPoint *) list2.GetNext(pos);
  54.                 _tprintf_s(_T("%d %d\r\n"), p->x, p->y);
  55.             }
  56.  
  57.             /*
  58.             */
  59.             CMapStringToOb myMap;    // A nontemplate collection class
  60.             CPerson myPerson;
  61.             myMap.SetAt(_T("Bill"), &myPerson);
  62.  
  63.             POSITION pos = myMap.GetStartPosition();
  64.             while (pos != NULL)
  65.             {
  66.                 CPerson* pPerson;
  67.                 CString string;
  68.                 // Gets key (string) and value (pPerson)
  69.                 myMap.GetNextAssoc(pos, string,
  70.                     (CObject*&)pPerson);
  71.                 ASSERT(pPerson->IsKindOf(
  72.                     RUNTIME_CLASS(CPerson)));
  73.                 // Use string and pPerson
  74.             }
  75.  
  76.  
  77.            
  78.  
  79.         }
  80.     }
  81.     else
  82.     {
  83.         // TODO: change error code to suit your needs
  84.         _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
  85.         nRetCode = 1;
  86.     }
  87.  
  88.     return nRetCode;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement