home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D11 / WDOCDEMO.ZIP / STEP04B.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  4.9 KB  |  181 lines

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Demo                           }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program Step04b;
  9.  
  10. uses WinDos, Strings, WinTypes, WinProcs, OWindows, OStdDlgs;
  11.  
  12. {$R STEPS.RES}
  13.  
  14. {$I STEPS.INC}
  15.  
  16. type
  17.   PStepWindow = ^TStepWindow;
  18.   TStepWindow = object(TWindow)
  19.     DragDC: HDC;
  20.     ButtonDown, HasChanged: Boolean;
  21.     ThePen: HPen;
  22.     PenSize: Integer;
  23.     FileName: array[0..fsPathName] of Char;
  24.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  25.     destructor Done; virtual;
  26.     function CanClose: Boolean; virtual;
  27.     procedure CMFileNew(var Msg: TMessage);
  28.       virtual cm_First + cm_FileNew;
  29.     procedure CMFileOpen(var Msg: TMessage);
  30.       virtual cm_First + cm_FileOpen;
  31.     procedure CMFileSave(var Msg: TMessage);
  32.       virtual cm_First + cm_FileSave;
  33.     procedure CMFileSaveAs(var Msg: TMessage);
  34.       virtual cm_First + cm_FileSaveAs;
  35.     procedure CMFilePrint(var Msg: TMessage);
  36.       virtual cm_First + cm_FilePrint;
  37.     procedure CMFileSetup(var Msg: TMessage);
  38.       virtual cm_First + cm_FileSetup;
  39.     procedure SetPenSize(NewSize: Integer);
  40.     procedure WMLButtonDown(var Msg: TMessage);
  41.       virtual wm_First + wm_LButtonDown;
  42.     procedure WMLButtonUp(var Msg: TMessage);
  43.       virtual wm_First + wm_LButtonUp;
  44.     procedure WMMouseMove(var Msg: TMessage);
  45.       virtual wm_First + wm_MouseMove;
  46.     procedure WMRButtonDown(var Msg: TMessage);
  47.       virtual wm_First + wm_RButtonDown;
  48.   end;
  49.   TMyApplication = object(TApplication)
  50.     procedure InitMainWindow; virtual;
  51.   end;
  52.  
  53. constructor TStepWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  54. begin
  55.   inherited Init(AParent, ATitle);
  56.   Attr.Menu := LoadMenu(HInstance, MakeIntResource(100));
  57.   HasChanged := False;
  58.   ButtonDown := False;
  59.   PenSize := 1;
  60.   ThePen := CreatePen(ps_Solid, PenSize, 0);
  61.   StrCopy(FileName, '*.PTS');
  62. end;
  63.  
  64. destructor TStepWindow.Done;
  65. begin
  66.   DeleteObject(ThePen);
  67.   inherited Done;
  68. end;
  69.  
  70. function TStepWindow.CanClose: Boolean;
  71. var
  72.   Reply: Integer;
  73. begin
  74.   CanClose := True;
  75.   if HasChanged then
  76.   begin
  77.     Reply := MessageBox(HWindow, 'Do you want to save?',
  78.       'Drawing has changed', mb_YesNo or mb_IconQuestion);
  79.     if Reply = id_Yes then CanClose := False;
  80.   end;
  81. end;
  82.  
  83. procedure TStepWindow.CMFileNew(var Msg: TMessage);
  84. begin
  85.   InvalidateRect(HWindow, nil, True);
  86. end;
  87.  
  88. procedure TStepWindow.CMFileOpen(var Msg: TMessage);
  89. begin
  90.   if Application^.ExecDialog(New(PFileDialog,
  91.     Init(@Self, PChar(sd_FileOpen), FileName))) = id_OK then
  92.     MessageBox(HWindow, FIleName, 'Open the file:', mb_OK);
  93. end;
  94.  
  95. procedure TStepWindow.CMFileSave(var Msg: TMessage);
  96. begin
  97.   MessageBox(HWindow, 'Feature not implemented.', 'File Save', mb_OK);
  98. end;
  99.  
  100. procedure TStepWindow.CMFileSaveAs(var Msg: TMessage);
  101. begin
  102.   if Application^.ExecDialog(New(PFileDialog,
  103.     Init(@Self, PChar(sd_FileSave), FileName))) = id_OK then
  104.     MessageBox(HWindow, FileName, 'Save the file:', mb_OK);
  105. end;
  106.  
  107. procedure TStepWindow.CMFilePrint(var Msg: TMessage);
  108. begin
  109.   MessageBox(HWindow, 'Feature not implemented.', 'File Print', mb_OK);
  110. end;
  111.  
  112. procedure TStepWindow.CMFileSetup(var Msg: TMessage);
  113. begin
  114.   MessageBox(HWindow, 'Feature not implemented.', 'Printer Setup', mb_OK);
  115. end;
  116.  
  117. procedure TStepWindow.SetPenSize(NewSize: Integer);
  118. begin
  119.   DeleteObject(ThePen);
  120.   ThePen := CreatePen(ps_Solid, NewSize, 0);
  121.   PenSize := NewSize;
  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.     SelectObject(DragDC, ThePen);
  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.     ReleaseDC(HWindow, DragDC);
  143.   end;
  144. end;
  145.  
  146. procedure TStepWindow.WMMouseMove(var Msg: TMessage);
  147. begin
  148.   if ButtonDown then LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  149. end;
  150.  
  151. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  152. var
  153.   InputText: array[0..5] of Char;
  154.   NewSize, ErrorPos: Integer;
  155. begin
  156.   if not ButtonDown then
  157.   begin
  158.     Str(PenSize, InputText);
  159.     if Application^.ExecDialog(New(PInputDialog,
  160.       Init(@Self, 'Line Width', 'Type a new line width:',
  161.       InputText, SizeOf(InputText)))) = id_OK then
  162.     begin
  163.       Val(InputText, NewSize, ErrorPos);
  164.       if ErrorPos = 0 then SetPenSize(NewSize);
  165.     end;
  166.   end;
  167. end;
  168.  
  169. procedure TMyApplication.InitMainWindow;
  170. begin
  171.   MainWindow := New(PStepWindow, Init(nil, 'Steps'));
  172. end;
  173.  
  174. var
  175.   MyApp: TMyApplication;
  176.  
  177. begin
  178.   MyApp.Init('Steps');
  179.   MyApp.Run;
  180.   MyApp.Done;
  181. end.