home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / ttips2 / mainfrm.cpp next >
Encoding:
C/C++ Source or Header  |  1994-06-13  |  4.2 KB  |  169 lines

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tooltest.h"
  6. #include "toolopti.h"
  7.  
  8. #include "mainfrm.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMainFrame
  17.  
  18. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  19.  
  20. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  21.     //{{AFX_MSG_MAP(CMainFrame)
  22.     ON_WM_CREATE()
  23.     ON_COMMAND(IDD_TOOLBAR, OnToolbar)
  24.     ON_COMMAND(IDD_SAMPLEBUTTON, OnSampleButton)
  25.     //}}AFX_MSG_MAP
  26.     // Global help commands
  27.     ON_COMMAND(ID_HELP_INDEX, CMDIFrameWnd::OnHelpIndex)
  28.     ON_COMMAND(ID_HELP_USING, CMDIFrameWnd::OnHelpUsing)
  29.     ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
  30.     ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
  31.     ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpIndex)
  32. END_MESSAGE_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // arrays of IDs used to initialize control bars
  36.  
  37. // toolbar buttons - IDs are command buttons
  38. static UINT BASED_CODE buttons[] =
  39. {
  40.     // same order as in the bitmap 'toolbar.bmp'
  41.     ID_FILE_NEW,
  42.     ID_FILE_OPEN,
  43.     ID_FILE_SAVE,
  44.         ID_SEPARATOR,
  45.     ID_EDIT_CUT,
  46.     ID_EDIT_COPY,
  47.     ID_EDIT_PASTE,
  48.         ID_SEPARATOR,
  49.     ID_FILE_PRINT,
  50.     ID_APP_ABOUT,
  51.         ID_SEPARATOR,
  52.     IDD_SAMPLEBUTTON,
  53. };
  54.  
  55. static UINT BASED_CODE indicators[] =
  56. {
  57.     ID_SEPARATOR,           // status line indicator
  58.     ID_INDICATOR_CAPS,
  59.     ID_INDICATOR_NUM,
  60.     ID_INDICATOR_SCRL,
  61. };
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CMainFrame construction/destruction
  65.  
  66. CMainFrame::CMainFrame()
  67. {
  68.     // TODO: add member initialization code here
  69. }
  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.         TRACE("Failed to create toolbar\n");
  86.         return -1;      // fail to create
  87.     }
  88.  
  89. //
  90. // This function sets the tool bar options that were read from the .ini
  91. // file.  They are really already set because the toolbar constructor
  92. // reads them, but if the toolbar is not displayed (I.E., the user leaves
  93. // it off last time they exit) then this will turn it off again ...
  94. //
  95.     SetToolbarOptions(FALSE); // set them but don't display dialog
  96.     
  97.     if (!m_wndStatusBar.Create(this) ||
  98.         !m_wndStatusBar.SetIndicators(indicators,
  99.           sizeof(indicators)/sizeof(UINT)))
  100.     {
  101.         TRACE("Failed to create status bar\n");
  102.         return -1;      // fail to create
  103.     }
  104.  
  105.     return 0;
  106. }
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CMainFrame diagnostics
  110.  
  111. #ifdef _DEBUG
  112. void CMainFrame::AssertValid() const
  113. {
  114.     CMDIFrameWnd::AssertValid();
  115. }
  116.  
  117. void CMainFrame::Dump(CDumpContext& dc) const
  118. {
  119.     CMDIFrameWnd::Dump(dc);
  120. }
  121.  
  122. #endif //_DEBUG
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125. // CMainFrame message handlers
  126.  
  127. //
  128. // These functions support the toolbar options dialog and initial setup
  129. // up after toolbar creation (incase the user leaves it off)
  130. //
  131. void CMainFrame::OnToolbar()
  132. {
  133.     SetToolbarOptions(TRUE);
  134. }
  135.  
  136. void CMainFrame::SetToolbarOptions(BOOL bDisplayDialog)
  137. {
  138.     CToolOptions ToolDlg;
  139.     int iStatus;
  140.     
  141.     ToolDlg.m_StatusLine = m_wndToolBar.GetFlyby();
  142.     ToolDlg.m_Popup = m_wndToolBar.GetTips();
  143.     ToolDlg.m_BoxStyle = m_wndToolBar.GetTipStyle();
  144.     ToolDlg.m_SystemFont = m_wndToolBar.GetTipFont();
  145.     ToolDlg.m_Wait = m_wndToolBar.GetTipWait();
  146.     ToolDlg.m_ToolBar = m_wndToolBar.GetToolbarDisplay();
  147.     
  148.     if (bDisplayDialog)
  149.         iStatus = ToolDlg.DoModal ();
  150.     else
  151.         iStatus = IDOK;
  152.             
  153.     if (iStatus == IDOK) {
  154.         m_wndToolBar.SetFlyby(ToolDlg.m_StatusLine);
  155.         m_wndToolBar.SetTips(ToolDlg.m_Popup);
  156.         m_wndToolBar.SetTipStyle(ToolDlg.m_BoxStyle);
  157.         m_wndToolBar.SetTipFont(ToolDlg.m_SystemFont);
  158.         m_wndToolBar.SetTipWait(ToolDlg.m_Wait);
  159.         m_wndToolBar.SetToolbarDisplay(ToolDlg.m_ToolBar);
  160.         RecalcLayout();
  161.     }
  162. }
  163.  
  164. void CMainFrame::OnSampleButton()
  165. {
  166.     MessageBeep(MB_ICONASTERISK);
  167.     AfxMessageBox("Sample Button Pressed - See It Works ...");
  168.     MessageBeep(MB_ICONHAND);
  169. }