home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WDOCDEMO.ZIP / STEP07.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  5.4 KB  |  200 lines

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Demo                           }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. {$R-} { Turn off range check because Windows message parameters
  9.         don't distinguish between Integer and Word. }
  10.  
  11. program Step07;
  12.  
  13. uses WinDos, Strings, WinTypes, WinProcs, Objects, OWindows, ODialogs, OStdDlgs, Pen, DrawLine;
  14.  
  15. {$R STEPS.RES}
  16.  
  17. {$I STEPS.INC}
  18.  
  19. type
  20.   PStepWindow = ^TStepWindow;
  21.   TStepWindow = object(TWindow)
  22.     DragDC: HDC;
  23.     ButtonDown, HasChanged: Boolean;
  24.     CurrentPen: PPen;
  25.     FileName: array[0..fsPathName] of Char;
  26.     Drawing: PCollection;
  27.     CurrentLine: PLine;
  28.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  29.     destructor Done; virtual;
  30.     function CanClose: Boolean; virtual;
  31.     procedure CMAbout(var Msg: TMessage);
  32.       virtual cm_First + cm_About;
  33.     procedure CMFileNew(var Msg: TMessage);
  34.       virtual cm_First + cm_FileNew;
  35.     procedure CMFileOpen(var Msg: TMessage);
  36.       virtual cm_First + cm_FileOpen;
  37.     procedure CMFileSave(var Msg: TMessage);
  38.       virtual cm_First + cm_FileSave;
  39.     procedure CMFileSaveAs(var Msg: TMessage);
  40.       virtual cm_First + cm_FileSaveAs;
  41.     procedure CMFilePrint(var Msg: TMessage);
  42.       virtual cm_First + cm_FilePrint;
  43.     procedure CMFileSetup(var Msg: TMessage);
  44.       virtual cm_First + cm_FileSetup;
  45.     procedure CMPen(var Msg: TMessage);
  46.       virtual cm_First + cm_Pen;
  47.     procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  48.     procedure WMLButtonDown(var Msg: TMessage);
  49.       virtual wm_First + wm_LButtonDown;
  50.     procedure WMLButtonUp(var Msg: TMessage);
  51.       virtual wm_First + wm_LButtonUp;
  52.     procedure WMMouseMove(var Msg: TMessage);
  53.       virtual wm_First + wm_MouseMove;
  54.     procedure WMRButtonDown(var Msg: TMessage);
  55.       virtual wm_First + wm_RButtonDown;
  56.   end;
  57.   TMyApplication = object(TApplication)
  58.     procedure InitMainWindow; virtual;
  59.   end;
  60.  
  61. constructor TStepWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  62. begin
  63.   inherited Init(AParent, ATitle);
  64.   Attr.Menu := LoadMenu(HInstance, MakeIntResource(100));
  65.   HasChanged := False;
  66.   ButtonDown := False;
  67.   StrCopy(FileName, '*.PTS');
  68.   CurrentPen := New(PPen, Init(ps_Solid, 1, 0));
  69.   Drawing := New(PCollection, Init(50, 50));
  70.   CurrentLine := nil;
  71. end;
  72.  
  73. destructor TStepWindow.Done;
  74. begin
  75.   Dispose(CurrentPen, Done);
  76.   Dispose(Drawing, DOne);
  77.   inherited Done;
  78. end;
  79.  
  80. function TStepWindow.CanClose: Boolean;
  81. var
  82.   Reply: Integer;
  83. begin
  84.   CanClose := True;
  85.   if HasChanged then
  86.   begin
  87.     Reply := MessageBox(HWindow, 'Do you want to save?',
  88.       'Drawing has changed', mb_YesNo or mb_IconQuestion);
  89.     if Reply = id_Yes then CanClose := False;
  90.   end;
  91. end;
  92.  
  93. procedure TStepWindow.CMAbout(var Msg: TMessage);
  94. begin
  95.   Application^.ExecDialog(New(PDialog, Init(@Self, 'ABOUTBOX')));
  96. end;
  97.  
  98. procedure TStepWindow.CMFileNew(var Msg: TMessage);
  99. begin
  100.   Drawing^.FreeAll;
  101.   InvalidateRect(HWindow, nil, True);
  102. end;
  103.  
  104. procedure TStepWindow.CMFileOpen(var Msg: TMessage);
  105. begin
  106.   if Application^.ExecDialog(New(PFileDialog,
  107.     Init(@Self, PChar(sd_FileOpen), FileName))) = id_OK then
  108.     MessageBox(HWindow, FIleName, 'Open the file:', mb_OK);
  109. end;
  110.  
  111. procedure TStepWindow.CMFileSave(var Msg: TMessage);
  112. begin
  113.   MessageBox(HWindow, 'Feature not implemented.', 'File Save', mb_OK);
  114. end;
  115.  
  116. procedure TStepWindow.CMFileSaveAs(var Msg: TMessage);
  117. begin
  118.   if Application^.ExecDialog(New(PFileDialog,
  119.     Init(@Self, PChar(sd_FileSave), FileName))) = id_OK then
  120.     MessageBox(HWindow, FileName, 'Save the file:', mb_OK);
  121. end;
  122.  
  123. procedure TStepWindow.CMFilePrint(var Msg: TMessage);
  124. begin
  125.   MessageBox(HWindow, 'Feature not implemented.', 'File Print', mb_OK);
  126. end;
  127.  
  128. procedure TStepWindow.CMFileSetup(var Msg: TMessage);
  129. begin
  130.   MessageBox(HWindow, 'Feature not implemented.', 'Printer Setup', mb_OK);
  131. end;
  132.  
  133. procedure TStepWindow.CMPen(var Msg: TMessage);
  134. begin
  135.   CurrentPen^.ChangePen;
  136. end;
  137.  
  138. procedure TStepWindow.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
  139.  
  140.   procedure DrawLine(P: PLine); far;
  141.   begin
  142.     P^.Draw(PaintDC);
  143.   end;
  144.  
  145. begin
  146.   Drawing^.ForEach(@DrawLine);
  147. end;
  148.  
  149. procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
  150. begin
  151.   if not ButtonDown then
  152.   begin
  153.     ButtonDown := True;
  154.     SetCapture(HWindow);
  155.     DragDC := GetDC(HWindow);
  156.     CurrentPen^.Select(DragDC);
  157.     MoveTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  158.     CurrentLine := New(PLine, Init(CurrentPen));
  159.     Drawing^.Insert(CurrentLine);
  160.   end;
  161. end;
  162.  
  163. procedure TStepWindow.WMLButtonUp(var Msg: TMessage);
  164. begin
  165.   if ButtonDown then
  166.   begin
  167.     ButtonDown := False;
  168.     ReleaseCapture;
  169.     CurrentPen^.Delete;
  170.     ReleaseDC(HWindow, DragDC);
  171.   end;
  172. end;
  173.  
  174. procedure TStepWindow.WMMouseMove(var Msg: TMessage);
  175. begin
  176.   if ButtonDown then
  177.   begin
  178.     LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  179.     CurrentLine^.AddPoint(Msg.LParamLo, Msg.LParamHi);
  180.   end;
  181. end;
  182.  
  183. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  184. begin
  185.   if not ButtonDown then CurrentPen^.ChangePen;
  186. end;
  187.  
  188. procedure TMyApplication.InitMainWindow;
  189. begin
  190.   MainWindow := New(PStepWindow, Init(nil, 'Steps'));
  191. end;
  192.  
  193. var
  194.   MyApp: TMyApplication;
  195.  
  196. begin
  197.   MyApp.Init('Steps');
  198.   MyApp.Run;
  199.   MyApp.Done;
  200. end.