sView.cpp
上传用户:mywtwc
上传日期:2013-04-05
资源大小:165k
文件大小:7k
- // sView.cpp : implementation of the CSView class
- //
- #include "stdafx.h"
- #include "s.h"
- #include "SYSMETS.H"
- #include "sDoc.h"
- #include "sView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSView
- IMPLEMENT_DYNCREATE(CSView, CView)
- BEGIN_MESSAGE_MAP(CSView, CView)
- //{{AFX_MSG_MAP(CSView)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_WM_VSCROLL()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSView construction/destruction
- CSView::CSView()
- {
- // TODO: add construction code here
- }
- CSView::~CSView()
- {
- }
- BOOL CSView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSView drawing
- void CSView::OnDraw(CDC* pDC)
- {
- CSDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSView printing
- BOOL CSView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CSView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CSView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSView diagnostics
- #ifdef _DEBUG
- void CSView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CSView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CSDoc* CSView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSDoc)));
- return (CSDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CSView message handlers
- int CSView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // TODO: Add your specialized creation code here
- CDC* pDC=GetDC();
- TEXTMETRIC tm;
- pDC->GetTextMetrics(&tm);
- cxChar = tm.tmAveCharWidth ;
- cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
- cyChar = tm.tmHeight + tm.tmExternalLeading ;
- // Save the width of the three columns
- iMaxWidth = 40 * cxChar + 22 * cxCaps ;
- ReleaseDC(pDC);
- return 0;
- }
- void CSView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- cxClient=cx;
- cyClient=cy;
- si.fMask = SIF_RANGE | SIF_PAGE ;
- si.nMin = 0 ;
- si.nMax = NUMLINES - 1 ;
- si.nPage = cyClient / cyChar ;
- SetScrollInfo (SB_VERT, &si, TRUE) ;
- si.fMask = SIF_RANGE | SIF_PAGE ;
- si.nMin = 0 ;
- si.nMax = 2 + iMaxWidth / cxChar ;
- si.nPage = cxClient / cxChar ;
- SetScrollInfo (SB_HORZ, &si, TRUE) ;
- }
- void CSView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
- si.fMask = SIF_ALL ;
- GetScrollInfo (SB_VERT, &si) ;
- // Save the position for comparison later on
- iVertPos = si.nPos ;
- switch (nSBCode)
- {
- case SB_TOP:
- si.nPos = si.nMin ;
- break ;
-
- case SB_BOTTOM:
- si.nPos = si.nMax ;
- break ;
-
- case SB_LINEUP:
- si.nPos -= 1 ;
- break ;
-
- case SB_LINEDOWN:
- si.nPos += 1 ;
- break ;
-
- case SB_PAGEUP:
- si.nPos -= si.nPage ;
- break ;
- case SB_PAGEDOWN:
- si.nPos += si.nPage ;
- break ;
-
- case SB_THUMBTRACK:
- si.nPos = si.nTrackPos ;
- break ;
- default:
- break ;
- }
- // Set the position and then retrieve it. Due to adjustments
- // by Windows it may not be the same as the value set.
- si.fMask = SIF_POS ;
- SetScrollInfo (SB_VERT, &si, TRUE) ;
- GetScrollInfo (SB_VERT, &si) ;
- // If the position has changed, scroll the window and update it
- if (si.nPos != iVertPos)
- {
- ScrollWindow (0, cyChar * (iVertPos - si.nPos),
- NULL, NULL) ;
- UpdateWindow () ;
- }
- }
- void CSView::OnPaint()
- {
- // CPaintDC dc(this); // device context for painting
- //pay attation please,remove the line above!!!
- // TODO: Add your message handler code here
- PAINTSTRUCT ps;
- CDC* pDC=BeginPaint(&ps);
- si.fMask = SIF_POS ;
- GetScrollInfo (SB_VERT, &si) ;
- iVertPos = si.nPos ;
- int x,y;
- // Get horizontal scroll bar position
- GetScrollInfo (SB_HORZ, &si) ;
- iHorzPos = si.nPos ;
- // Find painting limits
- iPaintBeg = max (0, iVertPos + ps.rcPaint.top / cyChar) ;
- iPaintEnd = min (NUMLINES - 1,
- iVertPos + ps.rcPaint.bottom / cyChar) ;
-
- for (int i = iPaintBeg ; i <= iPaintEnd ; i++)
- {
- x = cxChar * (1 - iHorzPos) ;
- y = cyChar * (i - iVertPos) ;
-
- pDC->TextOut (x, y,
- sysmetrics[i].szLabel,
- lstrlen (sysmetrics[i].szLabel)) ;
-
- pDC->TextOut (x + 22 * cxCaps, y,
- sysmetrics[i].szDesc,
- lstrlen (sysmetrics[i].szDesc)) ;
-
- pDC->SetTextAlign (TA_RIGHT | TA_TOP) ;
-
- pDC->TextOut (x + 22 * cxCaps + 40 * cxChar, y, szBuffer,
- wsprintf (szBuffer, TEXT ("%5d"),
- GetSystemMetrics (sysmetrics[i].iIndex))) ;
- pDC->SetTextAlign (TA_LEFT | TA_TOP) ;
- }
- }