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

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <stdio.h>
  4. #include <owl.h>
  5. #include <button.h>
  6. #include "dctltest.h"
  7.  
  8. class TTestApp : public TApplication
  9. {
  10. public:
  11.   TTestApp(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(TDrawableButton)
  18.  
  19. class TDrawableButton : public TButton
  20. {
  21. public:
  22.   TDrawableButton(PTWindowsObject AParent, int ResourceId) :
  23.     TButton(AParent, ResourceId) {}
  24.   void ODADrawEntire(DRAWITEMSTRUCT far & DrawInfo);
  25.   void ODAFocus(DRAWITEMSTRUCT far & DrawInfo);
  26.   void ODASelect(DRAWITEMSTRUCT far & DrawInfo);
  27. };
  28.  
  29. /* Function called when button needs to be drawn */
  30. void TDrawableButton::ODADrawEntire(DRAWITEMSTRUCT far & DrawInfo)
  31. {
  32.   Rectangle(DrawInfo.hDC, DrawInfo.rcItem.left, DrawInfo.rcItem.top,
  33.     DrawInfo.rcItem.right, DrawInfo.rcItem.bottom);
  34.   if ( IsCurrentDefPB )
  35.       Rectangle(DrawInfo.hDC, DrawInfo.rcItem.left+1,
  36.                 DrawInfo.rcItem.top+1, DrawInfo.rcItem.right-1,
  37.                 DrawInfo.rcItem.bottom-1);
  38.  
  39.   DrawInfo.rcItem.top += 6;
  40.   DrawText(DrawInfo.hDC, "DRAWN", -1, &DrawInfo.rcItem,
  41.     DT_CENTER | DT_VCENTER);
  42.   if ( (DrawInfo.itemState & ODS_FOCUS) == ODS_FOCUS )
  43.   {
  44.     DrawInfo.rcItem.left += 4;
  45.     DrawInfo.rcItem.right -= 4; DrawInfo.rcItem.bottom -= 6;
  46.     DrawFocusRect(DrawInfo.hDC, &DrawInfo.rcItem);
  47.   }
  48. }
  49.  
  50. /* Function called when button gains or loses focus */
  51. void TDrawableButton::ODAFocus(DRAWITEMSTRUCT far & DrawInfo)
  52. {
  53.   DrawInfo.rcItem.top += 6; DrawInfo.rcItem.left += 4;
  54.   DrawInfo.rcItem.right -= 4; DrawInfo.rcItem.bottom -= 6;
  55.   DrawFocusRect(DrawInfo.hDC, &DrawInfo.rcItem);
  56. }
  57.  
  58. /* Function called when button's selection status changes */
  59. void TDrawableButton::ODASelect(DRAWITEMSTRUCT far & DrawInfo)
  60. {
  61.   Rectangle(DrawInfo.hDC, DrawInfo.rcItem.left, DrawInfo.rcItem.top,
  62.     DrawInfo.rcItem.right, DrawInfo.rcItem.bottom);
  63.   if ( IsCurrentDefPB )
  64.       Rectangle(DrawInfo.hDC, DrawInfo.rcItem.left+1,
  65.                 DrawInfo.rcItem.top+1, DrawInfo.rcItem.right-1,
  66.                 DrawInfo.rcItem.bottom-1);
  67.  
  68.   DrawInfo.rcItem.top += 6;
  69.   if ( (DrawInfo.itemState & ODS_SELECTED) == ODS_SELECTED)
  70.     DrawText(DrawInfo.hDC, "SELECTED", -1, &DrawInfo.rcItem,
  71.       DT_CENTER | DT_VCENTER);
  72.   else
  73.     DrawText(DrawInfo.hDC, "DESELECTED", -1, &DrawInfo.rcItem,
  74.       DT_CENTER | DT_VCENTER);
  75.   if ( (DrawInfo.itemState & ODS_FOCUS) == ODS_FOCUS )
  76.   {
  77.     DrawInfo.rcItem.left += 4;
  78.     DrawInfo.rcItem.right -= 4; DrawInfo.rcItem.bottom -= 6;
  79.     DrawFocusRect(DrawInfo.hDC, &DrawInfo.rcItem);
  80.   }
  81. }
  82.  
  83. class TTestDialog : public TDialog
  84. {
  85. public:
  86.   PTDrawableButton Button1;
  87.   PTDrawableButton Button2;
  88.  
  89.   TTestDialog(PTWindowsObject AParent);
  90.   virtual void IDButton1(RTMessage) = [ID_FIRST + ID_BUTTON1]
  91.       { MessageBeep(0);}
  92. };
  93.  
  94. TTestDialog::TTestDialog(PTWindowsObject AParent)
  95.   : TDialog(AParent, "TESTDIALOG")
  96. {
  97.   Button1 = new TDrawableButton(this, ID_BUTTON1);
  98.   Button2 = new TDrawableButton(this, ID_BUTTON2);
  99. }
  100.  
  101. class TTestWindow : public TWindow
  102. {
  103. public:
  104.   TTestWindow(PTWindowsObject AParent, LPSTR ATitle);
  105.   virtual void Test(RTMessage Msg)
  106.     = [CM_FIRST + CM_TEST];
  107. };
  108.  
  109. TTestWindow::TTestWindow(PTWindowsObject AParent, LPSTR ATitle)
  110.   : TWindow(AParent, ATitle)
  111. {
  112.   AssignMenu("COMMANDS");
  113. }
  114.  
  115. void TTestWindow::Test(RTMessage)
  116. {
  117.   GetApplication()->ExecDialog(new TTestDialog(this));
  118. }
  119.  
  120. void TTestApp::InitMainWindow()
  121. {
  122.   MainWindow = new TTestWindow(NULL, Name);
  123. }
  124.  
  125. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  126.   LPSTR lpCmdLine, int nCmdShow)
  127. {
  128.   TTestApp TestApp("Drawable Button Tester", hInstance, hPrevInstance,
  129.     lpCmdLine, nCmdShow);
  130.   TestApp.Run();
  131.   return TestApp.Status;
  132. }
  133.