sView.cpp
上传用户:mywtwc
上传日期:2013-04-05
资源大小:165k
文件大小:7k
源码类别:

工具条

开发平台:

Visual C++

  1. // sView.cpp : implementation of the CSView class
  2. //
  3. #include "stdafx.h"
  4. #include "s.h"
  5. #include "SYSMETS.H"
  6. #include "sDoc.h"
  7. #include "sView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSView
  15. IMPLEMENT_DYNCREATE(CSView, CView)
  16. BEGIN_MESSAGE_MAP(CSView, CView)
  17. //{{AFX_MSG_MAP(CSView)
  18. ON_WM_CREATE()
  19. ON_WM_SIZE()
  20. ON_WM_VSCROLL()
  21. ON_WM_PAINT()
  22. //}}AFX_MSG_MAP
  23. // Standard printing commands
  24. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  25. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  26. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  27. END_MESSAGE_MAP()
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CSView construction/destruction
  30. CSView::CSView()
  31. {
  32. // TODO: add construction code here
  33. }
  34. CSView::~CSView()
  35. {
  36. }
  37. BOOL CSView::PreCreateWindow(CREATESTRUCT& cs)
  38. {
  39. // TODO: Modify the Window class or styles here by modifying
  40. //  the CREATESTRUCT cs
  41. return CView::PreCreateWindow(cs);
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CSView drawing
  45. void CSView::OnDraw(CDC* pDC)
  46. {
  47. CSDoc* pDoc = GetDocument();
  48. ASSERT_VALID(pDoc);
  49. // TODO: add draw code for native data here
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CSView printing
  53. BOOL CSView::OnPreparePrinting(CPrintInfo* pInfo)
  54. {
  55. // default preparation
  56. return DoPreparePrinting(pInfo);
  57. }
  58. void CSView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  59. {
  60. // TODO: add extra initialization before printing
  61. }
  62. void CSView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  63. {
  64. // TODO: add cleanup after printing
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CSView diagnostics
  68. #ifdef _DEBUG
  69. void CSView::AssertValid() const
  70. {
  71. CView::AssertValid();
  72. }
  73. void CSView::Dump(CDumpContext& dc) const
  74. {
  75. CView::Dump(dc);
  76. }
  77. CSDoc* CSView::GetDocument() // non-debug version is inline
  78. {
  79. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSDoc)));
  80. return (CSDoc*)m_pDocument;
  81. }
  82. #endif //_DEBUG
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CSView message handlers
  85. int CSView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  86. {
  87. if (CView::OnCreate(lpCreateStruct) == -1)
  88. return -1;
  89. // TODO: Add your specialized creation code here
  90. CDC* pDC=GetDC();
  91. TEXTMETRIC tm;
  92. pDC->GetTextMetrics(&tm);
  93. cxChar = tm.tmAveCharWidth ;
  94.     cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
  95.     cyChar = tm.tmHeight + tm.tmExternalLeading ;
  96.     // Save the width of the three columns
  97.     iMaxWidth = 40 * cxChar + 22 * cxCaps ;
  98. ReleaseDC(pDC);
  99. return 0;
  100. }
  101. void CSView::OnSize(UINT nType, int cx, int cy) 
  102. {
  103. CView::OnSize(nType, cx, cy);
  104. // TODO: Add your message handler code here
  105. cxClient=cx;
  106. cyClient=cy;
  107.     si.fMask  = SIF_RANGE | SIF_PAGE ;
  108.     si.nMin   = 0 ;
  109.     si.nMax   = NUMLINES - 1 ;
  110.     si.nPage  = cyClient / cyChar ;
  111.     SetScrollInfo (SB_VERT, &si, TRUE) ;
  112. si.fMask  = SIF_RANGE | SIF_PAGE ;
  113.     si.nMin   = 0 ;
  114.     si.nMax   = 2 + iMaxWidth / cxChar ;
  115.     si.nPage  = cxClient / cxChar ;
  116.     SetScrollInfo (SB_HORZ, &si, TRUE) ;
  117. }
  118. void CSView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  119. {
  120. // TODO: Add your message handler code here and/or call default
  121.       si.fMask  = SIF_ALL ;
  122.           GetScrollInfo (SB_VERT, &si) ;
  123. // Save the position for comparison later on
  124.           iVertPos = si.nPos ;
  125.           switch (nSBCode)
  126.           {
  127.           case SB_TOP:
  128.                si.nPos = si.nMin ;
  129.                break ;
  130.                
  131.           case SB_BOTTOM:
  132.                si.nPos = si.nMax ;
  133.                break ;
  134.                
  135.           case SB_LINEUP:
  136.                si.nPos -= 1 ;
  137.                break ;
  138.                
  139.           case SB_LINEDOWN:
  140.                si.nPos += 1 ;
  141.                break ;
  142.                
  143.           case SB_PAGEUP:
  144.                si.nPos -= si.nPage ;
  145.                break ;
  146.           case SB_PAGEDOWN:
  147.                si.nPos += si.nPage ;
  148.                break ;
  149.                
  150.           case SB_THUMBTRACK:
  151.                si.nPos = si.nTrackPos ;
  152.                break ;
  153.           default:
  154.                break ;         
  155.           }
  156.                // Set the position and then retrieve it.  Due to adjustments
  157.                //   by Windows it may not be the same as the value set.
  158.           si.fMask = SIF_POS ;
  159.           SetScrollInfo (SB_VERT, &si, TRUE) ;
  160.           GetScrollInfo (SB_VERT, &si) ;
  161. // If the position has changed, scroll the window and update it
  162.           if (si.nPos != iVertPos)
  163.           {                    
  164.                ScrollWindow (0, cyChar * (iVertPos - si.nPos), 
  165.                                    NULL, NULL) ;
  166.                UpdateWindow () ;
  167.           }
  168. }
  169. void CSView::OnPaint() 
  170. {
  171. // CPaintDC dc(this); // device context for painting
  172. //pay attation please,remove the line above!!!
  173. // TODO: Add your message handler code here
  174. PAINTSTRUCT ps;
  175. CDC* pDC=BeginPaint(&ps);
  176.           si.fMask  = SIF_POS ;
  177.           GetScrollInfo (SB_VERT, &si) ;
  178.           iVertPos = si.nPos ;
  179.   int x,y;
  180.                // Get horizontal scroll bar position
  181.           GetScrollInfo (SB_HORZ, &si) ;
  182.           iHorzPos = si.nPos ;
  183.                // Find painting limits
  184.           iPaintBeg = max (0, iVertPos + ps.rcPaint.top / cyChar) ;
  185.           iPaintEnd = min (NUMLINES - 1,
  186.                            iVertPos + ps.rcPaint.bottom / cyChar) ;
  187.           
  188.           for (int i = iPaintBeg ; i <= iPaintEnd ; i++)
  189.           {
  190.                x = cxChar * (1 - iHorzPos) ;
  191.                y = cyChar * (i - iVertPos) ;
  192.                
  193.                pDC->TextOut (x, y,
  194.                         sysmetrics[i].szLabel,
  195.                         lstrlen (sysmetrics[i].szLabel)) ;
  196.                
  197.                pDC->TextOut (x + 22 * cxCaps, y,
  198.                         sysmetrics[i].szDesc,
  199.                         lstrlen (sysmetrics[i].szDesc)) ;
  200.                
  201.                pDC->SetTextAlign (TA_RIGHT | TA_TOP) ;
  202.                
  203.                pDC->TextOut (x + 22 * cxCaps + 40 * cxChar, y, szBuffer,
  204.                         wsprintf (szBuffer, TEXT ("%5d"),
  205.                              GetSystemMetrics (sysmetrics[i].iIndex))) ;
  206.                pDC->SetTextAlign (TA_LEFT | TA_TOP) ;
  207.           }
  208. }