home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / rwmenu1.cpp < prev    next >
C/C++ Source or Header  |  1997-07-29  |  3KB  |  158 lines

  1. /*
  2.   Program which uses alternate menus with minimal response
  3. */
  4.  
  5. #include <owl\applicat.h>
  6. #include <owl\framewin.h>
  7. #include "rwmenu1.h"
  8.  
  9. // declare the custom application class as
  10. // a subclass of TApplication
  11.  
  12. class TWinApp : public TApplication
  13. {
  14. public:
  15.   TWinApp() : TApplication() {}
  16.  
  17. protected:
  18.   virtual void InitMainWindow();
  19. };
  20.  
  21. // expand the functionality of TWindow by deriving class TMainWindow
  22. class TMainWindow : public TWindow
  23. {
  24.  public:
  25.    TMainWindow()
  26.      : TWindow(0, 0, 0)
  27.      { LongMenuSelected = TRUE; }
  28.  
  29.  protected:
  30.  
  31.    BOOL LongMenuSelected;
  32.  
  33.    // handle clicking the left mouse button
  34.    void EvLButtonDown(UINT, TPoint&);
  35.  
  36.    // handle clicking the right mouse button
  37.    void EvRButtonDown(UINT, TPoint&);
  38.  
  39.    // handle the long menu
  40.    void CMLongMenu();
  41.  
  42.    // handle the short menu
  43.    void CMShortMenu();
  44.  
  45.    // handle the help menu
  46.     void CMHelp();
  47.  
  48.    // handle the Edit Copy menu
  49.    void CMEditCopy();
  50.  
  51.    // handle the Edit Cut menu
  52.    void CMEditCut();
  53.  
  54.    // handle the Edit Paste
  55.    void CMEditPaste();
  56.  
  57.    // display a message "Feature not implemented"
  58.    void notImplemented();
  59.  
  60.    // handle confirming closing the window
  61.    virtual BOOL CanClose();
  62.  
  63.    // declare the response table
  64.    DECLARE_RESPONSE_TABLE(TMainWindow);
  65.  
  66. };
  67.  
  68. DEFINE_RESPONSE_TABLE1(TMainWindow, TWindow)
  69.   EV_WM_LBUTTONDOWN,
  70.   EV_WM_RBUTTONDOWN,
  71.   EV_COMMAND(CM_LONGMENU, CMLongMenu),
  72.   EV_COMMAND(CM_SHORTMENU, CMShortMenu),
  73.   EV_COMMAND(CM_HELP, CMHelp),
  74.   EV_COMMAND(CM_EDITCOPY, CMEditCopy),
  75.   EV_COMMAND(CM_EDITCUT, CMEditCut),
  76.   EV_COMMAND(CM_EDITPASTE, CMEditPaste),
  77. END_RESPONSE_TABLE;
  78.  
  79. void TMainWindow::EvLButtonDown(UINT, TPoint&)
  80. {
  81.   MessageBox("You clicked the left mouse!", "Mouse Event",
  82.              MB_OK | MB_ICONEXCLAMATION);
  83. }
  84.  
  85. void TMainWindow::EvRButtonDown(UINT, TPoint&)
  86. {
  87.   if (LongMenuSelected)
  88.     CMShortMenu();
  89.   else
  90.     CMLongMenu();
  91. }
  92.  
  93. void TMainWindow::CMLongMenu()
  94. {
  95.   GetApplication()->MainWindow->AssignMenu(TResId(LONGMENU));
  96.   LongMenuSelected = TRUE;
  97.   MessageBox("The long menu is now active", "Menu Change",
  98.           MB_OK | MB_ICONINFORMATION);
  99. }
  100.  
  101. // assign the short menu
  102. void TMainWindow::CMShortMenu()
  103. {
  104.   GetApplication()->MainWindow->AssignMenu(TResId(SHORTMENU));
  105.   LongMenuSelected = FALSE;
  106.   MessageBox("The short menu is now active", "Menu Change",
  107.           MB_OK | MB_ICONINFORMATION);}
  108.  
  109. void TMainWindow::CMEditCut()
  110. {
  111.   notImplemented();
  112. }
  113.  
  114. void TMainWindow::CMEditCopy()
  115. {
  116.   notImplemented();
  117. }
  118.  
  119. void TMainWindow::CMEditPaste()
  120. {
  121.   notImplemented();
  122. }
  123.  
  124. void TMainWindow::CMHelp()
  125. {
  126.   MessageBox(
  127.     "This a sample one line help (that leaves more to be desired)",
  128.     "Help", MB_OK | MB_ICONINFORMATION);
  129. }
  130.  
  131. void TMainWindow::notImplemented()
  132. {
  133.   MessageBox("This feature is not implemented",
  134.           "Information", MB_OK | MB_ICONEXCLAMATION);
  135. }
  136.  
  137. BOOL TMainWindow::CanClose()
  138. {
  139.   return MessageBox("Want to close this application?",
  140.              "Query", MB_YESNO | MB_ICONQUESTION) == IDYES;
  141. }
  142.  
  143. void TWinApp::InitMainWindow()
  144. {
  145.   MainWindow = new TFrameWindow(0,
  146.                 "Alternate Menus Demo Program (version 1)",
  147.                 new TMainWindow);
  148.   // load the menu resource
  149.   MainWindow->AssignMenu(TResId(LONGMENU));
  150. }
  151.  
  152. int OwlMain(int /* argc */, char** /*argv[] */)
  153. {
  154.   TWinApp app;
  155.   return app.Run();
  156. }
  157.  
  158.