home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WDOCDEMO.ZIP / STEP02.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  1.9 KB  |  74 lines

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Demo                           }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program Step02;
  9.  
  10. uses Strings, WinTypes, WinProcs, OWindows;
  11.  
  12. type
  13.   PStepWindow = ^TStepWIndow;
  14.   TStepWindow = object(TWindow)
  15.     DragDC: HDC;
  16.     HasChanged: Boolean;
  17.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  18.     function CanClose: Boolean; virtual;
  19.     procedure WMLButtonDown(var Msg: TMessage);
  20.       virtual wm_First + wm_LButtonDown;
  21.     procedure WMRButtonDown(var Msg: TMessage);
  22.       virtual wm_First + wm_RButtonDown;
  23.   end;
  24.   TMyApplication = object(TApplication)
  25.     procedure InitMainWindow; virtual;
  26.   end;
  27.  
  28. constructor TStepWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  29. begin
  30.   inherited Init(AParent, ATitle);
  31.   HasChanged := False;
  32. end;
  33.  
  34. function TStepWindow.CanClose: Boolean;
  35. var
  36.   Reply: Integer;
  37. begin
  38.   CanClose := True;
  39.   if HasChanged then
  40.   begin
  41.     Reply := MessageBox(HWindow, 'Do you want to save?',
  42.       'Drawing has changed', mb_YesNo or mb_IconQuestion);
  43.     if Reply = id_Yes then CanClose := False;
  44.   end;
  45. end;
  46.  
  47. procedure TStepWindow.WMLButtonDown(var Msg: TMessage);
  48. var
  49.   S: array[0..9] of Char;
  50. begin
  51.   wvsprintf(S, '(%d,%d)', Msg.LParam);
  52.   DragDC := GetDC(HWindow);
  53.   TextOut(DragDC, Msg.LParamLo, Msg.LParamHi, S, StrLen(S));
  54.   ReleaseDC(HWindow, DragDC);
  55. end;
  56.  
  57. procedure TStepWindow.WMRButtonDown(var Msg: TMessage);
  58. begin
  59.   InvalidateRect(HWindow, nil, True);
  60. end;
  61.  
  62. procedure TMyApplication.InitMainWindow;
  63. begin
  64.   MainWindow := New(PStepWindow, Init(nil, 'Steps'));
  65. end;
  66.  
  67. var
  68.   MyApp: TMyApplication;
  69.  
  70. begin
  71.   MyApp.Init('Steps');
  72.   MyApp.Run;
  73.   MyApp.Done;
  74. end.