home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / propdlg / mainfrm.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  4KB  |  173 lines

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 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 related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "propdlg.h"
  15. #include "colorpge.h"
  16. #include "stylepge.h"
  17. #include "shapeobj.h"
  18. #include "preview.h"
  19. #include "propsht.h"
  20. #include "propsht2.h"
  21. #include "minifrm.h"
  22. #include "resource.h"
  23. #include "mainfrm.h"
  24. #include "shapedoc.h"
  25. #include "shapesvw.h"
  26.  
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMainFrame
  34.  
  35. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  36.  
  37. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  38.     //{{AFX_MSG_MAP(CMainFrame)
  39.     ON_WM_CREATE()
  40.     ON_COMMAND(ID_MINI_FRAME_PROPERTY_SHEET, OnMiniFramePropertySheet)
  41.     ON_UPDATE_COMMAND_UI(ID_MINI_FRAME_PROPERTY_SHEET, OnUpdateMiniFramePropertySheet)
  42.     //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // arrays of IDs used to initialize control bars
  47.  
  48. // toolbar buttons - IDs are command buttons
  49. static UINT BASED_CODE buttons[] =
  50. {
  51.     // same order as in the bitmap 'toolbar.bmp'
  52.     ID_FILE_NEW,
  53.     ID_FILE_OPEN,
  54.     ID_FILE_SAVE,
  55.         ID_SEPARATOR,
  56.     ID_EDIT_CUT,
  57.     ID_EDIT_COPY,
  58.     ID_EDIT_PASTE,
  59.         ID_SEPARATOR,
  60.     ID_FILE_PRINT,
  61.     ID_APP_ABOUT,
  62. };
  63.  
  64. static UINT BASED_CODE indicators[] =
  65. {
  66.     ID_SEPARATOR,           // status line indicator
  67.     ID_INDICATOR_CAPS,
  68.     ID_INDICATOR_NUM,
  69.     ID_INDICATOR_SCRL,
  70. };
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CMainFrame construction/destruction
  74.  
  75. CMainFrame::CMainFrame()
  76. {
  77.     m_pShapePropFrame = NULL;
  78. }
  79.  
  80. CMainFrame::~CMainFrame()
  81. {
  82. }
  83.  
  84. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  85. {
  86.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  87.         return -1;
  88.  
  89.     if (!m_wndToolBar.Create(this) ||
  90.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  91.         !m_wndToolBar.SetButtons(buttons,
  92.           sizeof(buttons)/sizeof(UINT)))
  93.     {
  94.         TRACE0("Failed to create toolbar\n");
  95.         return -1;      // fail to create
  96.     }
  97.  
  98.     if (!m_wndStatusBar.Create(this) ||
  99.         !m_wndStatusBar.SetIndicators(indicators,
  100.           sizeof(indicators)/sizeof(UINT)))
  101.     {
  102.         TRACE0("Failed to create status bar\n");
  103.         return -1;      // fail to create
  104.     }
  105.  
  106.     return 0;
  107. }
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CMainFrame diagnostics
  111.  
  112. #ifdef _DEBUG
  113. void CMainFrame::AssertValid() const
  114. {
  115.     CMDIFrameWnd::AssertValid();
  116. }
  117.  
  118. void CMainFrame::Dump(CDumpContext& dc) const
  119. {
  120.     CMDIFrameWnd::Dump(dc);
  121. }
  122. #endif //_DEBUG
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125. // CMainFrame message handlers
  126.  
  127. void CMainFrame::OnMiniFramePropertySheet()
  128. {
  129.     // If mini frame does not already exist, create a new one.
  130.     // Otherwise, unhide it
  131.  
  132.     if (m_pShapePropFrame == NULL)
  133.     {
  134.         m_pShapePropFrame = new CShapePropSheetFrame;
  135.         CRect rect(0, 0, 0, 0);
  136.         CString strTitle;
  137.         strTitle.LoadString(IDS_OBJECT_PROPERTIES);
  138.         if (!m_pShapePropFrame->Create(NULL, strTitle,
  139.             WS_POPUP | WS_CAPTION | WS_SYSMENU, rect, this))
  140.         {
  141.             m_pShapePropFrame = NULL;
  142.             return;
  143.         }
  144.         m_pShapePropFrame->CenterWindow();
  145.     }
  146.  
  147.     // Before unhiding the modeless property sheet, update its
  148.     // settings to reflect the currently selected shape.
  149.     CShapesView* pView =
  150.         STATIC_DOWNCAST(CShapesView, MDIGetActive()->GetActiveView());
  151.     ASSERT_VALID(pView);
  152.     if (pView->m_pShapeSelected != NULL)
  153.     {
  154.        m_pShapePropFrame->m_pModelessShapePropSheet->
  155.            SetSheetPropsFromShape(pView->m_pShapeSelected);
  156.     }
  157.  
  158.     if (m_pShapePropFrame != NULL && !m_pShapePropFrame->IsWindowVisible())
  159.         m_pShapePropFrame->ShowWindow(SW_SHOW);
  160. }
  161.  
  162. void CMainFrame::OnUpdateMiniFramePropertySheet(CCmdUI* pCmdUI)
  163. {
  164.     pCmdUI->Enable(m_pShapePropFrame == NULL
  165.         || !m_pShapePropFrame->IsWindowVisible());
  166. }
  167.  
  168. void CMainFrame::HideModelessPropSheet()
  169. {
  170.     if (m_pShapePropFrame != NULL)
  171.         m_pShapePropFrame->ShowWindow(SW_HIDE);
  172. }
  173.