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

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Demo                           }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program Step06a;
  9.  
  10. uses WinDos, Strings, WinTypes, WinProcs, OWindows, ODialogs, OStdDlgs, Pen;
  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.     CurrentPen: PPen;
  22.     FileName: array[0..fsPathName] of Char;
  23.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  24.     destructor Done; virtual;
  25.     function CanClose: Boolean; virtual;
  26.     procedure CMAbout(var Msg: TMessage);
  27.       virtual cm_First + cm_About;
  28.     procedure CMFileNew(var Msg: TMessage);
  29.       virtual cm_First + cm_FileNew;
  30.     procedure CMFileOpen(var Msg: TMessage);
  31.       virtual cm_First + cm_FileOpen;
  32.     procedure CMFileSave(var Msg: TMessage);
  33.       virtual cm_First + cm_FileSave;
  34.     procedure CMFileSaveAs(var Msg: TMessage);
  35.       virtual cm_First + cm_FileSaveAs;
  36.     procedure CMFilePrint(var Msg: TMessage);
  37.       virtual cm_First + cm_FilePrint;
  38.     procedure CMFileSetup(var Msg: TMessage);
  39.       virtual cm_First + cm_FileSetup;
  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.   StrCopy(FileName, '*.PTS');
  60.   CurrentPen := New(PPen, Init(ps_Solid, 1, 0));
  61. end;
  62.  
  63. destructor TStepWindow.Done;
  64. begin
  65.   Dispose(CurrentPen, Done);
  66.   inherited Done;
  67. end;
  68.  
  69. function TStepWindow.CanClose: Boolean;
  70. var
  71.   Reply: Integer;
  72. begin
  73.   CanClose := True;
  74.   if HasChanged then
  75.   begin
  76.     Reply := MessageBox(HWindow, 'Do you want to save?',
  77.       'Drawing has changed', mb_YesNo or mb_IconQuestion);
  78.     if Reply = id_Yes then CanClose := False;
  79.   end;
  80. end;
  81.  
  82. procedure TStepWindow.CMAbout(var Msg: TMessage);
  83. begin
  84.   Application^.ExecDialog(New(PDialog, Init(@Self, 'ABOUTBOX')));
  85. end;
  86.  
  87. procedure TStepWindow.CMFileNew(var Msg: TMessage);
  88. begin
  89.   InvalidateRect(HWindow, nil, True);
  90. end;
  91.  
  92. procedure TStepWindow.CMFileOpen(var Msg: TMessage);
  93. begin
  94.   if Application^.ExecDialog(New(PFileDialog,
  95.     Init(@Self, PChar(sd_FileOpen), FileName))) = id_OK then
  96.     MessageBox(HWindow, FIleName, 'Open the file:', mb_OK);
  97. end;
  98.  
  99. procedure TStepWindow.CMFileSave(var Msg: TMessage);
  100. begin
  101.   MessageBox(HWindow, 'Feature not implemented.', 'File Save', mb_OK);
  102. end;
  103.  
  104. procedure TStepWindow.CMFileSaveAs(var Msg: TMessage);
  105. begin
  106.   if Application^.ExecDialog(New(PFileDialog,
  107.     Init(@Self, PChar(sd_FileSave), FileName))) = id_OK then
  108.     MessageBox(HWindow, FileName, 'Save the file:', mb_OK);
  109. end;
  110.  
  111. procedure TStepWindow.CMFilePrint(var Msg: TMessage);
  112. begin
  113.   MessageBox(HWindow, 'Feature not implemented.', 'File Print', mb_OK);
  114. end;
  115.  
  116. procedure TStepWindow.CMFileSetup(var Msg: TMessage);
  117. begin
  118.   MessageBox(HWindow, 'Feature not implemented.', 'Printer Setup', mb_OK);
  119. end;
  120.  
  121. procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
  122. begin
  123.   if not ButtonDown then
  124.   begin
  125.     ButtonDown := True;
  126.     SetCapture(HWindow);
  127.     DragDC := GetDC(HWindow);
  128.     CurrentPen^.Select(DragDC);
  129.     MoveTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  130.   end;
  131. end;
  132.  
  133. procedure TStepWindow.WMLButtonUp(var Msg: TMessage);
  134. begin
  135.   if ButtonDown then
  136.   begin
  137.     ButtonDown := False;
  138.     ReleaseCapture;
  139.     CurrentPen^.Delete;
  140.     ReleaseDC(HWindow, DragDC);
  141.   end;
  142. end;
  143.  
  144. procedure TStepWindow.WMMouseMove(var Msg: TMessage);
  145. begin
  146.   if ButtonDown then LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  147. end;
  148.  
  149. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  150. var
  151.   InputText: array[0..5] of Char;
  152.   NewSize, ErrorPos: Integer;
  153. begin
  154.   if not ButtonDown then
  155.   begin
  156.     Str(CurrentPen^.Width, InputText);
  157.     if Application^.ExecDialog(New(PInputDialog,
  158.       Init(@Self, 'Line Width', 'Type a new line width:',
  159.       InputText, SizeOf(InputText)))) = id_OK then
  160.     begin
  161.       Val(InputText, NewSize, ErrorPos);
  162.       if ErrorPos = 0 then
  163.         with CurrentPen^ do
  164.           SetAttributes(ps_Solid, NewSize, 0);
  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.