home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WDOCDEMO.ZIP / STEP06A.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  5.1 KB  |  184 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 Step06a;
  12.  
  13. uses WinDos, Strings, WinTypes, WinProcs, OWindows, ODialogs, OStdDlgs, Pen;
  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.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  27.     destructor Done; virtual;
  28.     function CanClose: Boolean; virtual;
  29.     procedure CMAbout(var Msg: TMessage);
  30.       virtual cm_First + cm_About;
  31.     procedure CMFileNew(var Msg: TMessage);
  32.       virtual cm_First + cm_FileNew;
  33.     procedure CMFileOpen(var Msg: TMessage);
  34.       virtual cm_First + cm_FileOpen;
  35.     procedure CMFileSave(var Msg: TMessage);
  36.       virtual cm_First + cm_FileSave;
  37.     procedure CMFileSaveAs(var Msg: TMessage);
  38.       virtual cm_First + cm_FileSaveAs;
  39.     procedure CMFilePrint(var Msg: TMessage);
  40.       virtual cm_First + cm_FilePrint;
  41.     procedure CMFileSetup(var Msg: TMessage);
  42.       virtual cm_First + cm_FileSetup;
  43.     procedure WMLButtonDown(var Msg: TMessage);
  44.       virtual wm_First + wm_LButtonDown;
  45.     procedure WMLButtonUp(var Msg: TMessage);
  46.       virtual wm_First + wm_LButtonUp;
  47.     procedure WMMouseMove(var Msg: TMessage);
  48.       virtual wm_First + wm_MouseMove;
  49.     procedure WMRButtonDown(var Msg: TMessage);
  50.       virtual wm_First + wm_RButtonDown;
  51.   end;
  52.   TMyApplication = object(TApplication)
  53.     procedure InitMainWindow; virtual;
  54.   end;
  55.  
  56. constructor TStepWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  57. begin
  58.   inherited Init(AParent, ATitle);
  59.   Attr.Menu := LoadMenu(HInstance, MakeIntResource(100));
  60.   HasChanged := False;
  61.   ButtonDown := False;
  62.   StrCopy(FileName, '*.PTS');
  63.   CurrentPen := New(PPen, Init(ps_Solid, 1, 0));
  64. end;
  65.  
  66. destructor TStepWindow.Done;
  67. begin
  68.   Dispose(CurrentPen, Done);
  69.   inherited Done;
  70. end;
  71.  
  72. function TStepWindow.CanClose: Boolean;
  73. var
  74.   Reply: Integer;
  75. begin
  76.   CanClose := True;
  77.   if HasChanged then
  78.   begin
  79.     Reply := MessageBox(HWindow, 'Do you want to save?',
  80.       'Drawing has changed', mb_YesNo or mb_IconQuestion);
  81.     if Reply = id_Yes then CanClose := False;
  82.   end;
  83. end;
  84.  
  85. procedure TStepWindow.CMAbout(var Msg: TMessage);
  86. begin
  87.   Application^.ExecDialog(New(PDialog, Init(@Self, 'ABOUTBOX')));
  88. end;
  89.  
  90. procedure TStepWindow.CMFileNew(var Msg: TMessage);
  91. begin
  92.   InvalidateRect(HWindow, nil, True);
  93. end;
  94.  
  95. procedure TStepWindow.CMFileOpen(var Msg: TMessage);
  96. begin
  97.   if Application^.ExecDialog(New(PFileDialog,
  98.     Init(@Self, PChar(sd_FileOpen), FileName))) = id_OK then
  99.     MessageBox(HWindow, FIleName, 'Open the file:', mb_OK);
  100. end;
  101.  
  102. procedure TStepWindow.CMFileSave(var Msg: TMessage);
  103. begin
  104.   MessageBox(HWindow, 'Feature not implemented.', 'File Save', mb_OK);
  105. end;
  106.  
  107. procedure TStepWindow.CMFileSaveAs(var Msg: TMessage);
  108. begin
  109.   if Application^.ExecDialog(New(PFileDialog,
  110.     Init(@Self, PChar(sd_FileSave), FileName))) = id_OK then
  111.     MessageBox(HWindow, FileName, 'Save the file:', mb_OK);
  112. end;
  113.  
  114. procedure TStepWindow.CMFilePrint(var Msg: TMessage);
  115. begin
  116.   MessageBox(HWindow, 'Feature not implemented.', 'File Print', mb_OK);
  117. end;
  118.  
  119. procedure TStepWindow.CMFileSetup(var Msg: TMessage);
  120. begin
  121.   MessageBox(HWindow, 'Feature not implemented.', 'Printer Setup', mb_OK);
  122. end;
  123.  
  124. procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
  125. begin
  126.   if not ButtonDown then
  127.   begin
  128.     ButtonDown := True;
  129.     SetCapture(HWindow);
  130.     DragDC := GetDC(HWindow);
  131.     CurrentPen^.Select(DragDC);
  132.     MoveTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  133.   end;
  134. end;
  135.  
  136. procedure TStepWindow.WMLButtonUp(var Msg: TMessage);
  137. begin
  138.   if ButtonDown then
  139.   begin
  140.     ButtonDown := False;
  141.     ReleaseCapture;
  142.     CurrentPen^.Delete;
  143.     ReleaseDC(HWindow, DragDC);
  144.   end;
  145. end;
  146.  
  147. procedure TStepWindow.WMMouseMove(var Msg: TMessage);
  148. begin
  149.   if ButtonDown then LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  150. end;
  151.  
  152. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  153. var
  154.   InputText: array[0..5] of Char;
  155.   NewSize, ErrorPos: Integer;
  156. begin
  157.   if not ButtonDown then
  158.   begin
  159.     Str(CurrentPen^.Width, InputText);
  160.     if Application^.ExecDialog(New(PInputDialog,
  161.       Init(@Self, 'Line Width', 'Type a new line width:',
  162.       InputText, SizeOf(InputText)))) = id_OK then
  163.     begin
  164.       Val(InputText, NewSize, ErrorPos);
  165.       if ErrorPos = 0 then
  166.         with CurrentPen^ do
  167.           SetAttributes(ps_Solid, NewSize, 0);
  168.     end;
  169.   end;
  170. end;
  171.  
  172. procedure TMyApplication.InitMainWindow;
  173. begin
  174.   MainWindow := New(PStepWindow, Init(nil, 'Steps'));
  175. end;
  176.  
  177. var
  178.   MyApp: TMyApplication;
  179.  
  180. begin
  181.   MyApp.Init('Steps');
  182.   MyApp.Run;
  183.   MyApp.Done;
  184. end.