home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / MFCITER.ZIP / Source / MyProjects / MFCIteratorDemo / MFCIteratorDemo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-22  |  6.8 KB  |  199 lines

  1. // MFCIteratorDemo.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MFCIteratorDemo.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "ChildFrm.h"
  9. #include "MFCIteratorDemoDoc.h"
  10. #include "MFCIteratorDemoView.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMFCIteratorDemoApp
  20.  
  21. BEGIN_MESSAGE_MAP(CMFCIteratorDemoApp, CWinApp)
  22.     //{{AFX_MSG_MAP(CMFCIteratorDemoApp)
  23.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24.         // NOTE - the ClassWizard will add and remove mapping macros here.
  25.         //    DO NOT EDIT what you see in these blocks of generated code!
  26.     //}}AFX_MSG_MAP
  27.     // Standard file based document commands
  28.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  29.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  30.     // Standard print setup command
  31.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  32. END_MESSAGE_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMFCIteratorDemoApp construction
  36.  
  37. CMFCIteratorDemoApp::CMFCIteratorDemoApp()
  38. {
  39.     // TODO: add construction code here,
  40.     // Place all significant initialization in InitInstance
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // The one and only CMFCIteratorDemoApp object
  45.  
  46. CMFCIteratorDemoApp theApp;
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CMFCIteratorDemoApp initialization
  50.  
  51. BOOL CMFCIteratorDemoApp::InitInstance()
  52. {
  53.     AfxEnableControlContainer();
  54.  
  55.     // Standard initialization
  56.     // If you are not using these features and wish to reduce the size
  57.     //  of your final executable, you should remove from the following
  58.     //  the specific initialization routines you do not need.
  59.  
  60. #ifdef _AFXDLL
  61.     Enable3dControls();         // Call this when using MFC in a shared DLL
  62. #else
  63.     Enable3dControlsStatic();   // Call this when linking to MFC statically
  64. #endif
  65.  
  66.     // Change the registry key under which our settings are stored.
  67.     // TODO: You should modify this string to be something appropriate
  68.     // such as the name of your company or organization.
  69.     SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  70.  
  71.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  72.  
  73.     // Register the application's document templates.  Document templates
  74.     //  serve as the connection between documents, frame windows and views.
  75.  
  76.     CMultiDocTemplate* pDocTemplate;
  77.     pDocTemplate = new CMultiDocTemplate(
  78.         IDR_DOC_A,
  79.         RUNTIME_CLASS(CMFCIteratorDemoDoc),
  80.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  81.         RUNTIME_CLASS(CMFCIteratorDemoView));
  82.     AddDocTemplate(pDocTemplate);
  83.  
  84.     pDocTemplate = new CMultiDocTemplate(
  85.         IDR_DOC_B,
  86.         RUNTIME_CLASS(CMFCIteratorDemoDoc),
  87.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  88.         RUNTIME_CLASS(CMFCIteratorDemoView));
  89.     AddDocTemplate(pDocTemplate);
  90.  
  91.     pDocTemplate = new CMultiDocTemplate(
  92.         IDR_DOC_C,
  93.         RUNTIME_CLASS(CMFCIteratorDemoDoc),
  94.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  95.         RUNTIME_CLASS(CMFCIteratorDemoView));
  96.     AddDocTemplate(pDocTemplate);
  97.  
  98.     // create main MDI Frame window
  99.     CMainFrame* pMainFrame = new CMainFrame;
  100.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  101.         return FALSE;
  102.     m_pMainWnd = pMainFrame;
  103.  
  104.     // Parse command line for standard shell commands, DDE, file open
  105.     CCommandLineInfo cmdInfo;
  106.     ParseCommandLine(cmdInfo);
  107.  
  108.     // Dispatch commands specified on the command line
  109.     if (!ProcessShellCommand(cmdInfo))
  110.         return FALSE;
  111.  
  112.     // The main window has been initialized, so show and update it.
  113.     pMainFrame->ShowWindow(m_nCmdShow);
  114.     pMainFrame->UpdateWindow();
  115.  
  116.     return TRUE;
  117. }
  118.  
  119.  
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CAboutDlg dialog used for App About
  122.  
  123. class CAboutDlg : public CDialog
  124. {
  125. public:
  126.     CAboutDlg();
  127.  
  128. // Dialog Data
  129.     //{{AFX_DATA(CAboutDlg)
  130.     enum { IDD = IDD_ABOUTBOX };
  131.     CString m_AboutText;
  132.     //}}AFX_DATA
  133.  
  134.     // ClassWizard generated virtual function overrides
  135.     //{{AFX_VIRTUAL(CAboutDlg)
  136.     protected:
  137.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  138.     //}}AFX_VIRTUAL
  139.  
  140. // Implementation
  141. protected:
  142.     //{{AFX_MSG(CAboutDlg)
  143.         // No message handlers
  144.     //}}AFX_MSG
  145.     DECLARE_MESSAGE_MAP()
  146. };
  147.  
  148. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  149. {
  150.     //{{AFX_DATA_INIT(CAboutDlg)
  151.     m_AboutText = _T(
  152.         "This demo of the MFC Iterator classes shows how they may be used to "
  153.         "iterate through MFC containers, and apply an operation to the contents "
  154.         "of nested MFC container classes.\r\n\r\n"
  155.         "In this demo, the container classes are:\r\n\r\n"
  156.         "1. The application (CWinApp) which contains document templates (CDocTemplate).\r\n"
  157.         "2. The document templates, which contain documents (CDocument).\r\n"
  158.         "3. The documents, which contain views (CView).\r\n\r\n"
  159.         "The application has 3 document templates, each with a document (Doc A, Doc B, Doc C), "
  160.         "that each have a default view.\r\n\r\n"
  161.         "Using the MFC Iterator classes, all the views in all the documents in all the "
  162.         "document templates in the application can be iterated, and the operation that will "
  163.         "be applied to each in this demo is \"Toggle Minimise Window\".\r\n\r\n"
  164.         "The effect of this will be to toggle the state of every window in the application "
  165.         "between the minimised and the restored state.\r\n\r\n"
  166.         "To test this facility, create some windows in the usual way, and use the menu "
  167.         "option: 'Window\\DEMO: Toggle Minimise All', "
  168.         "or the toolbar button on the far right of the toolbar.\r\n\r\n"
  169.         "You will find all the relevant code in MainFrm.cpp and the headers it includes.\r\n\r\n"
  170.         "I hope you find this demo a useful intoduction to STL iterators,\r\n\r\n"
  171.         "\tDave Lorde");
  172.     //}}AFX_DATA_INIT
  173. }
  174.  
  175. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  176. {
  177.     CDialog::DoDataExchange(pDX);
  178.     //{{AFX_DATA_MAP(CAboutDlg)
  179.     DDX_Text(pDX, IDC_ABOUT_TEXT, m_AboutText);
  180.     //}}AFX_DATA_MAP
  181. }
  182.  
  183. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  184.     //{{AFX_MSG_MAP(CAboutDlg)
  185.         // No message handlers
  186.     //}}AFX_MSG_MAP
  187. END_MESSAGE_MAP()
  188.  
  189. // App command to run the dialog
  190. void CMFCIteratorDemoApp::OnAppAbout()
  191. {
  192.     CAboutDlg aboutDlg;
  193.     aboutDlg.DoModal();
  194. }
  195.  
  196. /////////////////////////////////////////////////////////////////////////////
  197. // CMFCIteratorDemoApp message handlers
  198.  
  199.