home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / docktool / mainfrm.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  18KB  |  522 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 "docktool.h"
  15. #include "tooldlg.h"
  16.  
  17. #include "mainfrm.h"
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMainFrame
  26.  
  27. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  28.  
  29. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  30.     //{{AFX_MSG_MAP(CMainFrame)
  31.     ON_WM_CREATE()
  32.     ON_COMMAND(ID_TOOLS_TOOLBAR, OnToolsToolbar)
  33.     ON_COMMAND(ID_BROWSE_CLASSGRAPH, OnMenuSelection)
  34.     ON_WM_CLOSE()
  35.     ON_COMMAND(ID_BROWSE_FILEOUTLINE, OnMenuSelection)
  36.     ON_COMMAND(ID_BROWSE_GOTODEFINITION, OnMenuSelection)
  37.     ON_COMMAND(ID_BROWSE_GOTOREFERENCE, OnMenuSelection)
  38.     ON_COMMAND(ID_BROWSE_REVERSECLASSGRAPH, OnMenuSelection)
  39.     ON_COMMAND(ID_DEBUG_CALLSTACK, OnMenuSelection)
  40.     ON_COMMAND(ID_DEBUG_DISASSEMBLY, OnMenuSelection)
  41.     ON_COMMAND(ID_DEBUG_LOCALS, OnMenuSelection)
  42.     ON_COMMAND(ID_DEBUG_MEMORY, OnMenuSelection)
  43.     ON_COMMAND(ID_DEBUG_QUICKWATCH, OnMenuSelection)
  44.     ON_COMMAND(ID_DEBUG_REGISTERS, OnMenuSelection)
  45.     ON_COMMAND(ID_DEBUG_RESTART, OnMenuSelection)
  46.     ON_COMMAND(ID_DEBUG_RUNTOCURSOR, OnMenuSelection)
  47.     ON_COMMAND(ID_DEBUG_STEPINTO, OnMenuSelection)
  48.     ON_COMMAND(ID_DEBUG_STEPOUT, OnMenuSelection)
  49.     ON_COMMAND(ID_DEBUG_STEPOVER, OnMenuSelection)
  50.     ON_COMMAND(ID_DEBUG_STOPDEBUGGING, OnMenuSelection)
  51.     ON_COMMAND(ID_DEBUG_WATCH, OnMenuSelection)
  52.     ON_COMMAND(ID_EDIT_BM_CLEARALL, OnMenuSelection)
  53.     ON_COMMAND(ID_EDIT_BM_NEXT, OnMenuSelection)
  54.     ON_COMMAND(ID_EDIT_BM_PREV, OnMenuSelection)
  55.     ON_COMMAND(ID_EDIT_BM_TOGGLE, OnMenuSelection)
  56.     ON_COMMAND(ID_EDIT_COPY, OnMenuSelection)
  57.     ON_COMMAND(ID_EDIT_CUT, OnMenuSelection)
  58.     ON_COMMAND(ID_EDIT_FINDINFILES, OnMenuSelection)
  59.     ON_COMMAND(ID_EDIT_INDENT, OnMenuSelection)
  60.     ON_COMMAND(ID_EDIT_PASTE, OnMenuSelection)
  61.     ON_COMMAND(ID_EDIT_UNDO, OnMenuSelection)
  62.     ON_COMMAND(ID_EDIT_UNINDENT, OnMenuSelection)
  63.     ON_COMMAND(ID_PALETTE_AIRBRUSH, OnMenuSelection)
  64.     ON_COMMAND(ID_PALETTE_BRUSH, OnMenuSelection)
  65.     ON_COMMAND(ID_PALETTE_ERASE, OnMenuSelection)
  66.     ON_COMMAND(ID_PALETTE_EYEDROP, OnMenuSelection)
  67.     ON_COMMAND(ID_PALETTE_FILL, OnMenuSelection)
  68.     ON_COMMAND(ID_PALETTE_FRAME, OnMenuSelection)
  69.     ON_COMMAND(ID_PALETTE_LINE, OnMenuSelection)
  70.     ON_COMMAND(ID_PALETTE_OVAL, OnMenuSelection)
  71.     ON_COMMAND(ID_PALETTE_PEN, OnMenuSelection)
  72.     ON_COMMAND(ID_PALETTE_RECTANGLE, OnMenuSelection)
  73.     ON_COMMAND(ID_PALETTE_SELECT, OnMenuSelection)
  74.     ON_COMMAND(ID_PALETTE_ZOOM, OnMenuSelection)
  75.     ON_COMMAND(ID_RESOURCE_NEWACCELERATORTABLE, OnMenuSelection)
  76.     ON_COMMAND(ID_RESOURCE_NEWBITMAP, OnMenuSelection)
  77.     ON_COMMAND(ID_RESOURCE_NEWCURSOR, OnMenuSelection)
  78.     ON_COMMAND(ID_RESOURCE_NEWICON, OnMenuSelection)
  79.     ON_COMMAND(ID_RESOURCE_NEWMENU, OnMenuSelection)
  80.     ON_COMMAND(ID_RESOURCE_NEWSTRINGTABLE, OnMenuSelection)
  81.     ON_COMMAND(ID_RESOURCE_NEWVERSION, OnMenuSelection)
  82.     ON_COMMAND(ID_EDIT_FIND, OnMenuSelection)
  83.     //}}AFX_MSG_MAP
  84.     // By making the Menu IDs that same as the ToolBar IDs
  85.     // we can leverage off of code that is already provided
  86.     // in MFCs implementation of CFrameWnd to check, uncheck
  87.     // show and hide toolbars.
  88.     ON_UPDATE_COMMAND_UI(IDW_BROWSE_BAR, OnUpdateControlBarMenu)
  89.     ON_COMMAND_EX(IDW_BROWSE_BAR, OnBarCheck)
  90.     ON_UPDATE_COMMAND_UI(IDW_DEBUG_BAR, OnUpdateControlBarMenu)
  91.     ON_COMMAND_EX(IDW_DEBUG_BAR, OnBarCheck)
  92.     ON_UPDATE_COMMAND_UI(IDW_EDIT_BAR, OnUpdateControlBarMenu)
  93.     ON_COMMAND_EX(IDW_EDIT_BAR, OnBarCheck)
  94.     ON_UPDATE_COMMAND_UI(IDW_PALETTE_BAR, OnUpdateControlBarMenu)
  95.     ON_COMMAND_EX(IDW_PALETTE_BAR, OnBarCheck)
  96.     ON_UPDATE_COMMAND_UI(IDW_RESOURCE_BAR, OnUpdateControlBarMenu)
  97.     ON_COMMAND_EX(IDW_RESOURCE_BAR, OnBarCheck)
  98. END_MESSAGE_MAP()
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // arrays of IDs used to initialize control bars
  102.  
  103. // toolbar buttons - IDs are command buttons
  104. static UINT BASED_CODE MainButtons[] =
  105. {
  106.     // same order as in the bitmap 'toolbar.bmp'
  107.     ID_FILE_NEW,
  108.     ID_FILE_OPEN,
  109.     ID_FILE_SAVE,
  110.         ID_SEPARATOR,
  111.     ID_EDIT_CUT,
  112.     ID_EDIT_COPY,
  113.     ID_EDIT_PASTE,
  114. };
  115. static UINT BASED_CODE ResourceButtons[] =
  116. {
  117.     // same order as in the bitmap 'toolbar.bmp'
  118.     ID_RESOURCE_NEWMENU,
  119.     ID_RESOURCE_NEWCURSOR,
  120.     ID_RESOURCE_NEWICON,
  121.     ID_RESOURCE_NEWBITMAP,
  122.     ID_RESOURCE_NEWSTRINGTABLE,
  123.     ID_RESOURCE_NEWACCELERATORTABLE,
  124.     ID_RESOURCE_NEWVERSION,
  125. };
  126. static UINT BASED_CODE DebugButtons[] =
  127. {
  128.     // same order as in the bitmap 'toolbar.bmp'
  129.     ID_DEBUG_RESTART,
  130.     ID_DEBUG_STOPDEBUGGING,
  131.     ID_DEBUG_STEPINTO,
  132.     ID_DEBUG_STEPOUT,
  133.     ID_DEBUG_STEPOVER,
  134.     ID_DEBUG_RUNTOCURSOR,
  135.     ID_DEBUG_QUICKWATCH,
  136.     ID_DEBUG_WATCH,
  137.     ID_DEBUG_LOCALS,
  138.     ID_DEBUG_REGISTERS,
  139.     ID_DEBUG_MEMORY,
  140.     ID_DEBUG_CALLSTACK,
  141.     ID_DEBUG_DISASSEMBLY,
  142. };
  143. static UINT BASED_CODE BrowseButtons[] =
  144. {
  145.     // same order as in the bitmap 'toolbar.bmp'
  146.     ID_BROWSE_GOTODEFINITION,
  147.     ID_BROWSE_GOTOREFERENCE,
  148.     ID_BROWSE_FILEOUTLINE,
  149.     ID_BROWSE_CLASSGRAPH,
  150.     ID_BROWSE_REVERSECLASSGRAPH,
  151. };
  152.  
  153. static UINT BASED_CODE PaletteButtons[] =
  154. {
  155.     // same order as in the bitmap 'toolbar.bmp'
  156.     ID_PALETTE_ERASE,
  157.     ID_PALETTE_PEN,
  158.     ID_PALETTE_SELECT,
  159.     ID_PALETTE_BRUSH,
  160.     ID_PALETTE_AIRBRUSH,
  161.     ID_PALETTE_FILL,
  162.     ID_PALETTE_LINE,
  163.     ID_PALETTE_EYEDROP,
  164.     ID_PALETTE_ZOOM,
  165.     ID_PALETTE_RECTANGLE,
  166.     ID_PALETTE_FRAME,
  167.     ID_PALETTE_OVAL,
  168. };
  169.  
  170. static UINT BASED_CODE indicators[] =
  171. {
  172.     ID_SEPARATOR,           // status line indicator
  173.     ID_INDICATOR_CAPS,
  174.     ID_INDICATOR_NUM,
  175.     ID_INDICATOR_SCRL,
  176. };
  177.  
  178. /////////////////////////////////////////////////////////////////////////////
  179. // Helpers for saving/restoring window state
  180.  
  181. static TCHAR BASED_CODE szSection[] = _T("Settings");
  182. static TCHAR BASED_CODE szWindowPos[] = _T("WindowPos");
  183. static TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  184.  
  185. static BOOL PASCAL NEAR ReadWindowPlacement(LPWINDOWPLACEMENT pwp)
  186. {
  187.     CString strBuffer = AfxGetApp()->GetProfileString(szSection, szWindowPos);
  188.     if (strBuffer.IsEmpty())
  189.         return FALSE;
  190.  
  191.     WINDOWPLACEMENT wp;
  192.     int nRead = _stscanf(strBuffer, szFormat,
  193.         &wp.flags, &wp.showCmd,
  194.         &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  195.         &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  196.         &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  197.         &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  198.  
  199.     if (nRead != 10)
  200.         return FALSE;
  201.  
  202.     wp.length = sizeof wp;
  203.     *pwp = wp;
  204.     return TRUE;
  205. }
  206.  
  207. static void PASCAL NEAR WriteWindowPlacement(LPWINDOWPLACEMENT pwp)
  208.     // write a window placement to settings section of app's ini file
  209. {
  210.     TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
  211.  
  212.     wsprintf(szBuffer, szFormat,
  213.         pwp->flags, pwp->showCmd,
  214.         pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  215.         pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  216.         pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  217.         pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  218.     AfxGetApp()->WriteProfileString(szSection, szWindowPos, szBuffer);
  219. }
  220.  
  221. /////////////////////////////////////////////////////////////////////////////
  222. // CMainFrame construction/destruction
  223.  
  224. CMainFrame::CMainFrame()
  225. {
  226. }
  227.  
  228. CMainFrame::~CMainFrame()
  229. {
  230. }
  231.  
  232. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  233. {
  234.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  235.         return -1;
  236.  
  237.     WINDOWPLACEMENT wp;
  238.     if (ReadWindowPlacement(&wp))
  239.         SetWindowPlacement(&wp);
  240.  
  241.     m_bColor = (AfxGetApp()->GetProfileInt(_T("General"),_T("Color"),1)!=0);
  242.     m_bToolTips = (AfxGetApp()->GetProfileInt(_T("General"),_T("ToolTips"),1)!=0);
  243.  
  244.     if (!m_wndMainBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  245.             CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_MAIN_BAR) ||
  246.         !m_wndMainBar.LoadBitmap(
  247.             (m_bColor)?IDR_COLOR_MAINBAR:IDR_MONO_MAINBAR) ||
  248.         !m_wndMainBar.SetButtons(MainButtons, sizeof(MainButtons)/sizeof(UINT)))
  249.     {
  250.         TRACE0("Failed to create mainbar\n");
  251.         return -1;      // fail to create
  252.     }
  253.     if (!m_wndResourceBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  254.             CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_RESOURCE_BAR) ||
  255.         !m_wndResourceBar.LoadBitmap(
  256.             (m_bColor)?IDR_COLOR_RESOURCEBAR:IDR_MONO_RESOURCEBAR) ||
  257.         !m_wndResourceBar.SetButtons(ResourceButtons, sizeof(ResourceButtons)/sizeof(UINT)))
  258.     {
  259.         TRACE0("Failed to create resourcebar\n");
  260.         return -1;      // fail to create
  261.     }
  262.     if (!m_wndDebugBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  263.             CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_DEBUG_BAR) ||
  264.         !m_wndDebugBar.LoadBitmap(
  265.             (m_bColor)?IDR_COLOR_DEBUGBAR:IDR_MONO_DEBUGBAR) ||
  266.         !m_wndDebugBar.SetButtons(DebugButtons, sizeof(DebugButtons)/sizeof(UINT)))
  267.     {
  268.         TRACE0("Failed to create debugbar\n");
  269.         return -1;      // fail to create
  270.     }
  271.     if (!m_wndEditBar.Init(this,m_bColor,m_bToolTips))
  272.     {
  273.         TRACE0("Failed to create editbar\n");
  274.         return -1;      // fail to create
  275.     }
  276.     if (!m_wndBrowseBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  277.             CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_BROWSE_BAR) ||
  278.         !m_wndBrowseBar.LoadBitmap(
  279.             (m_bColor)?IDR_COLOR_BROWSEBAR:IDR_MONO_BROWSEBAR) ||
  280.         !m_wndBrowseBar.SetButtons(BrowseButtons, sizeof(BrowseButtons)/sizeof(UINT)))
  281.     {
  282.         TRACE0("Failed to create browsebar\n");
  283.         return -1;      // fail to create
  284.     }
  285.  
  286.     if (!m_wndPaletteBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
  287.             CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_PALETTE_BAR) ||
  288.         !m_wndPaletteBar.LoadBitmap(
  289.             (m_bColor)?IDR_COLOR_PALETTEBAR:IDR_MONO_PALETTEBAR) ||
  290.         !m_wndPaletteBar.SetButtons(PaletteButtons, sizeof(PaletteButtons)/sizeof(UINT)))
  291.     {
  292.         TRACE0("Failed to create palettebar\n");
  293.         return -1;      // fail to create
  294.     }
  295.  
  296.     if (!m_wndStatusBar.Create(this) ||
  297.         !m_wndStatusBar.SetIndicators(indicators,
  298.           sizeof(indicators)/sizeof(UINT)))
  299.     {
  300.         TRACE0("Failed to create status bar\n");
  301.         return -1;      // fail to create
  302.     }
  303.  
  304.     m_wndMainBar.SetWindowText(_T("Standard"));
  305.     m_wndMainBar.EnableDocking(CBRS_ALIGN_ANY);
  306.  
  307.     m_wndResourceBar.SetWindowText(_T("Resource"));
  308.     m_wndResourceBar.EnableDocking(CBRS_ALIGN_ANY);
  309.  
  310.     m_wndDebugBar.SetWindowText(_T("Debug"));
  311.     m_wndDebugBar.EnableDocking(CBRS_ALIGN_ANY);
  312.  
  313.     m_wndEditBar.SetWindowText(_T("Edit"));
  314.     m_wndEditBar.EnableDocking(CBRS_ALIGN_ANY);
  315.  
  316.     m_wndBrowseBar.SetWindowText(_T("Browse"));
  317.     m_wndBrowseBar.EnableDocking(CBRS_ALIGN_ANY);
  318.  
  319.     m_wndPaletteBar.SetWindowText(_T("Palette"));
  320.     m_wndPaletteBar.EnableDocking(CBRS_ALIGN_ANY);
  321.  
  322.     EnableDocking(CBRS_ALIGN_ANY);
  323.  
  324.     DockControlBar(&m_wndMainBar,AFX_IDW_DOCKBAR_TOP);
  325.     DockControlBarLeftOf(&m_wndEditBar,&m_wndMainBar);
  326.     DockControlBarLeftOf(&m_wndBrowseBar,&m_wndEditBar);
  327.  
  328.     DockControlBar(&m_wndResourceBar,AFX_IDW_DOCKBAR_BOTTOM);
  329.     DockControlBarLeftOf(&m_wndDebugBar,&m_wndResourceBar);
  330.  
  331.     DockControlBar(&m_wndPaletteBar,AFX_IDW_DOCKBAR_RIGHT);
  332.  
  333.     // LoadBarState loads everything but the number of Columns in the Palette
  334.     // we need to do that ourseleves.
  335.     m_wndPaletteBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("Columns"),3));
  336.     LoadBarState(_T("General"));
  337.  
  338.     return 0;
  339. }
  340.  
  341. void CMainFrame::DockControlBarLeftOf(CToolBar* Bar,CToolBar* LeftOf)
  342. {
  343.     CRect rect;
  344.     DWORD dw;
  345.     UINT n;
  346.  
  347.     // get MFC to adjust the dimensions of all docked ToolBars
  348.     // so that GetWindowRect will be accurate
  349.     RecalcLayout();
  350.     LeftOf->GetWindowRect(&rect);
  351.     rect.OffsetRect(1,0);
  352.     dw=LeftOf->GetBarStyle();
  353.     n = 0;
  354.     n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
  355.     n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
  356.     n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
  357.     n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
  358.  
  359.     // When we take the default parameters on rect, DockControlBar will dock
  360.     // each Toolbar on a seperate line.  By calculating a rectangle, we in effect
  361.     // are simulating a Toolbar being dragged to that location and docked.
  362.     DockControlBar(Bar,n,&rect);
  363. }
  364.  
  365. /////////////////////////////////////////////////////////////////////////////
  366. // CMainFrame diagnostics
  367.  
  368. #ifdef _DEBUG
  369. void CMainFrame::AssertValid() const
  370. {
  371.     CFrameWnd::AssertValid();
  372. }
  373.  
  374. void CMainFrame::Dump(CDumpContext& dc) const
  375. {
  376.     CFrameWnd::Dump(dc);
  377. }
  378.  
  379. #endif //_DEBUG
  380.  
  381. /////////////////////////////////////////////////////////////////////////////
  382. // CMainFrame message handlers
  383.  
  384. void CMainFrame::OnToolsToolbar()
  385. {
  386.     CToolDlg ToolDlg;
  387.     UINT nColumns = m_wndPaletteBar.GetColumns();
  388.     nColumns = (nColumns < 4) ? nColumns - 2: 3;
  389.  
  390.     // If the style says the ToolBar is visible then it is visible.
  391.     ToolDlg.m_bMain = ((m_wndMainBar.GetStyle() & WS_VISIBLE) != 0);
  392.     ToolDlg.m_bResource = ((m_wndResourceBar.GetStyle() & WS_VISIBLE) != 0);
  393.     ToolDlg.m_bDebug = ((m_wndDebugBar.GetStyle() & WS_VISIBLE) != 0);
  394.     ToolDlg.m_bEdit = ((m_wndEditBar.GetStyle() & WS_VISIBLE) != 0);
  395.     ToolDlg.m_bBrowse = ((m_wndBrowseBar.GetStyle() & WS_VISIBLE) != 0);
  396.     ToolDlg.m_bPalette = ((m_wndPaletteBar.GetStyle() & WS_VISIBLE) != 0);
  397.  
  398.     ToolDlg.m_nColumns = nColumns;
  399.  
  400.     ToolDlg.m_nColor = (m_bColor) ? 0 : 1;
  401.     ToolDlg.m_nToolTips = (m_bToolTips) ? 0 : 1;
  402.  
  403.     if (IDOK == ToolDlg.DoModal())
  404.     {
  405.         ShowControlBar(&m_wndMainBar, ToolDlg.m_bMain, FALSE);
  406.         ShowControlBar(&m_wndResourceBar, ToolDlg.m_bResource, FALSE);
  407.         ShowControlBar(&m_wndDebugBar, ToolDlg.m_bDebug, FALSE);
  408.         ShowControlBar(&m_wndEditBar, ToolDlg.m_bEdit, FALSE);
  409.         ShowControlBar(&m_wndBrowseBar, ToolDlg.m_bBrowse, FALSE);
  410.         ShowControlBar(&m_wndPaletteBar, ToolDlg.m_bPalette, FALSE);
  411.         m_bToolTips = (ToolDlg.m_nToolTips==0);
  412.         if (m_bToolTips)
  413.         {
  414.             m_wndMainBar.SetBarStyle(m_wndMainBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  415.             m_wndResourceBar.SetBarStyle(m_wndResourceBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  416.             m_wndDebugBar.SetBarStyle(m_wndDebugBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  417.             m_wndEditBar.SetBarStyle(m_wndEditBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  418.             m_wndBrowseBar.SetBarStyle(m_wndBrowseBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  419.             m_wndPaletteBar.SetBarStyle(m_wndPaletteBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  420.         }
  421.         else
  422.         {
  423.             m_wndMainBar.SetBarStyle(m_wndMainBar.GetBarStyle() & ~(CBRS_TOOLTIPS | CBRS_FLYBY));
  424.             m_wndResourceBar.SetBarStyle(m_wndResourceBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  425.             m_wndDebugBar.SetBarStyle(m_wndDebugBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  426.             m_wndEditBar.SetBarStyle(m_wndEditBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  427.             m_wndBrowseBar.SetBarStyle(m_wndBrowseBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  428.             m_wndPaletteBar.SetBarStyle(m_wndPaletteBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  429.         }
  430.         nColumns = (ToolDlg.m_nColumns < 3) ? ToolDlg.m_nColumns + 2 : 6;
  431.         m_wndPaletteBar.SetColumns(nColumns);
  432.  
  433.         m_bColor = (ToolDlg.m_nColor==0);
  434.  
  435.         if (m_bColor)
  436.         {
  437.             m_wndMainBar.LoadBitmap(IDR_COLOR_MAINBAR);
  438.             m_wndResourceBar.LoadBitmap(IDR_COLOR_RESOURCEBAR);
  439.             m_wndDebugBar.LoadBitmap(IDR_COLOR_DEBUGBAR);
  440.             m_wndBrowseBar.LoadBitmap(IDR_COLOR_BROWSEBAR);
  441.             m_wndPaletteBar.LoadBitmap(IDR_COLOR_PALETTEBAR);
  442.         }
  443.         else
  444.         {
  445.             m_wndMainBar.LoadBitmap(IDR_MONO_MAINBAR);
  446.             m_wndResourceBar.LoadBitmap(IDR_MONO_RESOURCEBAR);
  447.             m_wndDebugBar.LoadBitmap(IDR_MONO_DEBUGBAR);
  448.             m_wndBrowseBar.LoadBitmap(IDR_MONO_BROWSEBAR);
  449.             m_wndPaletteBar.LoadBitmap(IDR_MONO_PALETTEBAR);
  450.         }
  451.         m_wndEditBar.SetColor(m_bColor);
  452.  
  453.         m_wndMainBar.Invalidate();
  454.         m_wndResourceBar.Invalidate();
  455.         m_wndDebugBar.Invalidate();
  456.         m_wndBrowseBar.Invalidate();
  457.         m_wndPaletteBar.Invalidate();
  458.         m_wndEditBar.Invalidate();
  459.     }
  460. }
  461.  
  462. void CMainFrame::OnMenuSelection()
  463. {
  464.     // This sample doesn't do anything with button presses but a command handler
  465.     // needs to be present for MFC to enable the buttons
  466. }
  467.  
  468. void CMainFrame::OnClose()
  469. {
  470.     // SaveBarState saves everything but the number of Columns in the Palette
  471.     // we need to do that ourseleves.
  472.     SaveBarState(_T("General"));
  473.     AfxGetApp()->WriteProfileInt(
  474.         _T("General"),_T("Columns"),m_wndPaletteBar.GetColumns());
  475.     AfxGetApp()->WriteProfileInt(
  476.         _T("General"),_T("Color"),(m_bColor!=0));
  477.     AfxGetApp()->WriteProfileInt(
  478.         _T("General"),_T("ToolTips"),(m_bToolTips!=0));
  479.  
  480.     WINDOWPLACEMENT wp;
  481.     wp.length = sizeof wp;
  482.     if (GetWindowPlacement(&wp))
  483.     {
  484.         wp.flags = 0;
  485.         if (IsZoomed())
  486.             wp.flags |= WPF_RESTORETOMAXIMIZED;
  487.         // and write it to the .INI file
  488.         WriteWindowPlacement(&wp);
  489.     }
  490.     CFrameWnd::OnClose();
  491. }
  492.  
  493. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  494. {
  495.     if (pMsg->message == WM_RBUTTONDOWN)
  496.     {
  497.         CWnd* pWnd = CWnd::FromHandlePermanent(pMsg->hwnd);
  498.         CControlBar* pBar = DYNAMIC_DOWNCAST(CControlBar, pWnd);
  499.  
  500.         if (pBar != NULL)
  501.          {
  502.             CMenu Menu;
  503.             CPoint pt;
  504.  
  505.             pt.x = LOWORD(pMsg->lParam);
  506.             pt.y = HIWORD(pMsg->lParam);
  507.             pBar->ClientToScreen(&pt);
  508.  
  509.             if (Menu.LoadMenu(IDR_TOOLBAR))
  510.             {
  511.                 CMenu* pSubMenu = Menu.GetSubMenu(0);
  512.  
  513.                 if (pSubMenu!=NULL)
  514.                 {
  515.                     pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,pt.x,pt.y,this);
  516.                 }
  517.             }
  518.         }
  519.     }
  520.     return CFrameWnd::PreTranslateMessage(pMsg);
  521. }
  522.