home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WDOCDEMO.ZIP / STEP04B.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  5.0 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 Step04b;
  12.  
  13. uses WinDos, Strings, WinTypes, WinProcs, OWindows, OStdDlgs;
  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.     ThePen: HPen;
  25.     PenSize: Integer;
  26.     FileName: array[0..fsPathName] of Char;
  27.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  28.     destructor Done; virtual;
  29.     function CanClose: Boolean; virtual;
  30.     procedure CMFileNew(var Msg: TMessage);
  31.       virtual cm_First + cm_FileNew;
  32.     procedure CMFileOpen(var Msg: TMessage);
  33.       virtual cm_First + cm_FileOpen;
  34.     procedure CMFileSave(var Msg: TMessage);
  35.       virtual cm_First + cm_FileSave;
  36.     procedure CMFileSaveAs(var Msg: TMessage);
  37.       virtual cm_First + cm_FileSaveAs;
  38.     procedure CMFilePrint(var Msg: TMessage);
  39.       virtual cm_First + cm_FilePrint;
  40.     procedure CMFileSetup(var Msg: TMessage);
  41.       virtual cm_First + cm_FileSetup;
  42.     procedure SetPenSize(NewSize: Integer);
  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.   PenSize := 1;
  63.   ThePen := CreatePen(ps_Solid, PenSize, 0);
  64.   StrCopy(FileName, '*.PTS');
  65. end;
  66.  
  67. destructor TStepWindow.Done;
  68. begin
  69.   DeleteObject(ThePen);
  70.   inherited Done;
  71. end;
  72.  
  73. function TStepWindow.CanClose: Boolean;
  74. var
  75.   Reply: Integer;
  76. begin
  77.   CanClose := True;
  78.   if HasChanged then
  79.   begin
  80.     Reply := MessageBox(HWindow, 'Do you want to save?',
  81.       'Drawing has changed', mb_YesNo or mb_IconQuestion);
  82.     if Reply = id_Yes then CanClose := False;
  83.   end;
  84. end;
  85.  
  86. procedure TStepWindow.CMFileNew(var Msg: TMessage);
  87. begin
  88.   InvalidateRect(HWindow, nil, True);
  89. end;
  90.  
  91. procedure TStepWindow.CMFileOpen(var Msg: TMessage);
  92. begin
  93.   if Application^.ExecDialog(New(PFileDialog,
  94.     Init(@Self, PChar(sd_FileOpen), FileName))) = id_OK then
  95.     MessageBox(HWindow, FIleName, 'Open the file:', mb_OK);
  96. end;
  97.  
  98. procedure TStepWindow.CMFileSave(var Msg: TMessage);
  99. begin
  100.   MessageBox(HWindow, 'Feature not implemented.', 'File Save', mb_OK);
  101. end;
  102.  
  103. procedure TStepWindow.CMFileSaveAs(var Msg: TMessage);
  104. begin
  105.   if Application^.ExecDialog(New(PFileDialog,
  106.     Init(@Self, PChar(sd_FileSave), FileName))) = id_OK then
  107.     MessageBox(HWindow, FileName, 'Save the file:', mb_OK);
  108. end;
  109.  
  110. procedure TStepWindow.CMFilePrint(var Msg: TMessage);
  111. begin
  112.   MessageBox(HWindow, 'Feature not implemented.', 'File Print', mb_OK);
  113. end;
  114.  
  115. procedure TStepWindow.CMFileSetup(var Msg: TMessage);
  116. begin
  117.   MessageBox(HWindow, 'Feature not implemented.', 'Printer Setup', mb_OK);
  118. end;
  119.  
  120. procedure TStepWindow.SetPenSize(NewSize: Integer);
  121. begin
  122.   DeleteObject(ThePen);
  123.   ThePen := CreatePen(ps_Solid, NewSize, 0);
  124.   PenSize := NewSize;
  125. end;
  126.  
  127. procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
  128. begin
  129.   if not ButtonDown then
  130.   begin
  131.     ButtonDown := True;
  132.     SetCapture(HWindow);
  133.     DragDC := GetDC(HWindow);
  134.     SelectObject(DragDC, ThePen);
  135.     MoveTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  136.   end;
  137. end;
  138.  
  139. procedure TStepWindow.WMLButtonUp(var Msg: TMessage);
  140. begin
  141.   if ButtonDown then
  142.   begin
  143.     ButtonDown := False;
  144.     ReleaseCapture;
  145.     ReleaseDC(HWindow, DragDC);
  146.   end;
  147. end;
  148.  
  149. procedure TStepWindow.WMMouseMove(var Msg: TMessage);
  150. begin
  151.   if ButtonDown then LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  152. end;
  153.  
  154. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  155. var
  156.   InputText: array[0..5] of Char;
  157.   NewSize, ErrorPos: Integer;
  158. begin
  159.   if not ButtonDown then
  160.   begin
  161.     Str(PenSize, InputText);
  162.     if Application^.ExecDialog(New(PInputDialog,
  163.       Init(@Self, 'Line Width', 'Type a new line width:',
  164.       InputText, SizeOf(InputText)))) = id_OK then
  165.     begin
  166.       Val(InputText, NewSize, ErrorPos);
  167.       if ErrorPos = 0 then SetPenSize(NewSize);
  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.