home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / OWLDEMOS.ZIP / SCRIBAPP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  3.0 KB  |  97 lines

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