home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / DRAWEDGE.PAK / DRAWEDGE.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.3 KB  |  159 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1995 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl/pch.h>
  5. #include <owl/applicat.h>
  6. #include <owl/framewin.h>
  7. #include <owl/uihelper.h>
  8. #include <owl/listbox.h>
  9. #include <owl/gdiobjec.h>
  10. #include <stdio.h>
  11. #include "drawedge.rh"
  12.  
  13. class TTestWindow : public TDialog {
  14.   public:
  15.     TTestWindow();
  16.  
  17.   protected:
  18.     void    Paint(TDC& dc, bool erase, TRect& rect);
  19.     void    SetupWindow();
  20.     LRESULT EvCommand(uint id, HWND hWndCtl, uint notifyCode);
  21.  
  22.     HBRUSH  EvCtlColor(HDC, HWND hWndChild, uint ctlType);
  23.  
  24.     void    PaintSample(TDC& dc);
  25.     void    Update();
  26.  
  27.     uint  Edge;
  28.     uint  Flags;
  29.     TRect SampleRect;
  30.  
  31.   DECLARE_RESPONSE_TABLE(TTestWindow);
  32. };
  33.  
  34. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  35.   EV_WM_CTLCOLOR,
  36.   EV_WM_WININICHANGE,
  37. END_RESPONSE_TABLE;
  38.  
  39.  
  40. TTestWindow::TTestWindow()
  41. :
  42.   TDialog(0, IDD_DRAWEDGE, 0)
  43. {
  44.   SetBkgndColor(TColor::Sys3dFace);
  45. }
  46.  
  47. //
  48. //
  49. //
  50. void
  51. TTestWindow::SetupWindow()
  52. {
  53.   TDialog::SetupWindow();
  54.  
  55.   ::GetWindowRect(GetDlgItem(IDC_SAMPLE), &SampleRect);
  56.   ScreenToClient(SampleRect.TopLeft());
  57.   ScreenToClient(SampleRect.BottomRight());
  58.   ::DestroyWindow(GetDlgItem(IDC_SAMPLE));
  59.   Update();
  60. }
  61.  
  62.  
  63. void
  64. TTestWindow::PaintSample(TDC& dc)
  65. {
  66.   if (Flags & TUIBorder::Soft)
  67.     dc.SelectObject(TBrush(TColor::Sys3dFace));
  68.   else
  69.     dc.SelectObject(TBrush(TColor::SysDesktop));
  70.   dc.PatBlt(SampleRect.InflatedBy(10,10), PATCOPY);
  71.  
  72.   TRect r(SampleRect);
  73.   TUIBorder border(r, TUIBorder::TEdge(Edge), Flags);
  74.   border.Paint(dc);
  75. }
  76.  
  77. //
  78. // Paint some UI style thingies
  79. //
  80. void
  81. TTestWindow::Paint(TDC& dc, bool, TRect&)
  82. {
  83.   PaintSample(dc);
  84. }
  85.  
  86. LRESULT
  87. TTestWindow::EvCommand(uint id, HWND hWndCtl, uint notifyCode)
  88. {
  89.   if (!hWndCtl)
  90.     return TDialog::EvCommand(id, hWndCtl, notifyCode);
  91.  
  92.   Update();
  93.   PaintSample(TClientDC(*this));
  94.  
  95.   return true;
  96. }
  97.  
  98. //
  99. // Provide a background color & brush for child controls to use
  100. //
  101. HBRUSH
  102. TTestWindow::EvCtlColor(HDC hDC, HWND /*hWndChild*/, uint /*ctlType*/)
  103. {
  104.   ::SetBkColor(hDC, TColor::Sys3dFace);
  105.   return TBrush(TColor::Sys3dFace);
  106. }
  107.  
  108. void
  109. TTestWindow::Update()
  110. {
  111.   static int edgeBit[] = {
  112.     TUIBorder::RaisedOuter,
  113.     TUIBorder::SunkenOuter,
  114.     TUIBorder::RaisedInner,
  115.     TUIBorder::SunkenInner,
  116.   };
  117.  
  118.   Edge = 0;
  119.   int i;
  120.   for (i = 0; i < 4; i++)
  121.     if (IsDlgButtonChecked(IDC_EDGE_RO + i))
  122.       Edge |= edgeBit[i];
  123.  
  124.   static int flagBit[] = {
  125.     TUIBorder::Left,
  126.     TUIBorder::Top,
  127.     TUIBorder::Right,
  128.     TUIBorder::Bottom,
  129.     TUIBorder::Diagonal,
  130.     TUIBorder::Fill,
  131.     TUIBorder::Soft,
  132.     TUIBorder::Adjust,
  133.     TUIBorder::Flat,
  134.     TUIBorder::Mono,
  135.   };
  136.  
  137.   Flags = 0;
  138.   for (i = 0; i < 10; i++)
  139.     if (IsDlgButtonChecked(IDC_FL_LEFT + i))
  140.       Flags |= flagBit[i];
  141. }
  142.  
  143. //----------------------------------------------------------------------------
  144.  
  145. class TTestApp : public TApplication {
  146.   public:
  147.     TTestApp() : TApplication() {}
  148.     void InitMainWindow() {
  149.       MainWindow = new TFrameWindow(0, "DrawEdge", new TTestWindow, true);
  150.       MainWindow->Attr.Style &= ~WS_THICKFRAME;
  151.     }
  152. };
  153.  
  154. int
  155. OwlMain(int /*argc*/, char* /*argv*/ [])
  156. {
  157.   return TTestApp().Run();
  158. }
  159.