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

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Demo                           }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program Step05;
  9.  
  10. uses WinDos, Strings, WinTypes, WinProcs, OWindows, ODialogs, 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 CMAbout(var Msg: TMessage);
  28.       virtual cm_First + cm_About;
  29.     procedure CMFileNew(var Msg: TMessage);
  30.       virtual cm_First + cm_FileNew;
  31.     procedure CMFileOpen(var Msg: TMessage);
  32.       virtual cm_First + cm_FileOpen;
  33.     procedure CMFileSave(var Msg: TMessage);
  34.       virtual cm_First + cm_FileSave;
  35.     procedure CMFileSaveAs(var Msg: TMessage);
  36.       virtual cm_First + cm_FileSaveAs;
  37.     procedure CMFilePrint(var Msg: TMessage);
  38.       virtual cm_First + cm_FilePrint;
  39.     procedure CMFileSetup(var Msg: TMessage);
  40.       virtual cm_First + cm_FileSetup;
  41.     procedure SetPenSize(NewSize: Integer);
  42.     procedure WMLButtonDown(var Msg: TMessage);
  43.       virtual wm_First + wm_LButtonDown;
  44.     procedure WMLButtonUp(var Msg: TMessage);
  45.       virtual wm_First + wm_LButtonUp;
  46.     procedure WMMouseMove(var Msg: TMessage);
  47.       virtual wm_First + wm_MouseMove;
  48.     procedure WMRButtonDown(var Msg: TMessage);
  49.       virtual wm_First + wm_RButtonDown;
  50.   end;
  51.   TMyApplication = object(TApplication)
  52.     procedure InitMainWindow; virtual;
  53.   end;
  54.  
  55. constructor TStepWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  56. begin
  57.   inherited Init(AParent, ATitle);
  58.   Attr.Menu := LoadMenu(HInstance, MakeIntResource(100));
  59.   HasChanged := False;
  60.   ButtonDown := False;
  61.   PenSize := 1;
  62.   ThePen := CreatePen(ps_Solid, PenSize, 0);
  63.   StrCopy(FileName, '*.PTS');
  64. end;
  65.  
  66. destructor TStepWindow.Done;
  67. begin
  68.   DeleteObject(ThePen);
  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.SetPenSize(NewSize: Integer);
  125. begin
  126.   DeleteObject(ThePen);
  127.   ThePen := CreatePen(ps_Solid, NewSize, 0);
  128.   PenSize := NewSize;
  129. end;
  130.  
  131. procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
  132. begin
  133.   if not ButtonDown then
  134.   begin
  135.     ButtonDown := True;
  136.     SetCapture(HWindow);
  137.     DragDC := GetDC(HWindow);
  138.     SelectObject(DragDC, ThePen);
  139.     MoveTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  140.   end;
  141. end;
  142.  
  143. procedure TStepWindow.WMLButtonUp(var Msg: TMessage);
  144. begin
  145.   if ButtonDown then
  146.   begin
  147.     ButtonDown := False;
  148.     ReleaseCapture;
  149.     ReleaseDC(HWindow, DragDC);
  150.   end;
  151. end;
  152.  
  153. procedure TStepWindow.WMMouseMove(var Msg: TMessage);
  154. begin
  155.   if ButtonDown then LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  156. end;
  157.  
  158. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  159. var
  160.   InputText: array[0..5] of Char;
  161.   NewSize, ErrorPos: Integer;
  162. begin
  163.   if not ButtonDown then
  164.   begin
  165.     Str(PenSize, InputText);
  166.     if Application^.ExecDialog(New(PInputDialog,
  167.       Init(@Self, 'Line Width', 'Type a new line width:',
  168.       InputText, SizeOf(InputText)))) = id_OK then
  169.     begin
  170.       Val(InputText, NewSize, ErrorPos);
  171.       if ErrorPos = 0 then SetPenSize(NewSize);
  172.     end;
  173.   end;
  174. end;
  175.  
  176. procedure TMyApplication.InitMainWindow;
  177. begin
  178.   MainWindow := New(PStepWindow, Init(nil, 'Steps'));
  179. end;
  180.  
  181. var
  182.   MyApp: TMyApplication;
  183.  
  184. begin
  185.   MyApp.Init('Steps');
  186.   MyApp.Run;
  187.   MyApp.Done;
  188. end.