home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch20 / mymenu / mymenvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-25  |  5.4 KB  |  235 lines

  1. // mymenvw.cpp : implementation of the CMymenuView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "mymenu.h"
  6.  
  7. #include "mymendoc.h"
  8. #include "mymenvw.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMymenuView
  17.  
  18. IMPLEMENT_DYNCREATE(CMymenuView, CView)
  19.  
  20. BEGIN_MESSAGE_MAP(CMymenuView, CView)
  21.     //{{AFX_MSG_MAP(CMymenuView)
  22.     ON_COMMAND(ID_FILE_BOLD, OnFileBold)
  23.     ON_COMMAND(ID_FORMAT_SIZE_SIZEPOINT1, OnFormatSizeSizepoint1)
  24.     ON_COMMAND(ID_FORMAT_SIZE_SIZEPOINT2, OnFormatSizeSizepoint2)
  25.     ON_COMMAND(ID_FORMAT_ITALIC, OnFormatItalic)
  26.     ON_UPDATE_COMMAND_UI(ID_FORMAT_ITALIC, OnUpdateFormatItalic)
  27.     //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMymenuView construction/destruction
  32.  
  33. CMymenuView::CMymenuView()
  34. {
  35.     // TODO: add construction code here
  36.  
  37.      //////////////////////
  38.      // MY CODE STARTS HERE
  39.      //////////////////////
  40.  
  41.     // Initialize the data member to 1.
  42.     m_Italic = 1;
  43.  
  44.      ////////////////////
  45.      // MY CODE ENDS HERE
  46.      ////////////////////
  47.  
  48. }
  49.  
  50. CMymenuView::~CMymenuView()
  51. {
  52. }
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CMymenuView drawing
  56.  
  57. void CMymenuView::OnDraw(CDC* pDC)
  58. {
  59.     CMymenuDoc* pDoc = GetDocument();
  60.     ASSERT_VALID(pDoc);
  61.  
  62.     // TODO: add draw code for native data here
  63. }
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CMymenuView diagnostics
  67.  
  68. #ifdef _DEBUG
  69. void CMymenuView::AssertValid() const
  70. {
  71.     CView::AssertValid();
  72. }
  73.  
  74. void CMymenuView::Dump(CDumpContext& dc) const
  75. {
  76.     CView::Dump(dc);
  77. }
  78.  
  79. CMymenuDoc* CMymenuView::GetDocument() // non-debug version is inline
  80. {
  81.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMymenuDoc)));
  82.     return (CMymenuDoc*)m_pDocument;
  83. }
  84. #endif //_DEBUG
  85.  
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CMymenuView message handlers
  88.  
  89. void CMymenuView::OnFileBold()
  90. {
  91.     // TODO: Add your command handler code here
  92.  
  93.      //////////////////////
  94.      // MY CODE STARTS HERE
  95.      //////////////////////
  96.  
  97.      // Extract the pointer of the parent window.
  98.     CWnd* pParent = GetParent();
  99.  
  100.     // Extract the pointer of the menu
  101.     CMenu* pMenu = pParent->GetMenu();
  102.  
  103.  
  104.     // Extract the pointer of the Format menu
  105.     CMenu* pMenuFormatItem = pMenu->GetSubMenu(1);
  106.  
  107.  
  108.     // Enable the Size menu
  109.     pMenuFormatItem->EnableMenuItem (0,
  110.                               MF_BYPOSITION | MF_ENABLED );
  111.  
  112.     // Display a message box
  113.     CString sMessage;
  114.      sMessage = "I'm inside OnFileBold() ";
  115.     MessageBox ( sMessage );
  116.  
  117.     // Invert the value of m_Italic
  118.     if ( m_Italic == 0 )
  119.          m_Italic = 1;
  120.     else
  121.          m_Italic = 0;
  122.  
  123.      ////////////////////
  124.      // MY CODE ENDS HERE
  125.      ////////////////////
  126.  
  127. }
  128.  
  129. void CMymenuView::OnFormatSizeSizepoint1()
  130. {
  131.     // TODO: Add your command handler code here
  132.  
  133.  
  134.      //////////////////////
  135.      // MY CODE STARTS HERE
  136.      //////////////////////
  137.  
  138.     // Extract the pointer of the parent window.
  139.     CWnd* pParent = GetParent();
  140.  
  141.     // Extract the pointer of the menu
  142.     CMenu* pMenu = pParent->GetMenu();
  143.  
  144.     // Remove the check mark from the Size point 2 item
  145.     pMenu->CheckMenuItem( ID_FORMAT_SIZE_SIZEPOINT2,
  146.                           MF_UNCHECKED );
  147.  
  148.  
  149.     // Place a check mark to the left of
  150.     // the Size point 1 item
  151.     pMenu->CheckMenuItem( ID_FORMAT_SIZE_SIZEPOINT1,
  152.                           MF_CHECKED );
  153.  
  154.  
  155.     // Display a message box
  156.     CString sMessage;
  157.     sMessage = "I'm inside Format->Size->Point 1";
  158.     MessageBox ( sMessage );
  159.  
  160.      ////////////////////
  161.      // MY CODE ENDS HERE
  162.      ////////////////////
  163. }
  164.  
  165. void CMymenuView::OnFormatSizeSizepoint2()
  166. {
  167.     // TODO: Add your command handler code here
  168.  
  169.      //////////////////////
  170.      // MY CODE STARTS HERE
  171.      //////////////////////
  172.  
  173.  
  174.     // Extract the pointer of the parent window.
  175.     CWnd* pParent = GetParent();
  176.  
  177.     // Extract the pointer of the menu
  178.     CMenu* pMenu = pParent->GetMenu();
  179.  
  180.     // Remove the check mark from the Size point 1 item
  181.     pMenu->CheckMenuItem( ID_FORMAT_SIZE_SIZEPOINT1,
  182.                           MF_UNCHECKED );
  183.  
  184.  
  185.   // Place a check mark to the left of the Size point 2 item
  186.     pMenu->CheckMenuItem( ID_FORMAT_SIZE_SIZEPOINT2,
  187.                           MF_CHECKED );
  188.  
  189.     // Display a message box
  190.     CString sMessage;
  191.     sMessage = "I'm inside Format->Size->Point 2";
  192.     MessageBox ( sMessage );
  193.  
  194.      ////////////////////
  195.      // MY CODE ENDS HERE
  196.      ////////////////////
  197.  
  198. }
  199.  
  200. void CMymenuView::OnFormatItalic()
  201. {
  202.     // TODO: Add your command handler code here
  203.  
  204.  
  205.      //////////////////////
  206.      // MY CODE STARTS HERE
  207.      //////////////////////
  208.  
  209.      MessageBox ("Format->Italic was selected");
  210.  
  211.      ////////////////////
  212.      // MY CODE ENDS HERE
  213.      ////////////////////
  214.     
  215. }
  216.  
  217. void CMymenuView::OnUpdateFormatItalic(CCmdUI* pCmdUI)
  218. {
  219.     // TODO: Add your command update UI handler code here
  220.     
  221.      //////////////////////
  222.      // MY CODE STARTS HERE
  223.      //////////////////////
  224.  
  225.     if ( m_Italic == 0 )
  226.        pCmdUI->Enable(FALSE);
  227.     else
  228.        pCmdUI->Enable(TRUE);
  229.  
  230.      ////////////////////
  231.      // MY CODE ENDS HERE
  232.      ////////////////////
  233.  
  234. }
  235.