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

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <owl.h>
  6. #include <inputdia.h>
  7.  
  8. class TMyApp : public TApplication
  9. {
  10. public:
  11.   TMyApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  12.     LPSTR lpCmdLine, int nCmdShow)
  13.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  14.   virtual void InitMainWindow();
  15. };
  16.  
  17. _CLASSDEF(TMyWindow)
  18. class TMyWindow : public TWindow
  19. {
  20. public:
  21.   HDC DragDC;
  22.   BOOL ButtonDown;
  23.   HPEN ThePen;
  24.   int PenSize;
  25.   TMyWindow(PTWindowsObject AParent, LPSTR ATitle);
  26.   ~TMyWindow();
  27.   virtual BOOL CanClose();
  28.   void SetPenSize(int NewSize);
  29.   virtual void WMLButtonDown(RTMessage Msg)
  30.     = [WM_FIRST + WM_LBUTTONDOWN];
  31.   virtual void WMLButtonUp(RTMessage Msg)
  32.     = [WM_FIRST + WM_LBUTTONUP];
  33.   virtual void WMMouseMove(RTMessage Msg)
  34.     = [WM_FIRST + WM_MOUSEMOVE];
  35.   virtual void WMRButtonDown(RTMessage Msg)
  36.     = [WM_FIRST + WM_RBUTTONDOWN];
  37. };
  38.  
  39. TMyWindow::TMyWindow(PTWindowsObject AParent, LPSTR ATitle)
  40.   : TWindow(AParent, ATitle)
  41. {
  42.   ButtonDown = FALSE;
  43.   PenSize = 1;
  44.   ThePen = CreatePen(PS_SOLID, PenSize, 0);
  45. }
  46.  
  47. TMyWindow::~TMyWindow()
  48. {
  49.   DeleteObject(ThePen);
  50. }
  51.  
  52. BOOL TMyWindow::CanClose()
  53. {
  54.   return MessageBox(HWindow, "Do you want to save?",
  55.     "Drawing has changed", MB_YESNO | MB_ICONQUESTION) == IDNO;
  56. }
  57.  
  58. void TMyWindow::WMLButtonDown(RTMessage Msg)
  59. {
  60.   InvalidateRect(HWindow, NULL, TRUE);
  61.   if ( !ButtonDown )
  62.   {
  63.     ButtonDown = TRUE;
  64.     SetCapture(HWindow);
  65.     DragDC = GetDC(HWindow);
  66.     SelectObject(DragDC, ThePen);
  67.     MoveTo(DragDC, Msg.LP.Lo, Msg.LP.Hi);
  68.   }
  69. }
  70.  
  71. void TMyWindow::WMMouseMove(RTMessage Msg)
  72. {
  73.   if ( ButtonDown )
  74.     LineTo(DragDC, Msg.LP.Lo, Msg.LP.Hi);
  75. }
  76.  
  77. void TMyWindow::WMLButtonUp(RTMessage)
  78. {
  79.   if ( ButtonDown )
  80.   {
  81.     ButtonDown = FALSE;
  82.     ReleaseCapture();
  83.     ReleaseDC(HWindow, DragDC);
  84.   }
  85. }
  86.  
  87. void TMyWindow::WMRButtonDown(RTMessage)
  88. {
  89.   char InputText[6];
  90.   int NewPenSize;
  91.  
  92.   sprintf(InputText, "%d", PenSize);
  93.   if ( GetApplication()->ExecDialog(new TInputDialog(this, "Line Thickness",
  94.     "Input a new thickness:", InputText, sizeof InputText)) == IDOK )
  95.   {
  96.       NewPenSize = atoi(InputText);
  97.       if ( NewPenSize < 0 )
  98.         NewPenSize = 1;
  99.       SetPenSize(NewPenSize);
  100.   }
  101. }
  102.  
  103. void TMyWindow::SetPenSize(int NewSize)
  104. {
  105.   DeleteObject(ThePen);
  106.   ThePen = CreatePen(PS_SOLID, NewSize, 0);
  107.   PenSize = NewSize;
  108. }
  109.  
  110. void TMyApp::InitMainWindow()
  111. {
  112.   MainWindow = new TMyWindow(NULL, Name);
  113. }
  114.  
  115. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  116.   LPSTR lpCmdLine, int nCmdShow)
  117. {
  118.   TMyApp MyApp("Sample ObjectWindows Program", hInstance, hPrevInstance,
  119.                lpCmdLine, nCmdShow);
  120.   MyApp.Run();
  121.   return MyApp.Status;
  122. }
  123.  
  124.