home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / tpwinst / docdemos.pak / DIALTEST.PAS < prev    next >
Pascal/Delphi Source File  |  1991-05-21  |  3KB  |  97 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Demo program                                 }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program DialTest;
  10.  
  11. {$R DIALTEST.RES}
  12.          
  13. uses WinTypes, WinProcs, WObjects;
  14.  
  15. const
  16.   TheMenu     = 100;
  17.   id_LB1      = 151;
  18.   id_BN1      = 152;
  19.   cm_DialTest = 101;
  20.  
  21. type
  22.   PTestDialog = ^TTestDialog;
  23.   TTestDialog = object(TDialog)
  24.     procedure IDBN1(var Msg: TMessage); virtual id_First + id_BN1;
  25.     procedure IDLB1(var Msg: TMessage); virtual id_First + id_LB1;
  26.   end;
  27.  
  28.   PTestWindow = ^TTestWindow;
  29.   TTestWindow = object(TWindow)
  30.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  31.     procedure CMDialTest(var Msg: TMessage); virtual cm_First + cm_DialTest;
  32.   end;
  33.  
  34.   TDlgApplication = object(TApplication)
  35.     procedure InitMainWindow; virtual;
  36.   end;
  37.  
  38. { TTestDialog }
  39. procedure TTestDialog.IDBN1(var Msg: TMessage);
  40. var
  41.   TextItem : PChar;
  42. begin
  43.   TextItem := 'Item 1';
  44.   SendDlgItemMsg(id_LB1, lb_AddString, 0, LongInt(TextItem));
  45.   TextItem := 'Item 2';
  46.   SendDlgItemMsg(id_LB1, lb_AddString, 0, LongInt(TextItem));
  47.   TextItem := 'Item 3';
  48.   SendDlgItemMsg(id_LB1, lb_AddString, 0, LongInt(TextItem));
  49.   TextItem := 'Item 4';
  50.   SendDlgItemMsg(id_LB1, lb_AddString, 0, LongInt(TextItem));
  51.   TextItem := 'Item 5';
  52.   SendDlgItemMsg(id_LB1, lb_AddString, 0, LongInt(TextItem));
  53.   TextItem := 'Item 6';
  54.   SendDlgItemMsg(id_LB1, lb_AddString, 0, LongInt(TextItem));
  55.   TextItem := 'Item 7';
  56.   SendDlgItemMsg(id_LB1, lb_AddString, 0, LongInt(TextItem));
  57. end;
  58.  
  59. procedure TTestDialog.IDLB1(var Msg: TMessage);
  60. var
  61.   Idx : Integer;
  62.   SelectedText: array[0..10] of Char;
  63. begin
  64.   if Msg.LParamHi = lbn_SelChange then
  65.   begin
  66.     Idx := SendDlgItemMsg(id_LB1, lb_GetCurSel, 0, LongInt(0));
  67.     SendDlgItemMsg(id_LB1, lb_GetText, Idx, LongInt(@SelectedText));
  68.     MessageBox(HWindow, SelectedText, 'List Box Notification', MB_OK);
  69.   end;
  70. end;
  71.  
  72. { TTestWindow }
  73. constructor TTestWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  74. begin
  75.   TWindow.Init(AParent, ATitle);
  76.   Attr.Menu := LoadMenu(Hinstance, MakeIntResource(TheMenu));
  77. end;
  78.  
  79. procedure TTestWindow.CMDialTest(var Msg: TMessage);
  80. begin
  81.   Application^.ExecDialog(New(PTestDialog, Init(@Self, 'DIAL1')));
  82. end;
  83.  
  84. { TDlgApplication }
  85. procedure TDlgApplication.InitMainWindow;
  86. begin
  87.   MainWindow := New(PTestWindow, Init(nil, 'Dialog Tester'));
  88. end;
  89.  
  90. var
  91.   MyApp: TDlgApplication;
  92. begin
  93.   MyApp.Init('DialTest');
  94.   MyApp.Run;
  95.   MyApp.Done;
  96. end.
  97.