home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 10.ddi / STEPS.ZIP / STEP4.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.0 KB  |  91 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <owl.h>
  4.  
  5. class TMyApp : public TApplication
  6. {
  7. public:
  8.   TMyApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  9.     LPSTR lpCmdLine, int nCmdShow)
  10.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  11.   virtual void InitMainWindow();
  12. };
  13.  
  14. _CLASSDEF(TMyWindow)
  15. class TMyWindow : public TWindow
  16. {
  17. public:
  18.   HDC DragDC;
  19.   BOOL ButtonDown;
  20.  
  21.   TMyWindow(PTWindowsObject AParent, LPSTR ATitle);
  22.   virtual BOOL CanClose();
  23.   virtual void WMLButtonDown(RTMessage Msg)
  24.     = [WM_FIRST + WM_LBUTTONDOWN];
  25.   virtual void WMLButtonUp(RTMessage Msg)
  26.     = [WM_FIRST + WM_LBUTTONUP];
  27.   virtual void WMMouseMove(RTMessage Msg)
  28.     = [WM_FIRST + WM_MOUSEMOVE];
  29.   virtual void WMRButtonDown(RTMessage Msg)
  30.     = [WM_FIRST + WM_RBUTTONDOWN];
  31. };
  32.  
  33. TMyWindow::TMyWindow(PTWindowsObject AParent, LPSTR ATitle)
  34.   : TWindow(AParent, ATitle)
  35. {
  36.   ButtonDown = FALSE;
  37. }
  38.  
  39. BOOL TMyWindow::CanClose()
  40. {
  41.   return MessageBox(HWindow, "Do you want to save?",
  42.     "Drawing has changed", MB_YESNO | MB_ICONQUESTION) == IDNO;
  43. }
  44.  
  45. void TMyWindow::WMLButtonDown(RTMessage Msg)
  46. {
  47.   InvalidateRect(HWindow, NULL, TRUE);
  48.   if ( !ButtonDown )
  49.   {
  50.     ButtonDown = TRUE;
  51.     SetCapture(HWindow);
  52.     DragDC = GetDC(HWindow);
  53.     MoveTo(DragDC, Msg.LP.Lo, Msg.LP.Hi);
  54.   }
  55. }
  56.  
  57. void TMyWindow::WMMouseMove(RTMessage Msg)
  58. {
  59.   if ( ButtonDown )
  60.     LineTo(DragDC, Msg.LP.Lo, Msg.LP.Hi);
  61. }
  62.  
  63. void TMyWindow::WMLButtonUp(RTMessage)
  64. {
  65.   if ( ButtonDown )
  66.   {
  67.     ButtonDown = FALSE;
  68.     ReleaseCapture();
  69.     ReleaseDC(HWindow, DragDC);
  70.   }
  71. }
  72.  
  73. void TMyWindow::WMRButtonDown(RTMessage)
  74. {
  75.   InvalidateRect(HWindow, NULL, TRUE);
  76. }
  77.  
  78. void TMyApp::InitMainWindow()
  79. {
  80.   MainWindow = new TMyWindow(NULL, Name);
  81. }
  82.  
  83. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  84.   LPSTR lpCmdLine, int nCmdShow)
  85. {
  86.   TMyApp MyApp("Sample ObjectWindows Program", hInstance, hPrevInstance,
  87.                lpCmdLine, nCmdShow);
  88.   MyApp.Run();
  89.   return MyApp.Status;
  90. }
  91.