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

📄 datesvw.cpp

📁 API经典入门
💻 CPP
字号:
// datesvw.cpp : implementation of the CDatesView class
//

#include "stdafx.h"
#include "dates.h"

#include "datesdoc.h"
#include "datesvw.h"
#include "date.h"
#include "datedial.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDatesView

IMPLEMENT_DYNCREATE(CDatesView, CView)

BEGIN_MESSAGE_MAP(CDatesView, CView)
	//{{AFX_MSG_MAP(CDatesView)
	ON_COMMAND(ID_DATES_TEST, OnDatesTest)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDatesView construction/destruction

CDatesView::CDatesView()
{
	// TODO: add construction code here
}

CDatesView::~CDatesView()
{
}

/////////////////////////////////////////////////////////////////////////////
// CDatesView drawing

void CDatesView::OnDraw(CDC* pDC)
{
	CDatesDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	CDate theDate(1962, 9, 13);
                 
	pDC->TextOut(20,20,theDate.DateString());
	
}

/////////////////////////////////////////////////////////////////////////////
// CDatesView diagnostics


// Routine for testing CDate functionality
void CDatesView::DebugDate()
{
	CTime t = CTime::GetCurrentTime();
                 
	CDate currentDate (t);
	CDate theDate(1962, 9, 13);

	currentDate.Dump(afxDump);
	ASSERT_VALID(&theDate);
	
	UWORD Y,M,D;
	currentDate.Subtract(theDate, Y, M, D);
	TRACE("My Age is %i years, %i months, and %i days.\n", Y, M, D);
	
	CDate tempDate = theDate;
	//int i;
	//int diff;
	/*for (i = 1; i < 10000; i++)
	{
		tempDate.SubtractDay();
		diff = theDate - tempDate;
		if ( diff != i )
		{
			TRACE("****Error in operator-: died in debug i = %i.\n", i);
			tempDate.Dump(afxDump);
			break;
		}
	}*/

	int Days = currentDate - theDate;
	TRACE1("My Age in days is %i.\n", Days);
	
	tempDate = currentDate;
	tempDate = tempDate + 2000;
	TRACE("2000 days from today is %s.\n", tempDate.DateString());
	ASSERT(2000 == (tempDate - currentDate));

	CDateDialog Dlg;
	Dlg.m_Date = currentDate;
	
	if (Dlg.DoModal() == IDOK)
	{
		if (tempDate.StringToDate(Dlg.m_DateString))
		{
			TRACE1("StringToDate() succeeded on '%s'\n", Dlg.m_DateString);
			TRACE1("	The resultant string is %s.\n", tempDate.DateString());
		}
		else
		{
			TRACE1("StringToDate() failed on '%s'\n", Dlg.m_DateString);
		}
	}
	MessageBox("And the DDX date is ..." + Dlg.m_Date.DateString());
	
	CDate d1;
	ASSERT_VALID(&d1);
	
	CDate d2(1903, 2, 29); // 1904 would be okay
	//TRACE("About to call false assert!\n");
	//ASSERT_VALID(&d2);

	// run-time class support testing
		
	ASSERT( d1.IsKindOf(RUNTIME_CLASS(CObject)) );
	ASSERT( d1.IsKindOf(RUNTIME_CLASS(CDate)) );
	
	CDate* pDate = new CDate(d1);
		
	
	//CRuntimeClass* pRTC = d1.GetRuntimeClass();  // for CDate
	//CRuntimeClass* pRTC = GetRuntimeClass(); // for our view
	//CRuntimeClass* pRTC = pDoc->GetRuntimeClass(); // for our document
	CRuntimeClass* pRTC = pDate->GetRuntimeClass(); // for a dynamic date

	
	while (pRTC)
	{
		TRACE("Class Name: %Fs; ObjectSize: %d; Schema #: %d\n",
			 pRTC->m_lpszClassName, pRTC->m_nObjectSize, pRTC->m_wSchema );
		
		pRTC = pRTC->m_pBaseClass;
	}
	
	
	delete pDate;
	
}


#ifdef _DEBUG
void CDatesView::AssertValid() const
{
	CView::AssertValid();
}

void CDatesView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDatesDoc* CDatesView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDatesDoc)));
	return (CDatesDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDatesView message handlers

void CDatesView::OnDatesTest()
{
	DebugDate();
	
}

⌨️ 快捷键说明

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