home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SIMBOR.PAK / BORDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.1 KB  |  198 lines

  1. // ---------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (C) 1995, 1995 by Borland International, All Rights Reserved
  4. // ---------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include "SimBor.h"
  7. #include <stdio.h>
  8. #include <windowsx.h>
  9.  
  10. //
  11. // constructor
  12. //
  13. TSimulatedBorlandDialog::TSimulatedBorlandDialog(TWindow* parent,
  14.   TResId resId, TModule* module)
  15. :
  16.   TDialog(parent, resId, module)
  17. {
  18.   TBitmap bmDialog(*GetApplication(), IDB_DLGBRSH);
  19.   BrDialog = new TBrush(bmDialog);
  20. }
  21.  
  22.  
  23. //
  24. // destructor
  25. //
  26. TSimulatedBorlandDialog::~TSimulatedBorlandDialog()
  27. {
  28.   delete BrDialog;
  29. }
  30.  
  31. //
  32. // Response Table
  33. //
  34. DEFINE_RESPONSE_TABLE1(TSimulatedBorlandDialog, TDialog)
  35.   EV_WM_PAINT,
  36.   EV_WM_CTLCOLOR,
  37. END_RESPONSE_TABLE;
  38.  
  39.  
  40. //
  41. // Draw3DRect
  42. //
  43. void
  44. Draw3DRect(TDC& dc, TRect& rect, TPen hilite, TPen shadow)
  45. {
  46.   dc.SelectObject(hilite);
  47.   dc.MoveTo(rect.left, rect.bottom);
  48.   dc.LineTo(rect.left, rect.top);
  49.   dc.LineTo(rect.right, rect.top);
  50.   dc.MoveTo(rect.right-1, rect.top);
  51.   dc.LineTo(rect.right-1, rect.bottom-1);
  52.   dc.LineTo(rect.left+1, rect.bottom-1);
  53.   dc.RestorePen();
  54.  
  55.   dc.SelectObject(shadow);
  56.   dc.MoveTo(rect.left+1, rect.bottom-1);
  57.   dc.LineTo(rect.left+1, rect.top+1);
  58.   dc.LineTo(rect.right-1, rect.top+1);
  59.   dc.MoveTo(rect.right, rect.top);
  60.   dc.LineTo(rect.right, rect.bottom);
  61.   dc.LineTo(rect.left, rect.bottom);
  62.   dc.RestorePen();
  63. }
  64.  
  65. //
  66. // EvPaint
  67. //
  68. void
  69. TSimulatedBorlandDialog::EvPaint()
  70. {
  71.   // let the dialog paint itself
  72.   //
  73.   TDialog::EvPaint();
  74.  
  75.   // draw 3D look
  76.   //
  77.   TClientDC dc(HWindow);
  78.   TRect rect;
  79.   GetClientRect(rect);
  80.   rect.right--;
  81.   rect.bottom--;
  82.   Draw3DRect(dc, rect, GetStockPen(WHITE_PEN), GetStockPen(BLACK_PEN));
  83. }
  84.  
  85.  
  86. //
  87. // Handle CtlColor
  88. //
  89. HBRUSH TSimulatedBorlandDialog::EvCtlColor(HDC hDC, HWND hWndChild, uint ctlType)
  90. {
  91.   switch (ctlType) {
  92.     case CTLCOLOR_DLG:
  93.       // change background of the dialog
  94.       //
  95.       return *BrDialog;
  96.   }
  97.   return TDialog::EvCtlColor(hDC, hWndChild, ctlType);
  98. }
  99.  
  100. //
  101. // constructor
  102. //
  103. TSimBorDialog::TSimBorDialog(TWindow* parent, TResId resId) :
  104.   TSimulatedBorlandDialog(parent, resId)
  105. {
  106.   ListBox   = new TListBox(this, ID_LISTBOX);
  107.   ScrollBar = new TScrollBar(this, ID_SCROLLBAR);
  108.   Static    = new TStatic(this, ID_MESSAGE);
  109. }
  110.  
  111. //
  112. // destructor
  113. //
  114. TSimBorDialog::~TSimBorDialog()
  115. {
  116.   delete BrScrollBar;
  117.   delete BrListBox;
  118.   delete BrStatic;
  119. }
  120.  
  121. //
  122. // SetupWindow
  123. //
  124. void
  125. TSimBorDialog::SetupWindow()
  126. {
  127.   TSimulatedBorlandDialog::SetupWindow();
  128.  
  129.   LOGBRUSH lbTemp;
  130.  
  131.   // create hatched brush
  132.   //
  133.   lbTemp.lbStyle = BS_HATCHED;
  134.   lbTemp.lbColor = RGB(255, 0, 255);
  135.   lbTemp.lbHatch = HS_DIAGCROSS;
  136.   BrStatic = new TBrush(&lbTemp);
  137.  
  138.   lbTemp.lbStyle = BS_SOLID;
  139.   lbTemp.lbColor = RGB(255, 255, 255);
  140.   lbTemp.lbHatch = 0;
  141.   BrListBox = new TBrush(&lbTemp);
  142.  
  143.   // create pattern brushes
  144.   //
  145.   TBitmap bmScrollBar(*GetApplication(), IDB_SCRLBRSH);
  146.   BrScrollBar = new TBrush(bmScrollBar);
  147.  
  148.   // add strings to the listbox
  149.   //
  150.   char cBuf[20];
  151.   for (int i = 0; i < 20; i++) {
  152.     sprintf(cBuf, "Line number #%d", i);
  153.     ListBox->AddString(cBuf);
  154.   }
  155.  
  156.   // set the scrollbar's thumb in the middle
  157.   //
  158.   ScrollBar->SetRange(0, 2);
  159.   ScrollBar->SetPosition(1);
  160. }
  161.  
  162. //
  163. // Response table
  164. //
  165. DEFINE_RESPONSE_TABLE1(TSimBorDialog, TSimulatedBorlandDialog)
  166.   EV_WM_CTLCOLOR,
  167. END_RESPONSE_TABLE;
  168.  
  169.  
  170. //
  171. // Handle CtlColor
  172. //
  173. HBRUSH
  174. TSimBorDialog::EvCtlColor(HDC hDC, HWND hWndChild, uint ctlType)
  175. {
  176.   TDC dc(hDC);
  177.  
  178.   switch (ctlType) {
  179.     case CTLCOLOR_STATIC:
  180.       dc.SetBkMode(TRANSPARENT);      // transparent bkgrnd
  181.       dc.SetTextColor(RGB(0, 0, 0));  // black text
  182.       return *BrStatic;
  183.  
  184.     case CTLCOLOR_LISTBOX:
  185.       dc.SetBkMode(TRANSPARENT);      // transparent bkgrnd
  186.       dc.SetTextColor(RGB(0, 0, 255));
  187.       return *BrListBox;
  188.  
  189.     case CTLCOLOR_SCROLLBAR:
  190.       dc.SetBkMode(TRANSPARENT);
  191.       dc.SetTextColor(RGB(0, 0, 0));
  192.       return *BrScrollBar;
  193.   }
  194.  
  195.   return TSimulatedBorlandDialog::EvCtlColor(hDC, hWndChild, ctlType);
  196. }
  197.  
  198.