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

  1. // CMainFrame.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "StdAfx.H"
  5. #include "TestCon.H"
  6. #include "Resource.hm"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CMainFrame
  16.  
  17. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  18.  
  19. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  20.    //{{AFX_MSG_MAP(CMainFrame)
  21.    ON_WM_CREATE()
  22.    ON_WM_DESTROY()
  23.    ON_COMMAND(ID_VIEW_MACROBAR, OnViewMacroBar)
  24.    ON_UPDATE_COMMAND_UI(ID_VIEW_MACROBAR, OnUpdateViewMacroBar)
  25.     //}}AFX_MSG_MAP
  26.    ON_COMMAND( ID_HELP_FINDER, CFrameWnd::OnHelpFinder )
  27.    ON_COMMAND( ID_HELP, CFrameWnd::OnHelp )
  28.    ON_COMMAND( ID_CONTEXT_HELP, CFrameWnd::OnContextHelp )
  29.    ON_COMMAND( ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder )
  30. END_MESSAGE_MAP()
  31.  
  32. static UINT indicators[] =
  33. {
  34.    ID_SEPARATOR,  // Status line indicator
  35.    ID_SEPARATOR,  // Activation state
  36.    ID_SEPARATOR,  // Windowed/windowless state
  37.    ID_INDICATOR_CAPS,
  38.    ID_INDICATOR_NUM,
  39.    ID_INDICATOR_SCRL,
  40. };
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CMainFrame construction/destruction
  44.  
  45. CMainFrame::CMainFrame()
  46. {
  47. }
  48.  
  49. CMainFrame::~CMainFrame()
  50. {
  51. }
  52.  
  53. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  54. {
  55.    CString strOutputWindowTitle;
  56.    UINT nID;
  57.    UINT nStyle;
  58.    int nWidth;
  59.  
  60.    if( CFrameWnd::OnCreate( lpCreateStruct ) == -1 )
  61.    {
  62.       return( -1 );
  63.    }
  64.  
  65.    if( !m_wndStatusBar.Create( this ) || !m_wndStatusBar.SetIndicators(
  66.       indicators, sizeof( indicators )/sizeof( UINT ) ) )
  67.    {
  68.       TRACE( "Failed to create status bar\n" );
  69.       return( -1 );
  70.    }
  71.  
  72.    // Shrink the windowed/windowless and activation state status bar panes to a
  73.    // more reasonable size
  74.    m_wndStatusBar.GetPaneInfo( 1, nID, nStyle, nWidth );
  75.    m_wndStatusBar.SetPaneInfo( 1, nID, nStyle, nWidth/3 );
  76.  
  77.    m_wndStatusBar.GetPaneInfo( 2, nID, nStyle, nWidth );
  78.    m_wndStatusBar.SetPaneInfo( 2, nID, nStyle, nWidth/3 );
  79.  
  80.    // Start out assuming that the latest comctl32.dll is installed
  81.    BOOL bHaveIE40 = TRUE;
  82.  
  83.    // Create the rebar. If the creation goes through then
  84.    // add an instance of a CReToolBar to the rebar
  85.    if( !m_wndReBar.Create( this ) )
  86.    {
  87.       TRACE( "Failed to create rebar\n" );
  88.       bHaveIE40 = FALSE;
  89.    }
  90.  
  91.    // Create the toolbar
  92.    if( !m_wndToolBar.CreateEx( this, TBSTYLE_FLAT, WS_CHILD|WS_VISIBLE|
  93.       CBRS_ALIGN_TOP|CBRS_TOOLTIPS|CBRS_FLYBY ) || !m_wndToolBar.LoadToolBar(
  94.       IDR_MAINFRAME ) )
  95.    {
  96.       TRACE( "Failed to create toolbar\n" );
  97.       return( -1 );
  98.    }
  99.  
  100.    if( !m_wndMacroBar.Create( this, CBRS_SIZE_FIXED, IDC_MACROBAR ) )
  101.    {
  102.       TRACE( "Failed to create macro bar\n" );
  103.       return( -1 );
  104.    }
  105.  
  106.    if( bHaveIE40 ) // Do the rebar
  107.    {
  108.       if( !m_wndReBar.AddBar( &m_wndToolBar ) )
  109.       {
  110.          TRACE( "Failed to add toolbar to rebar\n" );
  111.          return( -1 );
  112.       }
  113.       if( !m_wndReBar.AddBar( &m_wndMacroBar ) )
  114.       {
  115.          TRACE( "Failed to add macro bar to rebar\n" );
  116.          return( -1 );
  117.       }
  118.  
  119.       EnableDocking( CBRS_ALIGN_ANY );
  120.    }
  121.    else  // Do a regular toolbar
  122.    {
  123.       m_wndToolBar.EnableDocking( CBRS_ORIENT_VERT|CBRS_ALIGN_TOP );
  124.       m_wndMacroBar.EnableDocking( CBRS_ORIENT_VERT|CBRS_ALIGN_TOP );
  125.  
  126.       EnableDocking( CBRS_ALIGN_ANY );
  127.       DockControlBar( &m_wndToolBar );
  128.       DockControlBar( &m_wndMacroBar );
  129.    }
  130.  
  131.    return( 0 );
  132. }
  133.  
  134. BOOL CMainFrame::PreCreateWindow( CREATESTRUCT& cs )
  135. {
  136.    return( CFrameWnd::PreCreateWindow( cs ) );
  137. }
  138.  
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CMainFrame diagnostics
  141.  
  142. #ifdef _DEBUG
  143. void CMainFrame::AssertValid() const
  144. {
  145.    CFrameWnd::AssertValid();
  146. }
  147.  
  148. void CMainFrame::Dump(CDumpContext& dc) const
  149. {
  150.    CFrameWnd::Dump(dc);
  151. }
  152.  
  153. #endif //_DEBUG
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CMainFrame message handlers
  157.  
  158. void CMainFrame::OnDestroy()
  159. {
  160.    CFrameWnd::OnDestroy();
  161. }
  162.  
  163. void CMainFrame::OnViewMacroBar()
  164. {
  165.    CControlBar* pControlBar;
  166.  
  167.    pControlBar = GetControlBar( IDC_MACROBAR );
  168.    if( pControlBar != NULL )
  169.    {
  170.       ShowControlBar( pControlBar, (pControlBar->GetStyle()&WS_VISIBLE) == 0,
  171.          FALSE );
  172.    }
  173. }
  174.  
  175. void CMainFrame::OnUpdateViewMacroBar( CCmdUI* pCmdUI )
  176. {
  177.    CControlBar* pControlBar;
  178.  
  179.    pControlBar = GetControlBar( IDC_MACROBAR );
  180.    if( pControlBar != NULL )
  181.    {
  182.       pCmdUI->SetCheck( (pControlBar->GetStyle()&WS_VISIBLE) != 0 );
  183.    }
  184. }
  185.  
  186. BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /* pcs */,
  187.    CCreateContext* pContext )
  188. {
  189.    CSize size;
  190.    CRect rect;
  191.  
  192.    GetClientRect( &rect );
  193.    size = rect.Size();
  194.  
  195.    // Create a static splitter with two panes.  The top pane is the actual
  196.    // CTestContainer98View, and the bottom pane is the output window.
  197.    m_wndSplitter.CreateStatic( this, 2, 1 );
  198.    m_wndSplitter.CreateView( 0, 0, RUNTIME_CLASS( CTestContainer98View ),
  199.       CSize( size.cx, 2*size.cy/3 ), pContext );
  200.    m_wndSplitter.CreateView( 1, 0, RUNTIME_CLASS( COutputWindowView ), CSize(
  201.       size.cx, size.cy-(2*size.cy/3) ), pContext );
  202.  
  203.    return( TRUE );
  204. }
  205.  
  206. BOOL CMainFrame::OnCmdMsg( UINT nID, int nCode, void* pExtra,
  207.    AFX_CMDHANDLERINFO* pHandlerInfo )
  208. {
  209.    BOOL tHandled;
  210.    CWnd* pView;
  211.  
  212.    // First, try the default routing scheme.
  213.    tHandled = CFrameWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
  214.    if( tHandled )
  215.    {
  216.       return( TRUE );
  217.    }
  218.  
  219.    // If nobody handled it, and the main view isn't active, try the main view.
  220.    pView = m_wndSplitter.GetPane( 0, 0 );
  221.    if( pView != GetActiveView() )
  222.    {
  223.       tHandled = pView->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
  224.       if( tHandled )
  225.       {
  226.          return( TRUE );
  227.       }
  228.    }
  229.  
  230.    return( FALSE );
  231. }
  232.