home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / tpw / docdemos / btntest.pas next >
Pascal/Delphi Source File  |  1991-05-20  |  3KB  |  94 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Demo program                                 }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program BtnTest;
  10.  
  11. uses WObjects, WinTypes, WinProcs;
  12.          
  13. const
  14.   id_Push1  = 101;
  15.   id_Rad1   = 102;
  16.   id_Rad2   = 103;
  17.   id_Check1 = 104;
  18.   id_Group1 = 105;
  19.  
  20. type
  21.   TestApplication = object(TApplication)
  22.     procedure InitMainWindow; virtual;
  23.   end;
  24.  
  25.   PTestWindow = ^TestWindow;
  26.  
  27.   TestWindow = object(TWindow)
  28.     Rad1, Rad2: PRadioButton;
  29.     Check1: PCheckBox;
  30.     Group1: PGroupBox;
  31.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  32.     procedure HandlePush1Msg(var Msg: TMessage);
  33.       virtual id_First + id_Push1;
  34.     procedure HandleCheck1Msg(var Msg: TMessage);
  35.       virtual id_First + id_Check1;
  36.     procedure HandleGroup1Msg(var Msg: TMessage);
  37.       virtual id_First + id_Group1;
  38.   end;
  39.  
  40. { --------TestWindow methods------------------ }
  41. constructor TestWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  42. var
  43.   AButt: PButton;
  44. begin
  45.   TWindow.Init(AParent, ATitle);
  46.   AButt := New(PButton, Init(@Self, id_Push1, 'State of Check Box',
  47.     88, 48, 296, 24, False));
  48.   Check1 := New(PCheckBox, Init(@Self, id_Check1, 'Check Box Text',
  49.     158, 12, 150, 26, nil));
  50.   Group1 := New(PGroupBox, Init(@Self, id_Group1, 'Group Box',
  51.     158, 102, 176, 108));
  52.   Rad1 := New(PRadioButton, Init(@Self, id_Rad1, 'Radio Button 1',
  53.     174, 128, 138, 24, Group1));
  54.   Rad2 := New(PRadioButton, Init(@Self, id_Rad2, 'Radio Button 2',
  55.     174, 162, 138, 24, Group1));
  56. end;
  57.  
  58. procedure TestWindow.HandlePush1Msg(var Msg: TMessage);
  59. begin
  60.   if Check1^.GetCheck = 0 then
  61.   MessageBox(HWindow, 'Unchecked', 'The check box is:', MB_OK)
  62.   else MessageBox(HWindow, 'Checked', 'The check box is:', MB_OK);
  63. end;
  64.  
  65. procedure TestWindow.HandleCheck1Msg(var Msg: TMessage);
  66. begin
  67.   MessageBox(HWindow, 'Toggled', 'The check box has been:', MB_OK)
  68. end;
  69.  
  70. procedure TestWindow.HandleGroup1Msg(var Msg: TMessage);
  71. var
  72.   TextBuff: array[0..20] of Char;
  73. begin
  74.   if Rad1^.GetCheck <> 0
  75.   then GetWindowText(Rad1^.HWindow, TextBuff, SizeOf(TextBuff))
  76.   else GetWindowText(Rad2^.HWindow, TextBuff, SizeOf(TextBuff));
  77.   MessageBox(HWindow, TextBuff, 'You have selected:', MB_OK);
  78. end;
  79.  
  80. { -----------TestApplication Methods------------ }
  81. procedure TestApplication.InitMainWindow;
  82. begin
  83.   MainWindow := New(PTestWindow, Init(nil, 'Button Tester'));
  84. end;
  85.  
  86. var
  87.   TestApp : TestApplication;
  88.  
  89. begin
  90.   TestApp.Init('ButtTest');
  91.   TestApp.Run;
  92.   TestApp.Done;
  93. end.
  94.