home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pwrgu2.zip / POWERGU2.EXE / CONTROLS / CONTROLS.CPP next >
Text File  |  1995-07-23  |  4KB  |  107 lines

  1. //************************************************************
  2. // Controls - Constructor and color sample
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // All Rights Reserved.
  6. //************************************************************
  7. #include <icolor.hpp>
  8. #include <icombobx.hpp>
  9. #include <ientryfd.hpp>
  10. #include <iframe.hpp>
  11. #include <iapp.hpp>
  12. #include <ilistbox.hpp>
  13. #include <iscroll.hpp>
  14. #include "controls.h"
  15.  
  16. void main ( )
  17. {
  18.   IFrameWindow frame( ID_DIALOG );
  19.  
  20.   // Construct objects for dialog controls.
  21.   IComboBox combo( ID_COMBOBOX, &frame );
  22.   combo.addAsFirst( "The child entry field" );
  23.   combo.addAsLast ( "  should have a cyan background." );
  24.   IListBox listBox( ID_LISTBOX, &frame );
  25.   listBox.addAsFirst( "The child horizontal scroll bar" );
  26.   listBox.addAsLast ( "  should have a cyan scroll box." );
  27.   listBox.addAsLast ( "-- A long, long, long list box item\
  28.  to enable the horizontal scroll bar --" );
  29.  
  30.   // Find the entry field child of the combo box.
  31.   Boolean deleteEntryField = false;
  32.   IEntryField* ef =
  33.     (IEntryField*)IWindow::windowWithId( 0x029B, &combo );
  34.          // Note: IWindow::windowFromId works because we
  35.          // know the combo box owns the entry field.  If we
  36.          // weren't sure about the ownership, but knew the
  37.          // combination box was the parent of the entry
  38.          // field, we would have had to include <os2.h>,
  39.          // and call the following instead.
  40.          //   IWindowHandle handle =
  41.          //     WinWindowFromID( combo.handle(), 0x29B );
  42.          //   IEntryField* ef = (IEntryField*)
  43.          //     IWindow::windowWithHandle( handle );
  44.   if (!ef)         // No existing window object.
  45.   {                // Construct a new one.
  46.      ef = new IEntryField( 0x29B, &combo );
  47.      deleteEntryField = true;
  48.   }                // Else use the existing window object.
  49.   ef->setColor( IEntryField::background,
  50.                 IColor( IColor::cyan ));
  51.                    // Manipulate the entry field.
  52.   if (deleteEntryField)
  53.   {                // Memory clean-up.
  54.      delete ef;
  55.   }
  56.  
  57.   // Find the horizontal scroll bar child of the list box.
  58.   Boolean
  59.     deleteScrollBar = false,
  60.     done = false;
  61.   IScrollBar* sb = 0;
  62.   IWindow::ChildCursor cursor( listBox );
  63.   for (cursor.setToFirst();
  64.        !done  &&  cursor.isValid();
  65.        cursor.setToNext())
  66.   {
  67.      IWindowHandle childHandle = listBox.childAt( cursor );
  68.      sb = (IScrollBar*)
  69.             IWindow::windowWithHandle( childHandle );
  70.          // Note: Our code here assumes that the application
  71.          // has not added any child windows to the list box
  72.          // (which may not be scroll bars).
  73.      if (!sb)      // No existing window object.
  74.      {             // Construct a new one.
  75.         sb = new IScrollBar( childHandle );
  76.         deleteScrollBar = true;
  77.      }             // Else use the existing window object.
  78.      if (sb->isHorizontal())
  79.      {             // We found it.
  80.         done = true;
  81.      }
  82.      else if (deleteScrollBar)
  83.      {             // Horizontal scroll bar.
  84.         delete sb;
  85.         deleteScrollBar = false;
  86.      }
  87.   }
  88.   if (sb)          // Found the horizontal scroll bar.
  89.   {                // Change its color.
  90.      sb->setColor( IScrollBar::scrollBox,
  91.                    IColor( IColor::cyan ));
  92.                    // Manipulate the scroll bar.
  93.      if (deleteScrollBar)
  94.      {             // Memory clean-up.
  95.         delete sb;
  96.      }
  97.   }
  98.  
  99.   // Show the window now.
  100.   frame
  101.    .setFocus()
  102.    .show();
  103.  
  104.   // Display the window until the user closes it.
  105.   IApplication::current().run();
  106. }
  107.