home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / tpw / docdemos / step03.pas < prev    next >
Pascal/Delphi Source File  |  1991-05-20  |  2KB  |  79 lines

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