home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n07 / gdiobj.exe / GDIOBJ2.CPP < prev    next >
C/C++ Source or Header  |  1995-07-01  |  5KB  |  193 lines

  1. //***************************************************************************
  2. //
  3. //  GdiObj2 adds a view class derived from MFC's CScrollView.
  4. //
  5. //***************************************************************************
  6.  
  7. #include <afxwin.h>
  8. #include "gdiobj2.h"
  9.  
  10. CMyApp myApp;
  11.  
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMyApp member functions
  14.  
  15. BOOL CMyApp::InitInstance ()
  16. {
  17.     m_pMainWnd = new CMainWindow ();
  18.     m_pMainWnd->ShowWindow (m_nCmdShow);
  19.     m_pMainWnd->UpdateWindow ();
  20.     return TRUE;
  21. }
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CMainWindow message map and member functions
  25.  
  26. BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
  27.     ON_WM_CREATE ()
  28. END_MESSAGE_MAP ()
  29.  
  30. CMainWindow::CMainWindow ()
  31. {
  32.     Create (NULL, "GdiObj2");
  33. }
  34.  
  35. int CMainWindow::OnCreate (LPCREATESTRUCT lpCreateStruct)
  36. {
  37.     CMyView* pMyView = new CMyView ();
  38.     pMyView->Create (NULL, NULL, WS_CHILD | WS_VISIBLE,
  39.         CRect (0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL);
  40.     return 0;
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CMyView message map and member functions
  45.  
  46. BEGIN_MESSAGE_MAP (CMyView, CScrollView)
  47.     ON_WM_CREATE ()
  48.     ON_WM_SIZE ()
  49. END_MESSAGE_MAP ()
  50.  
  51. int CMyView::OnCreate (LPCREATESTRUCT lpCreateStruct)
  52. {
  53.     TEXTMETRIC tm;
  54.  
  55.     CDC* pDC = GetDC ();
  56.     pDC->GetTextMetrics (&tm);
  57.     m_cxChar = tm.tmAveCharWidth;
  58.     m_cyChar = tm.tmHeight;
  59.     ReleaseDC (pDC);
  60.     return 0;
  61. }
  62.  
  63. void CMyView::OnSize (UINT nType, int cx, int cy)
  64. {
  65.     SetScrollSizes (MM_TEXT, CSize (0, VHEIGHT), CSize (0, cy),
  66.         CSize (0, m_cyChar));
  67. }
  68.  
  69. void CMyView::OnDraw (CDC* pDC)
  70. {
  71.     ShowPenStyles (pDC, m_cxChar << 1, m_cyChar);   
  72.     ShowPenWidths (pDC, m_cxChar << 1, m_cyChar * 15);
  73.     ShowBrushStyles (pDC, m_cxChar << 1, m_cyChar * 27);
  74. }
  75.  
  76. void CMyView::ShowPenStyles (CDC* pDC, int x, int y)
  77. {
  78.     CPen* pPen;
  79.     CPen* pOldPen;
  80.  
  81.     struct STYLES styles[] = {
  82.         PS_SOLID,       "PS_SOLID",
  83.         PS_DASH,        "PS_DASH",
  84.         PS_DOT,         "PS_DOT",
  85.         PS_DASHDOT,     "PS_DASHDOT",
  86.         PS_DASHDOTDOT,  "PS_DASHDOTDOT",
  87.         PS_NULL,        "PS_NULL",
  88.         PS_INSIDEFRAME, "PS_INSIDEFRAME"
  89.     };
  90.  
  91.     CString string = "Pen Styles";
  92.     pDC->TextOut (x, y, string);
  93.  
  94.     int dy = (m_cyChar * 3) >> 1;
  95.     pDC->SetTextColor (RGB (255, 0, 0));
  96.  
  97.     for (int i=0; i<7; i++) {
  98.         y += dy;
  99.         string = styles[i].szStyleName;
  100.         pDC->TextOut (x + (m_cxChar << 1), y, string);
  101.  
  102.         pPen = new CPen (styles[i].nStyle, 1, RGB (255, 0, 0));
  103.         pOldPen = pDC->SelectObject (pPen);
  104.  
  105.         pDC->MoveTo (x + (m_cxChar * 22), y + (m_cyChar >> 1));
  106.         pDC->LineTo (x + (m_cxChar * 46), y + (m_cyChar >> 1));
  107.  
  108.         delete pDC->SelectObject (pOldPen);
  109.     }
  110. }
  111.  
  112. void CMyView::ShowPenWidths (CDC* pDC, int x, int y)
  113. {
  114.     CPen* pPen;
  115.     CPen* pOldPen;
  116.  
  117.     int nPenWidths[] = { 2, 8, 16, 24 };
  118.  
  119.     CString string = "Pen Widths";
  120.     pDC->SetTextColor (RGB (0, 0, 0));
  121.     pDC->TextOut (x, y, string);
  122.  
  123.     int dy = m_cyChar << 1;
  124.     pDC->SetTextColor (RGB (0, 0, 255));
  125.  
  126.     for (int i=0; i<4; i++) {
  127.         y += dy;
  128.         string.Format ("%d Pixels", nPenWidths[i]);
  129.         pDC->TextOut (x + (m_cxChar << 1), y, string);
  130.  
  131.         pPen = new CPen (PS_SOLID, nPenWidths[i], RGB (0, 0, 255));
  132.         pOldPen = pDC->SelectObject (pPen);
  133.  
  134.         pDC->MoveTo (x + (m_cxChar * 22), y + (m_cyChar >> 1));
  135.         pDC->LineTo (x + (m_cxChar * 46), y + (m_cyChar >> 1));
  136.  
  137.         delete pDC->SelectObject (pOldPen);
  138.     }
  139. }
  140.  
  141. void CMyView::ShowBrushStyles (CDC* pDC, int x, int y)
  142. {
  143.     CBrush* pBrush;
  144.     CBrush* pOldBrush;
  145.  
  146.     struct STYLES styles[] = {
  147.         HS_BDIAGONAL,   "HS_BDIAGONAL",
  148.         HS_CROSS,       "HS_CROSS",
  149.         HS_DIAGCROSS,   "HS_DIAGCROSS",
  150.         HS_FDIAGONAL,   "HS_FDIAGONAL",
  151.         HS_HORIZONTAL,  "HS_HORIZONTAL",
  152.         HS_VERTICAL,    "HS_VERTICAL"
  153.     };
  154.  
  155.     CString string = "Brush Styles";
  156.     pDC->SetTextColor (RGB (0, 0, 0));
  157.     pDC->TextOut (x, y, string);
  158.  
  159.     int dy = m_cyChar * 3;
  160.  
  161.     for (int i=0; i<6; i++) {
  162.         y += dy;
  163.         string = styles[i].szStyleName;
  164.         pDC->TextOut (x + (m_cxChar << 1), y, string);
  165.  
  166.         CRect rect (x + (m_cxChar * 22), y - m_cyChar,
  167.             x + (m_cxChar * 46), y + m_cyChar);
  168.  
  169.         pBrush = new CBrush (styles[i].nStyle, RGB (0, 255, 0));
  170.         CPoint point (rect.left, rect.top);
  171.         pDC->LPtoDP (&point);
  172.         point.x &= 0x07;
  173.         point.y &= 0x07;
  174.         pDC->SetBrushOrg (point);
  175.  
  176.         pOldBrush = pDC->SelectObject (pBrush);
  177.         pDC->Rectangle (rect);
  178.         delete pDC->SelectObject (pOldBrush);
  179.     }
  180.  
  181.     y += dy;
  182.     string = "Solid";
  183.     pDC->TextOut (x + (m_cxChar << 1), y, string);
  184.  
  185.     pBrush = new CBrush (RGB (0, 255, 0));
  186.     pOldBrush = pDC->SelectObject (pBrush);
  187.  
  188.     pDC->Rectangle (x + (m_cxChar * 22), y - m_cyChar,
  189.         x + (m_cxChar * 46), y + m_cyChar);
  190.  
  191.     delete pDC->SelectObject (pOldBrush);
  192. }
  193.