home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WDOCDEMO.ZIP / STEP03A.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  2.5 KB  |  98 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 Step03a;
  12.  
  13. uses Strings, WinTypes, WinProcs, OWindows;
  14.  
  15. type
  16.   PStepWindow = ^TStepWindow;
  17.   TStepWindow = object(TWindow)
  18.     DragDC: HDC;
  19.     ButtonDown, HasChanged: Boolean;
  20.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  21.     function CanClose: Boolean; virtual;
  22.     procedure WMLButtonDown(var Msg: TMessage);
  23.       virtual wm_First + wm_LButtonDown;
  24.     procedure WMLButtonUp(var Msg: TMessage);
  25.       virtual wm_First + wm_LButtonUp;
  26.     procedure WMMouseMove(var Msg: TMessage);
  27.       virtual wm_First + wm_MouseMove;
  28.     procedure WMRButtonDown(var Msg: TMessage);
  29.       virtual wm_First + wm_RButtonDown;
  30.   end;
  31.   TMyApplication = object(TApplication)
  32.     procedure InitMainWindow; virtual;
  33.   end;
  34.  
  35. constructor TStepWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  36. begin
  37.   inherited Init(AParent, ATitle);
  38.   HasChanged := False;
  39.   ButtonDown := False;
  40. end;
  41.  
  42. function TStepWindow.CanClose: Boolean;
  43. var
  44.   Reply: Integer;
  45. begin
  46.   CanClose := True;
  47.   if HasChanged then
  48.   begin
  49.     Reply := MessageBox(HWindow, 'Do you want to save?',
  50.       'Drawing has changed', mb_YesNo or mb_IconQuestion);
  51.     if Reply = id_Yes then CanClose := False;
  52.   end;
  53. end;
  54.  
  55. procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
  56. begin
  57.   if not ButtonDown then
  58.   begin
  59.     ButtonDown := True;
  60.     SetCapture(HWindow);
  61.     DragDC := GetDC(HWindow);
  62.     MoveTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  63.   end;
  64. end;
  65.  
  66. procedure TStepWindow.WMLButtonUp(var Msg: TMessage);
  67. begin
  68.   if ButtonDown then
  69.   begin
  70.     ButtonDown := False;
  71.     ReleaseCapture;
  72.     ReleaseDC(HWindow, DragDC);
  73.   end;
  74. end;
  75.  
  76. procedure TStepWindow.WMMouseMove(var Msg: TMessage);
  77. begin
  78.   if ButtonDown then LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
  79. end;
  80.  
  81. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  82. begin
  83.   InvalidateRect(HWindow, nil, True);
  84. end;
  85.  
  86. procedure TMyApplication.InitMainWindow;
  87. begin
  88.   MainWindow := New(PStepWindow, Init(nil, 'Steps'));
  89. end;
  90.  
  91. var
  92.   MyApp: TMyApplication;
  93.  
  94. begin
  95.   MyApp.Init('Steps');
  96.   MyApp.Run;
  97.   MyApp.Done;
  98. end.