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