home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / menus / cursor / cursor.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  2.4 KB  |  85 lines

  1. //************************************************************
  2. // Menus - Using a Menu Cursor
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <iapp.hpp>
  9. #include <icnr.hpp>
  10. #include <icnrobj.hpp>
  11. #include <iframe.hpp>
  12. #include <imenubar.hpp>
  13. #include <imnitem.hpp>
  14. #include "cursor.h"
  15.  
  16. void main()
  17. {
  18. IFrameWindow
  19.   frame ("Menu Cursor Example");
  20.  
  21. // Add the Menubar from a resource file.
  22. IMenuBar
  23.   menuBar(MAIN_MENU, &frame);
  24. menuBar.setBitmap(MI_BITMAP, MI_BITMAP);
  25.  
  26. // Create a Container Status Area in the Client.
  27. IContainerControl
  28.   statusArea(ID_STATUS, &frame, &frame);
  29. statusArea
  30.   .showTreeTextView()
  31.   .setDeleteObjectsOnClose();
  32.  
  33. // Create menu cursors to display the menu bar contents
  34. // in the client area.
  35. IMenu::Cursor level1Cursor(menuBar);
  36. for (level1Cursor.setToFirst();
  37.      level1Cursor.isValid();
  38.      level1Cursor.setToNext())
  39. {
  40.   IContainerObject* level1Object;
  41.   IMenuItem level1Item =
  42.              menuBar.elementAt(level1Cursor);
  43.  
  44.   if (level1Item.text().length()!=0)
  45.     level1Object = new IContainerObject(level1Item.text());
  46.   else if (level1Item.bitmap())
  47.     level1Object = new IContainerObject("Bitmap");
  48.   else if (level1Item.isSeparator())
  49.     level1Object = new IContainerObject("Separator");
  50.   else
  51.     level1Object = new IContainerObject("Unknown");
  52.   statusArea.addObject(level1Object);
  53.  
  54.   if(level1Item.submenuHandle())
  55.   {
  56.     IMenu::Cursor level2Cursor(menuBar, level1Item.id());
  57.     for (level2Cursor.setToFirst();
  58.          level2Cursor.isValid();
  59.          level2Cursor.setToNext())
  60.     {
  61.       IContainerObject* level2Object;
  62.       IMenuItem level2Item =
  63.                      menuBar.elementAt(level2Cursor);
  64.       if (level2Item.text().length()!=0)
  65.         level2Object = new IContainerObject(level2Item.text());
  66.       else if (level2Item.bitmap())
  67.         level2Object = new IContainerObject("Bitmap");
  68.       else if (level2Item.isSeparator())
  69.         level2Object = new IContainerObject("Separator");
  70.       else
  71.         level2Object = new IContainerObject("Unknown");
  72.       statusArea.addObject(level2Object, level1Object);
  73.     }
  74.   }
  75. }
  76.  
  77. // Set the focus and show the application.
  78. frame
  79.   .setClient(&statusArea)
  80.   .setFocus()
  81.   .show();
  82. IApplication::current().run();
  83. }
  84.  
  85.