⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmdbview.cpp

📁 中文信息处理方面的一个源码。此为一个拼音分析和生成软件功能强大
💻 CPP
字号:
// TestMDBvw.cpp : implementation of the CTestMDBView class
//

#include "stdafx.h"
#include "TestMDB.h"

#include "TestMDBdoc.h"
#include "TestMDBView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestMDBView

IMPLEMENT_DYNCREATE(CTestMDBView, CRowView)

BEGIN_MESSAGE_MAP(CTestMDBView, CRowView)
    //{{AFX_MSG_MAP(CTestMDBView)
    ON_WM_SETFOCUS()
    ON_WM_MOUSEACTIVATE()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CRowView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRowView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestMDBView construction/destruction

CTestMDBView::CTestMDBView()
{
	m_pSet = NULL;
}

CTestMDBView::~CTestMDBView()
{
}
									
/////////////////////////////////////////////////////////////////////////////
void CTestMDBView::OnUpdate(CView*, LPARAM lHint, CObject* pHint)
{
    // called when the user executes a new query
    // can't set m_pSet in OnInitialUpdate because it's NULL then
    ScrollToPosition(CPoint(0, 0));
    Invalidate(TRUE);
    m_nSelectedRow = -1;
	CTestMDBDoc* pDoc = GetDocument();
	if((m_pSet = pDoc->m_pRecordset) != NULL) {
		UpdateScrollSizes();
	}
}

/////////////////////////////////////////////////////////////////////////////
// CRowView overrides

/////////////////////////////////////////////////////////////////////////////
void CTestMDBView::OnDrawRow(CDC* pDC, int nRow, int y, BOOL bSelected)
{
    int x = 0;
    int i;
    CTestMDBDoc* pDoc = GetDocument();
    if (m_pSet == NULL) return;
	
    if (nRow == 0) {    // title row
      for (i = 0; i < pDoc->m_nFields; i++) {
        pDC->TextOut(x, y, pDoc->m_arrayFieldName[i]);
        x += pDoc->m_arrayFieldSize[i] * m_nCharWidth;
      }	
    }
    else {
      try {
        m_pSet->SetAbsolutePosition(nRow - 1); // adjust for title row
		// SetAbsolutePosition doesn't throw exception until AFTER 
		//  end of set
        if (m_pSet->GetAbsolutePosition() == (nRow - 1)) {
          DrawDataRow(pDC, y);
        }
      }
      catch (CDaoException* e) {
		// might be a time delay before delete is seen in this program
        if (e->m_pErrorInfo->m_lErrorCode == 3167) {
          pDC->TextOut(0, y, "**RECORD DELETED**");
        }
        else {
          m_pSet->MoveLast(); // in case m_nRowCount is too big
	      pDoc->m_nRowCount = m_pSet->GetAbsolutePosition() + 2;
        }
        e->Delete();
      }
    }
}

void CTestMDBView::DrawDataRow(CDC* pDC, int y)
{
    int x = 0;
    CString strTime;

    COleVariant var;
    CString str;
    CTestMDBDoc* pDoc = GetDocument();
    for (int i = 0; i < pDoc->m_nFields; i++) {
      var = m_pSet->GetFieldValue(i);
      switch (var.vt) {
      case VT_BSTR:
        str = (LPCSTR) var.bstrVal; // narrow characters in DAO
        break;
      case VT_I2:
        str.Format("%d", (int) var.iVal);
        break;
      case VT_I4:
        str.Format("%d", var.lVal);
        break;
      case VT_R4:
        str.Format("%10.2f", (double) var.fltVal);
        break;
      case VT_R8:
        str.Format("%10.2f", var.dblVal);
        break;
	  case VT_CY:
        str = COleCurrency(var).Format();
        break;
      case VT_DATE:
        str = COleDateTime(var).Format();
        break;
      case VT_BOOL:
        str = (var.boolVal == 0) ? "FALSE" : "TRUE";
        break;
      case VT_NULL:
        str =  "----";
        break;
      default:
        str.Format("Unk type %d\n", var.vt);
        TRACE("Unknown type %d\n", var.vt);
      }
      pDC->TextOut(x, y, str);
      x += pDoc->m_arrayFieldSize[i] * m_nCharWidth;
    }	
}

/////////////////////////////////////////////////////////////////////////////
void CTestMDBView::GetRowWidthHeight(CDC* pDC, int& nRowWidth,
         int& nRowHeight, int& nCharWidth)
{
    TEXTMETRIC tm;

    CTestMDBDoc* pDoc = GetDocument();
	pDC->GetTextMetrics(&tm);
    nCharWidth = tm.tmAveCharWidth + 1;
    nRowWidth = 0;
	for(int i = 0; i < pDoc->m_nFields; i++) {
	    nRowWidth += pDoc->m_arrayFieldSize[i];
	}
    nRowWidth *= nCharWidth;
    nRowHeight = tm.tmHeight;
}

/////////////////////////////////////////////////////////////////////////////
int CTestMDBView::GetActiveRow()
{
    return m_nSelectedRow;
}

/////////////////////////////////////////////////////////////////////////////
int CTestMDBView::GetRowCount()
{
    return GetDocument()->m_nRowCount;
}

/////////////////////////////////////////////////////////////////////////////
void CTestMDBView::ChangeSelectionNextRow(BOOL bNext)
{
    if (bNext && (m_nSelectedRow < min(GetRowCount() - 1,
                LastViewableRow() - 2))) {
        m_nSelectedRow++;
    }
    if (!bNext && m_nSelectedRow) {
        m_nSelectedRow--;
    }
    UpdateRow(m_nSelectedRow);
}

/////////////////////////////////////////////////////////////////////////////
void CTestMDBView::ChangeSelectionToRow(int nRow)
{
    if ((nRow >= 0) && (nRow < min(GetRowCount(), LastViewableRow() - 1))) {
        m_nSelectedRow = nRow;
    }
    UpdateRow(m_nSelectedRow);
}

/////////////////////////////////////////////////////////////////////////////
// CTestMDBView diagnostics

#ifdef _DEBUG
void CTestMDBView::AssertValid() const
{
    CRowView::AssertValid();
}

void CTestMDBView::Dump(CDumpContext& dc) const
{
    CRowView::Dump(dc);
}

/////////////////////////////////////////////////////////////////////////////
CTestMDBDoc* CTestMDBView::GetDocument() // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestMDBDoc)));
    return (CTestMDBDoc*) m_pDocument;
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestMDBView message handlers

/////////////////////////////////////////////////////////////////////////////
void CTestMDBView::OnSetFocus(CWnd* pOldWnd)
{
    // updates dialog bar query strings
	GetDocument()->PutQuery();
	CRowView::OnSetFocus(pOldWnd);
}

/////////////////////////////////////////////////////////////////////////////
int CTestMDBView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
	// resets the focus from the dialog bar
    SetFocus(); 
    return CRowView::OnMouseActivate(pDesktopWnd, nHitTest, message);
}


void CTestMDBView::OnInitialUpdate() 
{
	CRowView::OnInitialUpdate();
}

void CTestMDBView::OnTimer(UINT nIDEvent) 
{
	Invalidate(); // update view from database
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -