home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SAMPLES / VBCHART / MAINFRM.CP_ / MAINFRM.CP
Encoding:
Text File  |  1993-02-08  |  4.3 KB  |  176 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 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 and/or WinHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14.  
  15. #include "stdafx.h"
  16. #include "vbchart.h"
  17.  
  18. #include "mainfrm.h"
  19. #include "chartdoc.h"
  20. #include "chartvw.h"    // for different chart types
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CMainFrame
  29.  
  30. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  31.  
  32. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  33.     //{{AFX_MSG_MAP(CMainFrame)
  34.     ON_WM_CREATE()
  35.     //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // arrays of IDs used to initialize control bars
  40.  
  41. // toolbar buttons - IDs are command buttons
  42. static UINT BASED_CODE buttons[] =
  43. {
  44.     // same order as in the bitmap 'toolbar.bmp'
  45.     ID_FILE_NEW,
  46.     ID_FILE_OPEN,
  47.     ID_FILE_SAVE,
  48.         ID_SEPARATOR,
  49.     ID_FILE_PRINT,
  50.     ID_APP_ABOUT,
  51.         ID_SEPARATOR,
  52.         ID_SEPARATOR        // Index 7, Will be location for DropList
  53. };
  54. #define INDEX_DROPLIST 7
  55.  
  56. struct CHART_TYPES
  57. {
  58.     char*   pType;
  59.     int     nType;
  60. };
  61.  
  62. static CHART_TYPES chartNames[] =
  63. {
  64.     "3D Vert Bar",      CHART_3DVBAR,
  65.     "Line",             CHART_LINE, 
  66.     "Bar (Vertical)",   CHART_VBAR, 
  67.     "Bar (Horizontal)", CHART_HBAR, 
  68.     "3D Horiz Bar",     CHART_3DHBAR,
  69.     "Gantt (Vertical)", CHART_VGANTT,   
  70.     "Gantt (Horizontal)", CHART_HGANTT, 
  71.     NULL,               0
  72. };
  73.  
  74. static UINT BASED_CODE indicators[] =
  75. {
  76.     ID_SEPARATOR,           // status line indicator
  77.     ID_INDICATOR_CAPS,
  78.     ID_INDICATOR_NUM,
  79.     ID_INDICATOR_SCRL,
  80. };
  81.  
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CMainFrame construction/destruction
  84.  
  85. CMainFrame::CMainFrame()
  86. {
  87. }
  88.  
  89. CMainFrame::~CMainFrame()
  90. {
  91. }
  92.  
  93. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  94. {
  95.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  96.         return -1;
  97.  
  98.     if (!m_wndToolBar.Create(this) ||
  99.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  100.         !m_wndToolBar.SetButtons(buttons,
  101.           sizeof(buttons)/sizeof(UINT)))
  102.     {
  103.         TRACE("Failed to create toolbar\n");
  104.         return -1;      // fail to create
  105.     }
  106.  
  107.     CRect rect;
  108.     m_wndToolBar.GetItemRect(INDEX_DROPLIST, &rect);
  109.     int cyFit = rect.Height();
  110.     rect.top = 1;   // 1 pixel down from top of statusbar
  111.     rect.right = rect.left + 150;
  112.     rect.bottom = rect.top + 200;       // drop height
  113.  
  114.     if (!m_cboxDrop.Create(
  115.         WS_CHILD|WS_BORDER|WS_VISIBLE|CBS_DROPDOWNLIST|CBS_SORT,
  116.         rect, &m_wndToolBar, IDC_CHARTLIST))
  117.     {
  118.         TRACE("Failed to create combobox inside toolbar\n");
  119.         return -1;      // fail to create
  120.     }
  121.  
  122.     // load status bar font
  123.     LOGFONT logfont;
  124.     memset(&logfont, 0, sizeof(logfont));
  125.  
  126.     // 13 pixel high Sans Serif font
  127.     logfont.lfHeight = -13;
  128.     logfont.lfWeight = FW_NORMAL;
  129.     logfont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
  130.     static char BASED_CODE szFaceName[] = "MS Sans Serif";
  131.     lstrcpy(logfont.lfFaceName, szFaceName);
  132.  
  133.     if (m_fontDrop.CreateFontIndirect(&logfont))
  134.     {
  135.         m_cboxDrop.SetFont(&m_fontDrop, FALSE);
  136.                 // no need to redraw since invisible
  137.     }
  138.  
  139.     for (CHART_TYPES* pType = chartNames; pType->pType != NULL; pType++)
  140.     {
  141.         int index = m_cboxDrop.AddString(pType->pType);
  142.         m_cboxDrop.SetItemData(index, pType->nType);
  143.     }
  144.  
  145.     m_cboxDrop.SelectString(-1, chartNames[0].pType);
  146.  
  147.     if (!m_wndStatusBar.Create(this) ||
  148.         !m_wndStatusBar.SetIndicators(indicators,
  149.           sizeof(indicators)/sizeof(UINT)))
  150.     {
  151.         TRACE("Failed to create status bar\n");
  152.         return -1;      // fail to create
  153.     }
  154.  
  155.     return 0;
  156. }
  157.  
  158.  
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CMainFrame diagnostics
  161.  
  162. #ifdef _DEBUG
  163. void CMainFrame::AssertValid() const
  164. {
  165.     CMDIFrameWnd::AssertValid();
  166. }
  167.  
  168. void CMainFrame::Dump(CDumpContext& dc) const
  169. {
  170.     CMDIFrameWnd::Dump(dc);
  171. }
  172.  
  173. #endif //_DEBUG
  174.  
  175. /////////////////////////////////////////////////////////////////////////////
  176.