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

  1. //************************************************************
  2. // Menus - Title Bar Bitmaps
  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 <icmdhdr.hpp>
  10. #include <iframe.hpp>
  11. #include <imenu.hpp>
  12. #include <imnitem.hpp>
  13. #include <istattxt.hpp>
  14. #include "titlebmp.h"
  15.  
  16. #define INCL_WINFRAMEMGR  // For FID_MINMAX
  17. #include <os2.h>
  18.  
  19. // Create a Class to represent the MinMaxMenu.
  20. //  (This is modeled after ISystemMenu).
  21. class MinMaxMenu : public IMenu {
  22. public:
  23.    MinMaxMenu ( IFrameWindow& owner );
  24.  
  25. private:
  26. MinMaxMenu ( const MinMaxMenu&);
  27. MinMaxMenu& operator= ( const MinMaxMenu&);
  28. };
  29.  
  30. MinMaxMenu :: MinMaxMenu(IFrameWindow&  owner)
  31. {
  32.    IWindowHandle hwndMinMaxMenu =
  33.              handleWithId(FID_MINMAX,owner.handle());
  34.    setAutoDestroyWindow(false);
  35.    startHandlingEventsFor(hwndMinMaxMenu);
  36. }
  37. // Command handler to capture menu commands.
  38. class CommandHandler : public ICommandHandler
  39. {
  40. public:
  41.   CommandHandler ( IStaticText& status)
  42.             : aStatus(status) {}
  43.  
  44. protected:
  45. virtual Boolean
  46.   command              ( ICommandEvent& event );
  47.  
  48. private:
  49. IStaticText
  50.  &aStatus;
  51. CommandHandler& operator=( const CommandHandler&);
  52. };
  53.  
  54. void main()
  55. {
  56. IFrameWindow
  57.   frame ("Title Bar Bitmap Example");
  58.  
  59. // Titlebar Bitmaps using Menus.
  60. MinMaxMenu minMaxMenu(frame);
  61. IMenuItem
  62.   ringBefore(ID_RINGBEFORE),
  63.   ringAfter(ID_RINGAFTER);
  64.  
  65. // Put the bitmaps first in the menu.
  66. ringBefore
  67.   .setBitmap(ID_RINGBEFORE)
  68.   .setIndex(0);
  69. ringAfter
  70.   .setBitmap(ID_RINGAFTER)
  71.   .setIndex(0);
  72.  
  73. minMaxMenu
  74.   .addItem(ringAfter, 0)
  75.   .addItem(ringBefore, 0);
  76.  
  77. // Create a Status Area in the Client
  78. // and a command handler to write in it.
  79. IStaticText statusArea(ID_STATUS, &frame, &frame);
  80. CommandHandler commandHandler(statusArea);
  81. commandHandler.handleEventsFor(&frame);
  82.  
  83. // Set the focus and show the application.
  84. frame
  85.   .setClient(&statusArea)
  86.   .setFocus()
  87.   .show();
  88. IApplication::current().run();
  89.  
  90. }
  91.  
  92.  
  93. IBase::Boolean CommandHandler::command( ICommandEvent& event )
  94. {
  95.   switch(event.commandId())
  96.   {
  97.     case ID_RINGBEFORE :
  98.     {
  99.        aStatus.setText("Ring before button pressed");
  100.        return true;
  101.     }
  102.  
  103.     case ID_RINGAFTER :
  104.     {
  105.        aStatus.setText("Ring after button pressed");
  106.        return true;
  107.     }
  108.   }
  109. return false;
  110. }
  111.  
  112.  
  113.