home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / oclient / frame.cpp next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.9 KB  |  169 lines

  1. // frame.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.  
  14.  
  15. #include "stdafx.h"
  16. #include "oclient.h"
  17.  
  18. #include "frame.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_DYNAMIC(CMainFrame, CMDIFrameWnd)
  29.  
  30. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  31.     //{{AFX_MSG_MAP(CMainFrame)
  32.     ON_WM_CREATE()
  33.     ON_COMMAND(ID_WINDOW_TILE_HORZ, OnWindowTileHorz)
  34.     ON_WM_PALETTECHANGED()
  35.     ON_WM_QUERYNEWPALETTE()
  36.     //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // arrays of IDs used to initialize control bars
  41.  
  42. // toolbar buttons - IDs are command buttons
  43. static UINT BASED_CODE buttons[] =
  44. {
  45.     // same order as in the bitmap 'toolbar.bmp'
  46.     ID_FILE_NEW,
  47.     ID_FILE_OPEN,
  48.     ID_FILE_SAVE,
  49.         ID_SEPARATOR,
  50.     ID_EDIT_CUT,
  51.     ID_EDIT_COPY,
  52.     ID_EDIT_PASTE,
  53.         ID_SEPARATOR,
  54.     ID_FILE_PRINT,
  55.     ID_APP_ABOUT,
  56.     ID_CONTEXT_HELP,
  57. };
  58.  
  59. static UINT BASED_CODE indicators[] =
  60. {
  61.     ID_SEPARATOR,           // status line indicator
  62.     ID_INDICATOR_CAPS,
  63.     ID_INDICATOR_NUM,
  64.     ID_INDICATOR_SCRL,
  65. };
  66.  
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CMainFrame construction/destruction
  70.  
  71. CMainFrame::CMainFrame()
  72. {
  73. }
  74.  
  75. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  76. {
  77.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  78.         return -1;
  79.  
  80.     if (!m_wndToolBar.Create(this) ||
  81.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  82.         !m_wndToolBar.SetButtons(buttons,
  83.           sizeof(buttons)/sizeof(UINT)))
  84.     {
  85.         TRACE0("Failed to create toolbar\n");
  86.         return -1;      // fail to create
  87.     }
  88.  
  89.     if (!m_wndStatusBar.Create(this) ||
  90.         !m_wndStatusBar.SetIndicators(indicators,
  91.           sizeof(indicators)/sizeof(UINT)))
  92.     {
  93.         TRACE0("Failed to create status bar\n");
  94.         return -1;      // fail to create
  95.     }
  96.     EnableDocking(CBRS_ALIGN_ANY);
  97.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  98.     DockControlBar(&m_wndToolBar);
  99.     CDC* pDC = GetDC();
  100.     m_palette.CreateHalftonePalette(pDC);
  101.     ReleaseDC(pDC);
  102.     return 0;
  103. }
  104.  
  105. CMainFrame::~CMainFrame()
  106. {
  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.  
  123. #endif //_DEBUG
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CMainFrame commands
  127.  
  128. void CMainFrame::OnWindowTileHorz()
  129. {
  130.     if (GetKeyState(VK_SHIFT) < 0)
  131.         OnMDIWindowCmd(ID_WINDOW_TILE_VERT);
  132.     else
  133.         OnMDIWindowCmd(ID_WINDOW_TILE_HORZ);
  134. }
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CMainFrame message handlers
  138.  
  139. void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
  140. {
  141.     CMDIFrameWnd::OnPaletteChanged(pFocusWnd);
  142.     if (pFocusWnd != this)
  143.         SelectPalette(TRUE);
  144. }
  145.  
  146. BOOL CMainFrame::OnQueryNewPalette()
  147. {
  148.     if (CMDIFrameWnd::OnQueryNewPalette())
  149.         return TRUE;
  150.     return SelectPalette(FALSE);
  151. }
  152.  
  153. BOOL CMainFrame::SelectPalette(BOOL bBackground)
  154. {
  155.     if (m_palette.m_hObject == NULL)
  156.         return FALSE;
  157.  
  158.     CDC* pDC = GetDC();
  159.     CPalette* pOldPal = pDC->SelectPalette(&m_palette, bBackground);
  160.     UINT nPalChg = pDC->RealizePalette();
  161.     pDC->SelectPalette(pOldPal, TRUE); // background
  162.     ReleaseDC(pDC);
  163.  
  164.     if (nPalChg > 0)
  165.         InvalidateRect(NULL, TRUE);
  166.  
  167.     return TRUE;
  168. }
  169.