home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / menus / sysmenu / sysmenu.cpp < prev   
Text File  |  1996-10-29  |  2KB  |  71 lines

  1. //************************************************************
  2. // Menus - Accessing the System Menu
  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 <iframe.hpp>
  10. #include <imnitem.hpp>
  11. #include <isysmenu.hpp>
  12.  
  13. #define MI_WINDOW 0x100
  14.  
  15. void main()
  16. {
  17. IFrameWindow
  18.   frame ("System Menu Example");
  19.  
  20. // Wrapper the System menu.
  21. ISystemMenu
  22.   systemMenu(&frame);
  23.  
  24. // We want the "Window" Submenu to be first in the list
  25. // This is accomplished by creating a menu item and
  26. // setting its index to zero.  We then call addSubmenu
  27. // to change from a normal menu item to a submenu.
  28. IMenuItem windowSubmenu(MI_WINDOW);
  29. windowSubmenu
  30.   .setIndex(0)
  31.  
  32. // Because we are not using a resource file, we need to handle
  33. // the special case difference of the mnemonic on Windows.
  34. #ifdef IC_WIN
  35.   .setText("&Window");
  36. #else
  37.   .setText("~Window");
  38. #endif
  39.  
  40. systemMenu
  41.   .addItem(windowSubmenu, ISystemMenu::idPulldown)
  42.   .addSubmenu(MI_WINDOW);
  43.  
  44. // Move some of the system menu items under
  45. // the submenu we just added.
  46. unsigned long itemsToMove[] =
  47.     {ISystemMenu::idRestore, ISystemMenu::idMove,
  48.      ISystemMenu::idSize, ISystemMenu::idMinimize,
  49.      ISystemMenu::idMaximize, ISystemMenu::idHide};
  50. for (int i=0; i<sizeof(itemsToMove)/sizeof(unsigned long); i++)
  51. {
  52.   // 1) Save the menu item data.
  53.   // 2) Change the items index to add it last.
  54.   // 3) Delete the old menu item.
  55.   // 4) Add the menu item under the "Window" submenu.
  56.   IMenuItem systemItem = systemMenu.menuItem(itemsToMove[i]);
  57.   systemItem.setIndex((unsigned long)-1);
  58.   systemMenu
  59.     .deleteItem(itemsToMove[i])
  60.     .addItem(systemItem, MI_WINDOW);
  61. }
  62.  
  63. // Add an icon, set the focus, show the frame
  64. // ... and run the application.
  65. frame
  66.   .setIcon(ISystemPointerHandle(ISystemPointerHandle::folder))
  67.   .setFocus()
  68.   .show();
  69. IApplication::current().run();
  70. }
  71.