home *** CD-ROM | disk | FTP | other *** search
- {************************************************}
- { }
- { ObjectWindows Demo }
- { Copyright (c) 1992 by Borland International }
- { }
- {************************************************}
-
- {$R-} { Turn off range check because Windows message parameters
- don't distinguish between Integer and Word. }
-
- program Step03a;
-
- uses Strings, WinTypes, WinProcs, OWindows;
-
- type
- PStepWindow = ^TStepWindow;
- TStepWindow = object(TWindow)
- DragDC: HDC;
- ButtonDown, HasChanged: Boolean;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- function CanClose: Boolean; virtual;
- procedure WMLButtonDown(var Msg: TMessage);
- virtual wm_First + wm_LButtonDown;
- procedure WMLButtonUp(var Msg: TMessage);
- virtual wm_First + wm_LButtonUp;
- procedure WMMouseMove(var Msg: TMessage);
- virtual wm_First + wm_MouseMove;
- procedure WMRButtonDown(var Msg: TMessage);
- virtual wm_First + wm_RButtonDown;
- end;
- TMyApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- constructor TStepWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- inherited Init(AParent, ATitle);
- HasChanged := False;
- ButtonDown := False;
- end;
-
- function TStepWindow.CanClose: Boolean;
- var
- Reply: Integer;
- begin
- CanClose := True;
- if HasChanged then
- begin
- Reply := MessageBox(HWindow, 'Do you want to save?',
- 'Drawing has changed', mb_YesNo or mb_IconQuestion);
- if Reply = id_Yes then CanClose := False;
- end;
- end;
-
- procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
- begin
- if not ButtonDown then
- begin
- ButtonDown := True;
- SetCapture(HWindow);
- DragDC := GetDC(HWindow);
- MoveTo(DragDC, Msg.LParamLo, Msg.LParamHi);
- end;
- end;
-
- procedure TStepWindow.WMLButtonUp(var Msg: TMessage);
- begin
- if ButtonDown then
- begin
- ButtonDown := False;
- ReleaseCapture;
- ReleaseDC(HWindow, DragDC);
- end;
- end;
-
- procedure TStepWindow.WMMouseMove(var Msg: TMessage);
- begin
- if ButtonDown then LineTo(DragDC, Msg.LParamLo, Msg.LParamHi);
- end;
-
- procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
- begin
- InvalidateRect(HWindow, nil, True);
- end;
-
- procedure TMyApplication.InitMainWindow;
- begin
- MainWindow := New(PStepWindow, Init(nil, 'Steps'));
- end;
-
- var
- MyApp: TMyApplication;
-
- begin
- MyApp.Init('Steps');
- MyApp.Run;
- MyApp.Done;
- end.