home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 6.ddi / OWLDEMOS.ZIP / SCRIBAPP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.0 KB  |  97 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include "owl.h"
  4.  
  5.   /* Declare TScribbleApp, a TApplication descendant */
  6. class TScribbleApp : public TApplication
  7. {
  8. public:
  9.   TScribbleApp(LPSTR name, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  10.     LPSTR lpCmdLine, int nCmdShow)
  11.     : TApplication(name, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  12.   virtual void InitMainWindow();
  13. };
  14.  
  15.   /* Declare TScribbleWindow, a TWindow descendant */
  16. class TScribbleWindow : public TWindow
  17. {
  18. public:
  19.   HDC HoldDC;
  20.   BOOL ButtonDown ;
  21.   TScribbleWindow(PTWindowsObject Parent,LPSTR name);
  22.   virtual void WMLButtonDown(RTMessage Msg) = [WM_FIRST + WM_LBUTTONDOWN];
  23.   virtual void WMLButtonUp(RTMessage Msg) = [WM_FIRST + WM_LBUTTONUP];
  24.   virtual void WMMouseMove(RTMessage Msg) = [WM_FIRST + WM_MOUSEMOVE];
  25.   virtual void WMRButtonDown(RTMessage Msg) = [WM_FIRST + WM_RBUTTONDOWN];
  26. };
  27.  
  28. TScribbleWindow::TScribbleWindow(PTWindowsObject AParent, LPSTR AName)
  29.                 : TWindow(AParent, AName)
  30. {
  31.   ButtonDown = FALSE;
  32. }
  33.  
  34. /* Define a TScribbleWindow's response to an incoming "left-button-down"
  35.   message.  In response, TScribbleWindows prepare to draw a line,
  36.   setting the current position in client area, retrieving a display
  37.   context from MS-Windows, and capturing mouse input. */
  38. void TScribbleWindow::WMLButtonDown(RTMessage Msg)
  39. {
  40.   if (!ButtonDown)
  41.   {
  42.     ButtonDown = TRUE;
  43.     // Direct all subsequent mouse input to this window
  44.     SetCapture(HWindow); //MS-Windows function
  45.     HoldDC = GetDC(HWindow);
  46.     MoveTo (HoldDC, Msg.LP.Lo, Msg.LP.Hi);
  47.   }
  48. }
  49.  
  50. /* Define a TScribbleWindow's response to an incoming "mouse-move"
  51.   message.  In response, TScribbleWindows draw a line using the new
  52.   position of the mouse. */
  53. void TScribbleWindow::WMMouseMove(RTMessage Msg)
  54. {
  55.   if (ButtonDown)
  56.     LineTo(HoldDC, Msg.LP.Lo, Msg.LP.Hi);   // draw the line
  57. }
  58.  
  59.  
  60. /* Define a TScribbleWindow's response to an incoming "left-button-up"
  61.   message.  In response, TScribbleWindows "cleanup" required after a
  62.   line is drawn, releasing the display context to MS-Windows, and
  63.   releasing mouse input. */
  64. void TScribbleWindow::WMLButtonUp(RTMessage)
  65. {
  66.   if (ButtonDown)
  67.   {
  68.     ReleaseCapture();
  69.     ReleaseDC(HWindow, HoldDC);
  70.     ButtonDown = FALSE;
  71.   }
  72. }
  73.  
  74. /* Define a TScribbleWindow's response to an incoming
  75.    "right-button-down" message.  In response, TScribbleWindows "clear"
  76.    their client area. */
  77. void TScribbleWindow::WMRButtonDown(RTMessage)
  78. {
  79.   // Invalidate the entire window
  80.   InvalidateRect(HWindow, LPRECT(NULL), TRUE);  // MS-Windows function
  81.   // MS-Windows will send WM_PAINT message to the window
  82. }
  83.  
  84. void TScribbleApp::InitMainWindow()
  85. {
  86.   MainWindow = new TScribbleWindow(NULL, "Scribble Away!");
  87. }
  88.  
  89. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  90.   LPSTR lpCmdLine, int nCmdShow)
  91. {
  92.   TScribbleApp ScribbleApp ("Scribble", hInstance, hPrevInstance,
  93.     lpCmdLine, nCmdShow);
  94.   ScribbleApp.Run();
  95.   return ScribbleApp.Status;
  96. }
  97.