REPORTVIEW.CPP
资源名称:SNMP范例源代码.zip [点击查看]
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:13k
源码类别:
SNMP编程
开发平台:
MultiPlatform
- // ReportView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OAM.h"
- #include "OamDoc.h"
- #include "ReportView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CReportView
- IMPLEMENT_DYNCREATE(CReportView, CScrollView)
- CReportView::CReportView()
- {
- m_nHasAlert = 0;
- m_nSplashCnt = 0;
- m_nChildID = 0;
- m_pFont = NULL;
- m_nMapMode = MM_TEXT;
- m_nType = 0;
- m_crText = RGB(0,0,0);
- m_crStrictText = RGB(255,0,0);
- memset(&m_lfFont, 0, sizeof(m_lfFont));
- m_lfFont.lfHeight = -9;
- m_lfFont.lfWeight = FW_DONTCARE;
- m_lfFont.lfPitchAndFamily = FIXED_PITCH | FW_DONTCARE;
- strcpy(m_lfFont.lfFaceName, "FixedSys");
- // Set a reasonable default font size for scrollbar initialization
- m_charSize.cx = 8;
- m_charSize.cy = 15;
- }
- CReportView::~CReportView()
- {
- if (m_pFont)
- {
- delete m_pFont;
- m_pFont = NULL;
- }
- }
- BEGIN_MESSAGE_MAP(CReportView, CScrollView)
- //{{AFX_MSG_MAP(CReportView)
- ON_WM_SIZE()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CReportView drawing
- void CReportView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- COAMDoc * pDoc = GetDocument();
- if (m_pFont)
- {
- delete m_pFont;
- m_pFont = NULL;
- }
- m_pFont = new CFont;
- m_pFont->CreateFontIndirect(&m_lfFont);
- }
- void CReportView::OnDraw(CDC* pDC)
- {
- // TODO: add draw code here
- RECT rect;
- CPoint scrollPos;
- int nRow, nCol, nEndRow, nEndCol, nCount, nHorzPos, nVertPos;
- CFont *pOldFont;
- COAMDoc *pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // Calculate text block that needs to be displayed
- rect = ((CPaintDC *)pDC)->m_ps.rcPaint; // Rectangle to be painted
- pOldFont = pDC->SelectObject(m_pFont);
- // set the text color as appropriate
- COLORREF cr = m_crText;
- if (cr == GetSysColor(COLOR_WINDOW))
- cr = GetSysColor(COLOR_WINDOW+1);
- // pDC->SetTextColor(cr);
- // COLORREF crStrict = m_crStrictText;
- // if (crStrict == GetSysColor(COLOR_WINDOW))
- // crStrict = GetSysColor(COLOR_WINDOW+1);
- pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
- scrollPos = GetScrollPosition();
- rect.left += scrollPos.x;
- rect.top += scrollPos.y;
- rect.right += scrollPos.x;
- rect.bottom += scrollPos.y;
- nRow = min(MAXROW - 1, max(0, rect.top / m_charSize.cy));
- nEndRow = min(MAXROW - 1, (rect.bottom - 1) / m_charSize.cy);
- // nCol = min(MAXCOL - 1, max(0, rect.left / m_charSize.cx));
- // nEndCol = min(MAXCOL - 1, (rect.right - 1) / m_charSize.cx);
- nCol = 0;
- nEndCol = MAXCOL-1;
- // BYTE byteTest = m_pScreen[((nRow + m_OperationReportData.m_nTopRow) % MAXROW) * MAXCOL + nCol];
- // if( (byteTest | 0x80) && !IsDBCSLeadByte(byteTest)) nCol = max(0,nCol-1);
- // Repaint calculated portion of view
- nCount = nEndCol - nCol + 1;
- for (; nRow <= nEndRow; nRow++)
- {
- nVertPos = nRow * m_charSize.cy;
- // nHorzPos = nCol * m_charSize.cx;
- nHorzPos = 0;
- rect.top = nVertPos;
- rect.bottom = nVertPos + m_charSize.cy;
- rect.left = nHorzPos;
- rect.right = nHorzPos + m_charSize.cx * nCount;
- pDC->SetBkMode(OPAQUE);
- /* pDC->ExtTextOut(nHorzPos, nVertPos, ETO_OPAQUE | ETO_CLIPPED, &rect,
- (LPSTR)(&(m_pScreen[(nRow + m_OperationReportData.m_nTopRow) %
- MAXROW][nCol])), nCount, NULL);
- */
- if(m_OperationReportData.m_pReportString[((nRow + m_OperationReportData.m_nTopRow) % MAXROW)].m_Type == OPERATE_REPORT)
- pDC->SetTextColor(cr);
- else
- pDC->SetTextColor(m_OperationReportData.m_pReportString[((nRow + m_OperationReportData.m_nTopRow) % MAXROW)].m_Type);
- pDC->ExtTextOut(nHorzPos, nVertPos, ETO_OPAQUE | ETO_CLIPPED, &rect,
- (LPCSTR)(&(m_OperationReportData.m_pReportString[((nRow + m_OperationReportData.m_nTopRow) %
- MAXROW)].m_pString[nCol])), nCount, NULL);
- }
- // Reset cursor location
- MoveCursor();
- pDC->SelectObject(pOldFont);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CReportView diagnostics
- #ifdef _DEBUG
- void CReportView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CReportView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- COAMDoc* CReportView::GetDocument()
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COAMDoc)));
- return (COAMDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CReportView message handlers
- void CReportView::MoveCursor(BOOL bScroll)
- {
- POINT scrollPos;
- POINT newPos;
- POINT toPos;
- BOOL needScroll;
- RECT clientRect;
- COAMDoc *pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // Calculate cursor position on view
- scrollPos = GetScrollPosition();
- newPos.x = (m_OperationReportData.m_nColumn) * m_charSize.cx - scrollPos.x;
- newPos.y = ((m_OperationReportData.m_nRow + MAXROW - m_OperationReportData.m_nTopRow) % MAXROW) *
- m_charSize.cy - scrollPos.y;
- // if (m_bHasCaret) SetCaretPos(newPos);
- // If bScroll is TRUE, scroll view to show cursor
- if (bScroll)
- {
- toPos.x = scrollPos.x;
- toPos.y = scrollPos.y;
- needScroll = FALSE;
- GetClientRect(&clientRect);
- if (newPos.x < 0)
- {
- toPos.x += newPos.x;
- needScroll = TRUE;
- }
- if (newPos.y < 0)
- {
- toPos.y += newPos.y;
- needScroll = TRUE;
- }
- if (newPos.x + m_charSize.cx > clientRect.right)
- {
- toPos.x += newPos.x + m_charSize.cx - clientRect.right;
- needScroll = TRUE;
- }
- if (newPos.y + m_charSize.cy > clientRect.bottom)
- {
- toPos.y += newPos.y + m_charSize.cy - clientRect.bottom;
- needScroll = TRUE;
- }
- if (m_OperationReportData.m_nScrolled > 0)
- {
- toPos.y += (m_OperationReportData.m_nScrolled) * m_charSize.cy;
- if (m_nMapMode != MM_TEXT)
- {
- CWindowDC dc(NULL);
- dc.SetMapMode(m_nMapMode);
- dc.LPtoDP((LPPOINT)&toPos);
- }
- ScrollToDevicePosition(toPos);
- m_OperationReportData.m_nScrolled = 0;
- }
- else if (needScroll) ScrollToPosition(toPos);
- }
- }
- void CReportView::SetSizes()
- {
- SIZE sizeTotal;
- SIZE sizePage;
- SIZE sizeLine;
- RECT clientRect;
- COAMDoc *pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // Calculate scrollbar sizes
- GetClientRect(&clientRect);
- sizeTotal.cx = m_charSize.cx * MAXCOL;
- sizeTotal.cy = m_charSize.cy *
- ((m_OperationReportData.m_nRow + MAXROW - (m_OperationReportData.m_nTopRow)) % MAXROW + 1);
- sizePage.cx = clientRect.right - clientRect.right % m_charSize.cx;
- sizePage.cy = clientRect.bottom - clientRect.bottom % m_charSize.cy;
- sizeLine.cx = m_charSize.cx;
- sizeLine.cy = m_charSize.cy;
- SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
- }
- void CReportView::SetFont(LOGFONT * lf)
- {
- if (m_pFont)
- {
- delete m_pFont;
- m_pFont = NULL;
- }
- m_pFont = new CFont;
- m_pFont->CreateFontIndirect(lf);
- SetSizes();
- Invalidate();
- MoveCursor(TRUE);
- }
- void CReportView::OnSize(UINT nType, int cx, int cy)
- {
- CScrollView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- if (nType != SIZE_MINIMIZED && cx != 0 && cy != 0 )
- {
- // SetSizes(); // Reset scrollbars
- }
- }
- void CReportView::SetType(int type)
- {
- m_nType = type;
- }
- void CReportView::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CScrollView::OnLButtonDblClk(nFlags, point);
- }
- void CReportView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- UINT msg;
- UINT wCode;
- BOOL IsKey = TRUE;
- switch(nChar){
- case VK_DOWN:
- msg=WM_VSCROLL;
- wCode=SB_LINEDOWN;
- break;
- case VK_UP:
- msg=WM_VSCROLL;
- wCode=SB_LINEUP;
- break;
- case VK_LEFT:
- msg=WM_HSCROLL;
- wCode=SB_LINEUP;
- break;
- case VK_RIGHT:
- msg=WM_HSCROLL;
- wCode=SB_LINEDOWN;
- break;
- case VK_NEXT:
- msg=WM_VSCROLL;
- wCode=SB_PAGEDOWN;
- break;
- case VK_PRIOR:
- msg=WM_VSCROLL;
- wCode=SB_PAGEUP;
- break;
- case VK_HOME:
- if(GetKeyState(0x11)<0){
- msg=WM_VSCROLL;
- wCode=SB_TOP;
- }
- else{
- msg=WM_HSCROLL;
- wCode=SB_LEFT;
- }
- break;
- case VK_END:
- if(GetKeyState(0x11)<0){
- msg=WM_VSCROLL;
- wCode=SB_RIGHT;
- }
- else{
- msg=WM_HSCROLL;
- wCode=SB_BOTTOM;
- }
- break;
- default:
- IsKey = FALSE;
- break;
- }
- if(IsKey)
- for(UINT i=0; i<nRepCnt; i++)
- PostMessage(msg,wCode,0l);
- CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- BOOL CReportView::WriteReportBlock(LPSTR lpBlock, int nLength, int Type)
- {
- int i;
- RECT rect;
- // if(Type == STRICT_OPERATE_REPORT)
- m_OperationReportData.m_pReportString[(m_OperationReportData.m_nRow)].m_Type = Type;
- for (i = 0; i < nLength; i++)
- {
- switch (lpBlock[i])
- {
- // Process special characters
- case ASCII_BEL:
- MessageBeep(0);
- break;
- case ASCII_BS:
- if (m_OperationReportData.m_nColumn > 0)
- {
- (m_OperationReportData.m_nColumn)--;
- }
- break;
- case ASCII_TAB:
- if (((m_OperationReportData.m_nColumn) / TABSTOP) < ((MAXCOL - 1) / TABSTOP))
- {
- m_OperationReportData.m_nColumn += TABSTOP - m_OperationReportData.m_nColumn % TABSTOP;
- MoveCursor(TRUE);
- }
- break;
- case ASCII_CR:
- m_OperationReportData.m_nColumn = 0;
- case ASCII_LF:
- if (++(m_OperationReportData.m_nRow) >= MAXROW) (m_OperationReportData.m_nRow) = 0;
- if ((m_OperationReportData.m_nRow) == (m_OperationReportData.m_nTopRow))
- {
- m_OperationReportData.m_bScrolled = TRUE;
- memset(&m_OperationReportData.m_pReportString[(m_OperationReportData.m_nTopRow)], ' ', sizeof(ReprtString));
- (m_OperationReportData.m_nTopRow)++;
- (m_OperationReportData.m_nScrolled)++;
- if (m_OperationReportData.m_nTopRow >= MAXROW) m_OperationReportData.m_nTopRow = 0;
- }
- SetSizes();
- break;
- default:
- m_OperationReportData.m_pReportString[(m_OperationReportData.m_nRow)].m_pString[m_OperationReportData.m_nColumn] = lpBlock[i];
- rect.left = (m_OperationReportData.m_nColumn) * m_charSize.cx -
- GetScrollPosition().x;
- rect.top = ((m_OperationReportData.m_nRow + MAXROW - m_OperationReportData.m_nTopRow) % MAXROW) *
- m_charSize.cy - GetScrollPosition().y;
- rect.right = rect.left + m_charSize.cx;
- rect.bottom = rect.top + m_charSize.cy;
- InvalidateRect(&rect, FALSE);
- if (++(m_OperationReportData.m_nColumn) >= MAXCOL)
- {
- // if (m_bAutoWrap)
- {
- // if (m_bNewLine)
- // WriteReportBlock("r", 1, Type);
- // else
- WriteReportBlock("r", 1, Type);
- }
- // else m_nColumn--;
- }
- break;
- }
- }
- MoveCursor(TRUE);
- return TRUE;
- }
- BOOL CReportView::WriteReportLine(LPSTR lpBlock, int Type,BOOL bShowTime)
- {
- CString strHead;
- if(bShowTime)
- {
- CTime NowTime;
- NowTime=CTime::GetCurrentTime();
- strHead = NowTime.Format("%Y/%m/%d %H:%M:%S ");
- }
- int nLength = min(MAXCOL,strlen(lpBlock)+strHead.GetLength());
- RECT rect;
- memcpy(m_OperationReportData.m_pReportString[(m_OperationReportData.m_nRow)].m_pString,strHead.GetBuffer(strHead.GetLength()),strHead.GetLength());
- memcpy(&m_OperationReportData.m_pReportString[(m_OperationReportData.m_nRow)].m_pString[strHead.GetLength()],lpBlock,nLength-strHead.GetLength());
- m_OperationReportData.m_pReportString[(m_OperationReportData.m_nRow)].m_Type = Type;//(BYTE)STRICT_OPERATE_REPORT;
- rect.left = (m_OperationReportData.m_nColumn) * m_charSize.cx -
- GetScrollPosition().x;
- (m_OperationReportData.m_nColumn) += nLength;
- rect.top = ((m_OperationReportData.m_nRow + MAXROW - m_OperationReportData.m_nTopRow) % MAXROW) *
- m_charSize.cy - GetScrollPosition().y;
- rect.right = rect.left + nLength * m_charSize.cx;
- rect.bottom = rect.top + m_charSize.cy;
- InvalidateRect(&rect, FALSE);
- m_OperationReportData.m_nColumn = 0;
- if (++(m_OperationReportData.m_nRow) >= MAXROW) (m_OperationReportData.m_nRow) = 0;
- if ((m_OperationReportData.m_nRow) == (m_OperationReportData.m_nTopRow))
- {
- m_OperationReportData.m_bScrolled = TRUE;
- memset(&m_OperationReportData.m_pReportString[(m_OperationReportData.m_nTopRow)], ' ', sizeof(ReprtString));
- (m_OperationReportData.m_nTopRow)++;
- (m_OperationReportData.m_nScrolled)++;
- if (m_OperationReportData.m_nTopRow >= MAXROW) m_OperationReportData.m_nTopRow = 0;
- }
- SetSizes();
- MoveCursor(TRUE);
- HWND FirsthWnd = NULL;
- return TRUE;
- }
- BOOL CReportView::WriteReportLine(LPCSTR lpBlock, int Type, BOOL bShowTime)
- {
- return WriteReportLine(CString(lpBlock).GetBuffer(MAXCOL),Type,bShowTime);
- }