home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / GROUPBOX.PAK / GROUPBXX.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  5KB  |  169 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\applicat.h>
  6. #include <owl\radiobut.h>
  7. #include <owl\groupbox.h>
  8. #include <owl\static.h>
  9. #include <owl\framewin.h>
  10. #include <cstring.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. const int ID_BCCGROUP     = 100;
  15. const int ID_BCC1         = 101;
  16. const int ID_BCC5         = 102;
  17. const int ID_BCC10        = 103;
  18. const int ID_BCCX         = 104;
  19. const int ID_CPPGROUP     = 110;
  20. const int ID_CPP1         = 111;
  21. const int ID_CPP5         = 112;
  22. const int ID_CPP10        = 113;
  23. const int ID_CPPX         = 114;
  24. const int ID_PLACEBUTTON  = 131;
  25. const int ID_CANCELBUTTON = 132;
  26.  
  27. class TOrderGroupBox : public TGroupBox {
  28.   public:
  29.     TOrderGroupBox(TWindow*        parent,
  30.                    int             id,
  31.                    const char far* text,
  32.                    int X, int Y, int W, int H,
  33.                    TModule*        module = 0) :
  34.       TGroupBox(parent, id, text, X, Y, W, H, module) {}
  35.  
  36.     void SelectionChanged(int controlId);
  37.  
  38.     string  itemsOrderedStr;    // stuff ordered.
  39. };
  40.  
  41. //
  42. // SelectionChanged(). Called by check boxes and radio buttons (or your own
  43. // control) when checked/unchecked.
  44. //
  45. void
  46. TOrderGroupBox::SelectionChanged(int controlId)
  47. {
  48.   switch (controlId) {
  49.   case ID_BCC1 :
  50.     itemsOrderedStr = "1 BCC compiler";
  51.     break;
  52.   case ID_BCC5 :
  53.     itemsOrderedStr = "5 BCC compilers";
  54.     break;
  55.   case ID_BCC10 :
  56.     itemsOrderedStr = "10 BCC compilers";
  57.     break;
  58.   case ID_BCCX :
  59.     itemsOrderedStr = "X BCC compilers";
  60.     break;
  61.   case ID_CPP1 :
  62.     itemsOrderedStr = "1 Professional Pack";
  63.     break;
  64.   case ID_CPP5 :
  65.     itemsOrderedStr = "5 Professional Packs";
  66.     break;
  67.   case ID_CPP10 :
  68.     itemsOrderedStr = "10 Professional Packs";
  69.     break;
  70.   case ID_CPPX :
  71.     itemsOrderedStr = "X Professional Packs";
  72.     break;
  73.   };
  74. }
  75.  
  76. //////////////////////////////////////////////////////////////////////
  77.  
  78. class TOrderWindow : public TFrameWindow {
  79.   public:
  80.     TOrderGroupBox* BCCGroup;
  81.     TOrderGroupBox* CPPGroup;
  82.  
  83.     TOrderWindow(TWindow* parent, const char* title);
  84.     void PlaceOrder();
  85.     void CancelOrder();
  86.  
  87.   DECLARE_RESPONSE_TABLE(TOrderWindow);
  88. };
  89.  
  90. DEFINE_RESPONSE_TABLE1(TOrderWindow, TFrameWindow)
  91.   EV_COMMAND(ID_PLACEBUTTON, PlaceOrder),
  92.   EV_COMMAND(ID_CANCELBUTTON, CancelOrder),
  93. END_RESPONSE_TABLE;
  94.  
  95. TOrderWindow::TOrderWindow(TWindow* parent, const char* title)
  96.   : TWindow(parent, title),
  97.     TFrameWindow(parent, title)
  98. {
  99.   TRadioButton* radio;
  100.   Attr.X = 20;
  101.   Attr.Y = 5;
  102.   Attr.W = 380;
  103.   Attr.H = 260;
  104.   new TStatic(this, -1, "Borland C++ now includes an extensive Windows",
  105.     20, 10, 380, 15, 55);
  106.   new TStatic(this, -1, "class library and a complete toolkit for Windows",
  107.     20, 27, 380, 15, 45);
  108.   new TStatic(this, -1, "resource editing.", 20, 44, 380, 15, 55);
  109.   new TStatic(this, -1, "              How many copies would you like?",
  110.     10, 61, 380, 15, 35);
  111.   BCCGroup = new TOrderGroupBox(this, ID_BCCGROUP, "BCC Compiler",
  112.     20, 80, 150, 105);
  113.   radio = new TRadioButton(this, ID_BCC1, "1", 30, 100, 40, 17, BCCGroup);
  114.   radio->Attr.Style |= WS_TABSTOP;
  115.   new TRadioButton(this, ID_BCC5, "5", 30, 120, 40, 17, BCCGroup);
  116.   new TRadioButton(this, ID_BCC10, "10", 30, 140, 40, 17, BCCGroup);
  117.   new TRadioButton(this, ID_BCCX, "X", 30, 160, 40, 17, BCCGroup);
  118.   CPPGroup = new TOrderGroupBox(this, ID_CPPGROUP, "Professional Packs",
  119.     189, 80, 150, 105);
  120.   radio = new TRadioButton(this, ID_CPP1, "1", 200, 100, 40, 17, CPPGroup);
  121.   radio->Attr.Style |= WS_TABSTOP;
  122.   new TRadioButton(this, ID_CPP5, "5", 200, 120, 40, 17, CPPGroup);
  123.   new TRadioButton(this, ID_CPP10, "10", 200, 140, 40, 17, CPPGroup);
  124.   new TRadioButton(this, ID_CPPX, "X", 200, 160, 40, 17, CPPGroup);
  125.   new TButton(this, ID_PLACEBUTTON, "PLACE ORDER", 20, 195, 157, 25, FALSE);
  126.   new TButton(this, ID_CANCELBUTTON, "CANCEL ORDER", 181, 195, 157, 25, FALSE);
  127.   EnableKBHandler();
  128. }
  129.  
  130. //
  131. // PlaceOrder(). Display order.  Display header and items ordered, from group
  132. // box.
  133. //
  134. void
  135. TOrderWindow::PlaceOrder()
  136. {
  137.   string msg;
  138.   string zero("0");   // if nothing ordered.
  139.  
  140.   msg += "BCC: " + (BCCGroup->itemsOrderedStr.is_null() ? zero :
  141.                     BCCGroup->itemsOrderedStr) + "\n";
  142.   msg += "Professional: " + (CPPGroup->itemsOrderedStr.is_null() ? zero :
  143.                              CPPGroup->itemsOrderedStr) + "\n";
  144.   MessageBox(msg.c_str(), "Order", MB_OK);
  145. }
  146.  
  147. void
  148. TOrderWindow::CancelOrder()
  149. {
  150.   MessageBox("Order Canceled", "Order", MB_OK);
  151. }
  152.  
  153. //----------------------------------------------------------------------------
  154.  
  155. class TOrderApp : public TApplication {
  156.   public:
  157.     TOrderApp() : TApplication() {}
  158.     void InitMainWindow() {
  159.       MainWindow = new TOrderWindow(0, "BCC Order Form");
  160.     }
  161. };
  162.  
  163. int
  164. OwlMain(int /*argc*/, char* /*argv*/ [])
  165. {
  166.   TOrderApp app;
  167.   return app.Run();
  168. }
  169.