home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c05 / dlgbars / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.4 KB  |  134 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "DlgBars.h"
  6.  
  7. #include "MainFrm.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMainFrame
  17.  
  18. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  19.  
  20. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  21.     //{{AFX_MSG_MAP(CMainFrame)
  22.     ON_WM_CREATE()
  23.     ON_COMMAND(ID_VIEW_MYDIALOGBAR, OnViewDialogbar)
  24.     ON_UPDATE_COMMAND_UI(ID_VIEW_MYDIALOGBAR, OnUpdateViewDialogbar)
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. static UINT indicators[] =
  29. {
  30.     ID_SEPARATOR,           // status line indicator
  31.     ID_INDICATOR_CAPS,
  32.     ID_INDICATOR_NUM,
  33.     ID_INDICATOR_SCRL
  34. };
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMainFrame construction/destruction
  38.  
  39. CMainFrame::CMainFrame()
  40. {
  41. }
  42.  
  43. CMainFrame::~CMainFrame()
  44. {
  45. }
  46.  
  47. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  48. {
  49.     return CFrameWnd::PreCreateWindow(cs);
  50. }
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMainFrame diagnostics
  54.  
  55. #ifdef _DEBUG
  56. void CMainFrame::AssertValid() const
  57. {
  58.     CFrameWnd::AssertValid();
  59. }
  60.  
  61. void CMainFrame::Dump(CDumpContext& dc) const
  62. {
  63.     CFrameWnd::Dump(dc);
  64. }
  65.  
  66. #endif //_DEBUG
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CMainFrame message handlers
  70.  
  71. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  72. {
  73.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  74.         return -1;
  75.  
  76.     if (!m_wndStatusBar.Create(this) ||
  77.         !m_wndStatusBar.SetIndicators(indicators,
  78.           sizeof(indicators)/sizeof(UINT)))
  79.     {
  80.         TRACE0("Failed to create status bar\n");
  81.         return -1;      // fail to create
  82.     }
  83.  
  84. // Everything from here to end of this function was added to 
  85. // create and initialize the dialog bar.
  86.     EnableDocking(CBRS_ALIGN_ANY);
  87.  
  88.      // Programmer coded this to provide a Dialog Bar for the application.
  89.     // The first 32 IDs for CMainFrame should not be used, hence the 33.
  90.     // See comments in afxres.h and TN 31.
  91.     if (! m_wndDialogBar.Create(this, IDD_DIALOG_BAR, 
  92.                     CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY,
  93.                     ID_VIEW_MYDIALOGBAR))
  94.     {
  95.         TRACE0("Failed to create dialog bar m_wndDialogBar\n");
  96.         return -1; // fail to create
  97.     }
  98.  
  99.     // Command buttons on a Dialog Bar work properly just by having the
  100.     // same command ID as the corresponding menu item. 
  101.     // In this way they behave like toolbar icons.
  102.  
  103.     // Icons, however, must also have their Notify properties set. 
  104.     // Then they behave like ordinary toolbar icons.
  105.  
  106.     // Being a combo box, IDC_LIST_COLORS was populated at design time
  107.     // The combo box has its command handler in the view class which
  108.     // facilitates access to the document class. See the view class, and
  109.     // in particular its message map, for details.
  110.     CComboBox * p_lb = (CComboBox *)m_wndDialogBar.GetDlgItem(IDC_LIST_COLORS);
  111.     p_lb->SetCurSel(0);
  112.  
  113.     // Also, an entry was added to the string table to so that tooltips
  114.     // will be shown whenever the mouse cursor is over the list box.
  115.     // See string table and entry IDC_LIST_COLORS.
  116.  
  117.     m_wndDialogBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
  118.     DockControlBar(&m_wndDialogBar);
  119.  
  120.     return 0;
  121. }
  122.  
  123. void CMainFrame::OnViewDialogbar() 
  124. {
  125.     OnBarCheck(ID_VIEW_MYDIALOGBAR);
  126. }
  127.  
  128. void CMainFrame::OnUpdateViewDialogbar(CCmdUI* pCmdUI) 
  129. {
  130.     OnUpdateControlBarMenu(pCmdUI);
  131. }
  132.  
  133.  
  134.