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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //
  4. //----------------------------------------------------------------------------
  5. #include <owl\owlpch.h>
  6. #include <owl\applicat.h>
  7. #include <owl\framewin.h>
  8. #include <owl\button.h>
  9. #include <owl\checkbox.h>
  10. #include <owl\radiobut.h>
  11. #include <owl\groupbox.h>
  12.  
  13. const WORD ID_BUTTON   = 101;
  14. const WORD ID_RBUTTON1 = 102;
  15. const WORD ID_RBUTTON2 = 103;
  16. const WORD ID_CHECKBOX = 104;
  17. const WORD ID_GROUPBOX = 105;
  18.  
  19. class TTestWindow : public TWindow {
  20.   public:
  21.     TRadioButton* RButton1;
  22.     TRadioButton* RButton2;
  23.     TCheckBox*    CheckBox;
  24.     TGroupBox*    GroupBox;
  25.  
  26.     TTestWindow();
  27.  
  28.     // button handlers
  29.     //
  30.     void  HandleButtonMsg();    // ID_BUTTON
  31.     void  HandleCheckBoxMsg();  // ID_CHECKBOX
  32.  
  33.     void  HandleGroupBoxMsg(UINT);
  34.  
  35.   DECLARE_RESPONSE_TABLE(TTestWindow);
  36. };
  37.  
  38. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  39.   EV_COMMAND(ID_BUTTON, HandleButtonMsg),
  40.   EV_COMMAND(ID_CHECKBOX, HandleCheckBoxMsg),
  41.   EV_CHILD_NOTIFY_ALL_CODES(ID_GROUPBOX, HandleGroupBoxMsg),
  42. END_RESPONSE_TABLE;
  43.  
  44. TTestWindow::TTestWindow()
  45.   : TWindow(0, 0, 0)
  46. {
  47.   new TButton(this, ID_BUTTON, "State of Check Box", 88, 48, 296, 24, FALSE);
  48.   CheckBox = new TCheckBox(this, ID_CHECKBOX, "Check Box Text", 158, 12, 150, 26, 0);
  49.   GroupBox = new TGroupBox(this, ID_GROUPBOX, "Group Box", 158, 102, 176, 108);
  50.   RButton1 = new TRadioButton(this, ID_RBUTTON1, "Radio Button 1",
  51.                               174, 128, 138, 24, GroupBox);
  52.   RButton2 = new TRadioButton(this, ID_RBUTTON2, "Radio Button 2", 
  53.                               174, 162, 138, 24, GroupBox);
  54. }
  55.  
  56. void
  57. TTestWindow::HandleButtonMsg()
  58. {
  59.   if (CheckBox->GetCheck() == BF_CHECKED)
  60.     MessageBox("Checked", "The check box is:", MB_OK);
  61.  
  62.   else
  63.     MessageBox("Unchecked", "The check box is:", MB_OK);
  64. }
  65.  
  66. void
  67. TTestWindow::HandleCheckBoxMsg()
  68. {
  69.   MessageBox("Toggled", "The check box has been:", MB_OK);
  70. }
  71.  
  72. void
  73. TTestWindow::HandleGroupBoxMsg(UINT /* notifyCode */)
  74. {
  75.   char textBuff[20];
  76.  
  77.   if (RButton1->GetCheck() == BF_CHECKED)
  78.     RButton1->GetWindowText(textBuff, sizeof(textBuff));
  79.  
  80.   else
  81.     RButton2->GetWindowText(textBuff, sizeof(textBuff));
  82.  
  83.   MessageBox(textBuff, "You have selected:", MB_OK);
  84. }
  85.  
  86. //----------------------------------------------------------------------------
  87.  
  88. class TTestApp : public TApplication {
  89.   public:
  90.     TTestApp() : TApplication() {}
  91.     void  InitMainWindow();
  92. };
  93.  
  94. void
  95. TTestApp::InitMainWindow()
  96. {
  97.   MainWindow = new TFrameWindow(0, "Button Tester", new TTestWindow);
  98. }
  99.  
  100. int
  101. OwlMain(int /*argc*/, char* /*argv*/ [])
  102. {
  103.   return TTestApp().Run();
  104. }
  105.