Annotation of mstools/mfc/samples/mdi/mdi.cpp, revision 1.1.1.1

1.1       root        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: { 
                     60:        m_pMenuInit = new CMenu();
                     61:        m_pMenuInit->LoadMenu("MdiMenuInit");
                     62:        CreateClient(lpCreateStruct, m_pMenuInit->GetSubMenu(0));
                     63: 
                     64:        return 0;
                     65: }
                     66: 
                     67: // OnAbout:
                     68: // Display this application's about box (defined in about.dlg).
                     69: //
                     70: void CMainWindow::OnAbout()
                     71: {
                     72:        CModalDialog about("AboutBox", this);
                     73:        about.DoModal();
                     74: }
                     75: 
                     76: // OnNewHello:
                     77: // Create a new Hello child window.
                     78: //
                     79: void CMainWindow::OnNewHello()
                     80: {
                     81:        CHelloWnd *pHelloWnd = new CHelloWnd;
                     82:        if (!pHelloWnd->Create("Hello", 0, rectDefault, this))
                     83:        {
                     84:                delete pHelloWnd;       // HWND not created
                     85:                return;
                     86:        }
                     87:        pHelloWnd->ShowWindow(SW_SHOW);
                     88:        // the default PostNcDestroy handler will delete this object when destroyed
                     89: }
                     90: 
                     91: // OnNewBounce:
                     92: // Create a new Bounce child window.
                     93: //
                     94: void CMainWindow::OnNewBounce()
                     95: {
                     96:        CBounceWnd *pBounceWnd = new CBounceWnd;
                     97:        if (!pBounceWnd->Create("Bounce", 0, rectDefault, this))
                     98:        {
                     99:                delete pBounceWnd;      // HWND not created
                    100:                return;
                    101:        }
                    102:        pBounceWnd->ShowWindow(SW_SHOW);
                    103:        // the default PostNcDestroy handler will delete this object when destroyed
                    104: }
                    105: 
                    106: // OnChildDestroy:
                    107: // Example of a custom message handler (for the custom WM_CHILDDESTROY message)
                    108: // This handler is triggered when a CBounceWnd or CHelloWnd destroys
                    109: // itself -- the default implementation here does nothing but could
                    110: // be customized to do additional work.
                    111: //
                    112: LONG CMainWindow::OnChildDestroy(UINT /*hWnd*/, LONG /* lParam */)
                    113: {
                    114:        return 0;
                    115: }
                    116: 
                    117: // Destructor:
                    118: // Destroy all existing child windows.
                    119: //
                    120: CMainWindow::~CMainWindow()
                    121: {
                    122:        delete m_pMenuInit;
                    123: }
                    124: 
                    125: // OnExit:
                    126: // Exit the application.
                    127: //
                    128: void CMainWindow::OnExit()
                    129: {
                    130:        DestroyWindow();
                    131: }
                    132: 
                    133: /////////////////////////////////////////////////////////////////////////////
                    134: // CTheApp
                    135: 
                    136: // InitInstance:
                    137: // Create and display the application main frame window
                    138: //
                    139: BOOL CTheApp::InitInstance()
                    140: {
                    141:        m_pMainWnd = new CMainWindow();
                    142:        m_pMainWnd->ShowWindow(m_nCmdShow);
                    143:        m_pMainWnd->UpdateWindow();
                    144:        return TRUE;
                    145: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.