home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK8 / MFC / SAMPLES / MDI / MDI.CP$ / mdi
Encoding:
Text File  |  1992-03-18  |  3.9 KB  |  146 lines

  1. // mdi.cpp : Defines the class behaviors for the MDI sample application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // QuickHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. //
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15.  
  16. #include "mdi.h"
  17.  
  18. // Create one global CTheApp object.  Once created, it takes care of itself.
  19. //
  20. CTheApp theApp;
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CMainWindow
  24.  
  25. // CMainWindow message map:
  26. // Note: certain built-in MDI window behavior (tiling and cascading child
  27. // windows, arranging icons, switching to the next child window) must be
  28. // linked to user menu items explicitly by the developer (since MFC cannot
  29. // know an application's menu structure ahead of time).  MDICascade, 
  30. // MDITile, MDINext, MDIIconArrange are all CMDIFrameWnd member functions.
  31. //
  32. BEGIN_MESSAGE_MAP(CMainWindow, CMDIFrameWnd)
  33.     ON_WM_CREATE()
  34.     ON_COMMAND(IDM_ABOUT, OnAbout)
  35.     ON_COMMAND(IDM_HELLO, OnNewHello)
  36.     ON_COMMAND(IDM_BOUNCE, OnNewBounce)
  37.     ON_COMMAND(IDM_CASCADE, MDICascade)
  38.     ON_COMMAND(IDM_TILE, MDITile)
  39.     ON_COMMAND(IDM_NEXT, MDINext)
  40.     ON_COMMAND(IDM_ARRANGE, MDIIconArrange)
  41.     ON_COMMAND(IDM_EXIT, OnExit)
  42.     ON_MESSAGE(WM_CHILDDESTROY, OnChildDestroy)
  43. END_MESSAGE_MAP()
  44.  
  45.  
  46. // CMainWindow constructor:
  47. //
  48. CMainWindow::CMainWindow()
  49. {
  50.     VERIFY(LoadAccelTable("MdiAccel"));
  51.     Create(NULL, "MDI Sample Application", WS_OVERLAPPEDWINDOW, rectDefault, 
  52.            NULL, "MdiMenuInit");
  53. }
  54.  
  55. // OnCreate:
  56. // Load application's initial MDI frame menu and create an MDI client
  57. //
  58. int CMainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
  59.     m_pMenuInit = new CMenu();
  60.     m_pMenuInit->LoadMenu("MdiMenuInit");
  61.     CreateClient(lpCreateStruct, m_pMenuInit->GetSubMenu(0));
  62.  
  63.     return 0;
  64. }
  65.  
  66. // OnAbout:
  67. // Display this application's about box (defined in about.dlg).
  68. //
  69. void CMainWindow::OnAbout()
  70. {
  71.     CModalDialog about("AboutBox", this);
  72.     about.DoModal();
  73. }
  74.  
  75. // OnNewHello:
  76. // Create a new Hello child window.
  77. //
  78. void CMainWindow::OnNewHello()
  79. {
  80.     CHelloWnd *pHelloWnd = new CHelloWnd;
  81.     if (!pHelloWnd->Create("Hello", 0, rectDefault, this))
  82.     {
  83.         delete pHelloWnd;       // HWND not created
  84.         return;
  85.     }
  86.     pHelloWnd->ShowWindow(SW_SHOW);
  87.     // the default PostNcDestroy handler will delete this object when destroyed
  88. }
  89.  
  90. // OnNewBounce:
  91. // Create a new Bounce child window.
  92. //
  93. void CMainWindow::OnNewBounce()
  94. {
  95.     CBounceWnd *pBounceWnd = new CBounceWnd;
  96.     if (!pBounceWnd->Create("Bounce", 0, rectDefault, this))
  97.     {
  98.         delete pBounceWnd;      // HWND not created
  99.         return;
  100.     }
  101.     pBounceWnd->ShowWindow(SW_SHOW);
  102.     // the default PostNcDestroy handler will delete this object when destroyed
  103. }
  104.  
  105. // OnChildDestroy:
  106. // Example of a custom message handler (for the custom WM_CHILDDESTROY message)
  107. // This handler is triggered when a CBounceWnd or CHelloWnd destroys
  108. // itself -- the default implementation here does nothing but could
  109. // be customized to do additional work.
  110. //
  111. LONG CMainWindow::OnChildDestroy(UINT /*hWnd*/, LONG /* lParam */)
  112. {
  113.     return 0;
  114. }
  115.  
  116. // Destructor:
  117. // Destroy all existing child windows.
  118. //
  119. CMainWindow::~CMainWindow()
  120. {
  121.     delete m_pMenuInit;
  122. }
  123.  
  124. // OnExit:
  125. // Exit the application.
  126. //
  127. void CMainWindow::OnExit()
  128. {
  129.     DestroyWindow();
  130. }
  131.  
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CTheApp
  134.  
  135. // InitInstance:
  136. // Create and display the application main frame window
  137. //
  138. BOOL CTheApp::InitInstance()
  139. {
  140.     m_pMainWnd = new CMainWindow();
  141.     m_pMainWnd->ShowWindow(m_nCmdShow);
  142.     m_pMainWnd->UpdateWindow();
  143.     return TRUE;
  144. }
  145.