home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / advanced / cube / mainfrm.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  143 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 "cube.h"
  15.  
  16. #include "cubedoc.h"
  17. #include "cubeview.h"
  18. #include "mainfrm.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMainFrame
  27.  
  28. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  29.  
  30. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  31.     //{{AFX_MSG_MAP(CMainFrame)
  32.     ON_WM_CREATE()
  33.     ON_WM_PALETTECHANGED()
  34.     ON_WM_QUERYNEWPALETTE()
  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_PLAY,
  46.     ID_APP_ABOUT,
  47. };
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CMainFrame construction/destruction
  51.  
  52. CMainFrame::CMainFrame()
  53. {
  54.     // TODO: add member initialization code here
  55.  
  56. }
  57.  
  58. CMainFrame::~CMainFrame()
  59. {
  60. }
  61.  
  62. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  63. {
  64.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  65.         return -1;
  66.  
  67.     if (!m_wndToolBar.Create(this) ||
  68.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  69.         !m_wndToolBar.SetButtons(buttons,
  70.           sizeof(buttons)/sizeof(UINT)))
  71.     {
  72.         TRACE0("Failed to create toolbar\n");
  73.         return -1;      // fail to create
  74.     }
  75.  
  76.     // TODO: Delete these three lines if you don't want the toolbar to
  77.     //  be dockable
  78.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  79.     EnableDocking(CBRS_ALIGN_ANY);
  80.     DockControlBar(&m_wndToolBar);
  81.  
  82.     // TODO: Remove this if you don't want tool tips
  83.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  84.         CBRS_TOOLTIPS | CBRS_FLYBY);
  85.  
  86.     return 0;
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CMainFrame diagnostics
  91.  
  92. #ifdef _DEBUG
  93. void CMainFrame::AssertValid() const
  94. {
  95.     CFrameWnd::AssertValid();
  96. }
  97.  
  98. void CMainFrame::Dump(CDumpContext& dc) const
  99. {
  100.     CFrameWnd::Dump(dc);
  101. }
  102.  
  103. #endif //_DEBUG
  104.  
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CMainFrame message handlers
  107.  
  108. void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
  109. {
  110.     CFrameWnd::OnPaletteChanged(pFocusWnd);
  111.  
  112.     if(pFocusWnd != this)
  113.         OnQueryNewPalette();
  114. }
  115.  
  116. BOOL CMainFrame::OnQueryNewPalette()
  117. {
  118.     WORD        i;
  119.     CPalette    *pOldPal;
  120.     CCubeView   *pView = (CCubeView *)GetActiveView();
  121.     CClientDC   dc(pView);
  122.  
  123.  
  124.     pOldPal = dc.SelectPalette(&pView->m_cPalette, FALSE);
  125.     i = dc.RealizePalette();
  126.     dc.SelectPalette(pOldPal, FALSE);
  127.  
  128.     if(i > 0)
  129.         InvalidateRect(NULL);
  130.  
  131.  
  132.     return CFrameWnd::OnQueryNewPalette();
  133. }
  134.  
  135. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  136. {
  137.     // remove this flag to remove " - Untitled" from the frame's caption
  138.  
  139.     cs.style &= ~ FWS_ADDTOTITLE;
  140.  
  141.     return CFrameWnd::PreCreateWindow(cs);
  142. }
  143.